IBM Support

How to use New Term stereotypes with the Rhapsody API

Question & Answer


Question

How do you use New Term stereotypes with the IBM Rational Rhapsody API

Cause

Unable to create or access elements using the new term stereotype name

Answer

Here we will use the example of SysML constraint Blocks. Note you must be using the SysML profile with this example. See help for adding a profile to your project.

Since Constraint Blocks are a new term stereotype applied to Classes, you need to add a class and then apply the "ConstraintBlock" stereotype to that class. This is the same process for creating any non-UML type, including blocks. You can confirm this by checking the specific stereotype in the SysML profile.



The new term value is set to the UserDefinedMetaClass property of each element it is applied to.



Therefore, to retrieve the Constraint Blocks you must first retrieve all the classes, then use a condition on the UserDefinedMetaClass method to filter out the Constraint Blocks in the results.

Example Java code would be:


// create constraint blocks

IRPApplication app = RhapsodyAppServer.getActiveRhapsodyApplication();
IRPStereotype cbSType = (IRPStereotype)app.activeProject().findNestedElementRecursive("ConstraintBlock", "Stereotype");
IRPPackage pkg = app.activeProject().addPackage("TestPkg");
IRPClass cb1 = (IRPClass)pkg.addNewAggr("Class", "Test");
if(cbSType != null) {
cb1.setStereotype(cbSType);
}

// OR

IRPClass cb2 = (IRPClass)pkg.addNewAggr("Class", "Test2");
cb2.addStereotype("ConstraintBlock", "Class");

/// retrieve the constraint blocks

List<IRPModelElement> cbs = app.activeProject().getNestedElementsByMetaClass("Class", 1).toList();
for (IRPModelElement el : cbs) {
if(el.getUserDefinedMetaClass().equals("ConstraintBlock")) {
System.out.println(el.getName() + " - " + el.getUserDefinedMetaClass());
}
}


[{"Product":{"code":"SSB2MU","label":"IBM Engineering Systems Design Rhapsody"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"General Information","Platform":[{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"}],"Version":"7.6;7.6.0.1;7.6.1;7.6.1.1;7.6.1.2;7.6.1.3;7.6.1.4;7.6.1.5;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","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21969498