IBM Support

How to use OTScript to extract model properties using IBM Rational Rhapsody

Question & Answer


Question

How do you use OTScript to extract properties from my project in IBM Rational Rhapsody?

Cause

You would like to include specific IBM Rational Rhapsody properties in my Gateway analysis but they do not appear to be available.

Answer

By default these properties are not available in Gateway. However, it is possible to use Gateway OTScript to extract model properties via the IBM Rational Rhapsody API.

  1. Open the Configuration > Types window in Gateway and create a new Rhapsody type.
  2. Under the new type add a new attribute and name it PreDeclarationModifier. This is the name of IBM Rational Rhapsody model property you will be extracting in this demonstration.
  3. Create a new text file in the _rpy directory of your IBM Rational Rhapsody project, making sure the extension of the file is .br rather than .txt
  4. Open the file in a text editor and paste in the code at the bottom of this document.

The relevant parts of the code are:

  • Retrieval of the PreDeclarationModifier attribute added in steps above


  • Identifying the types of elements to which you want to add the attribute. In this example, Operations, Constructors, Destructors, etcetera are stored in a temporary variable called operationTypes. We then iterate the contents of the Gateway project ("aDocument") filtering out the types contained in operationTypes.


  • Retrieval of the property from the IBM Rational Rhapsody model using the IBM Rational Rhapsody API method IRPModelElement.getPropertyValue(string key). If all the commands are executed with a valid result, the attribute is added with the corresponding property value using the OTScript command, newAttribute.


  • Full Code:
METHOD Rhapsody.ModelElement.asOperation() : { class_ := CLASS(Rhapsody.Operation); THIS[EACH ISA Rhapsody.Operation]; };

ATTRIBUTE Rhapsody.Operation.visibility : String;

METHOD Rhapsody.postprocessOperationVisibility(aDocument : Document, reloadedDocuments : Document) : {
postprocess(aDocument); // Call predefined post-process method

aDocument $< reloadedDocuments
IF TRUE: {
// retrieve the PreDeclarationModifier attribute we defined in our Rhapsody type
TMP PreDeclarationModifierAttribute := aDocument.documentType.findType("PreDeclarationModifier")[elementClass = Attribute];
TMP VisibilityAttribute := aDocument.documentType.findType("Visibility")[elementClass = Attribute];
$SOME(PreDeclarationModifierAttribute) AND $SOME(VisibilityAttribute)
IF TRUE: {
TMP rhpPrj := GETOBJECT(Rhapsody.Application,"").activeProject;
TMP operationTypes := aDocument.documentType.findType("Operation" $+ "Constructor" $+ "Destructor" $+ "TriggeredOperation" $+ "PrimitiveOperation" $+ "Reception");
operationTypes += aDocument.documentType.types[$SOME(superType) AND superType $< operationTypes];

aDocument.entities[type $< operationTypes].{

TMP visibility := rhpPrj.findElementByGUID(guid)[metaClass = "Operation"].asOperation.visibility;
$SOME(visibility) IF TRUE: newAttribute(PreDeclarationModifierAttribute, visibility);

// look up the PreDeclarationModifier property value
TMP PreDeclarationModifierKey := "CPP_CG.Operation.PreDeclarationModifier";
TMP PreDeclarationModifierValue := rhpPrj.findElementByGUID(guid)[metaClass = "Operation"].asOperation.getPropertyValue(PreDeclarationModifierKey);
$SOME(PreDeclarationModifierValue) IF TRUE: newAttribute(PreDeclarationModifierAttribute, PreDeclarationModifierValue);

};
}
}
}

 
Disclaimer

All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

OTScriptDemo - PropertyLookup.zipOTScriptDemo - PropertyLookup.zip

[{"Product":{"code":"SSB2MU","label":"IBM Engineering Systems Design Rhapsody"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"General Information","Platform":[{"code":"PF033","label":"Windows"}],"Version":"8.0;8.0.1;8.0.2;8.0.3;8.0.4;8.0.5;8.0.6;8.1;8.1.1;8.1.2;8.1.2.1;8.1.3;8.1.4;8.1.5","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21993611