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.
- Open the Configuration > Types window in Gateway and create a new Rhapsody type.
- 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.
- 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
- 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
![](/support/pages/system/files/support/swg/rattech.nsf/0/cb51bbba5079013385258060005d9906/Content/6.3EA4.jpg)
- 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 inoperationTypes
.
![](/support/pages/system/files/support/swg/rattech.nsf/0/cb51bbba5079013385258060005d9906/Content/12.4B0E.jpg)
- 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
.
![](/support/pages/system/files/support/swg/rattech.nsf/0/cb51bbba5079013385258060005d9906/Content/16.3880.jpg)
- Full Code:
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);
};
}
}
}
[{"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
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21993611