IBM Support

How to create Instance Specifications and Slots using the Rational Rhapsody API

Question & Answer


Question

How do you create Instance Specifications and Slots using the IBM Rational Rhapsody API?

Cause

It is not clear which API methods you should use to add a slot to a specification.

Answer

 
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.



IRPApplication app = RhapsodyAppServer.getActiveRhapsodyApplication();

/// Adding an attribute to an Instance Specification/Slot
IRPPackage pkg1 = (IRPPackage)app.activeProject().addPackage("InstanceSlotWithAttribute");
//the classifier
IRPClass class1 = pkg1.addClass("TestClass");
IRPAttribute att1 = class1.addAttribute("Att1");
// the instance spec
IRPInstanceSpecification spec1 = (IRPInstanceSpecification)pkg1.addNewAggr("InstanceSpecification", "Blah");
// set the instance spec classifier
spec1.setClassifier(class1);
// create an instance slot
IRPInstanceSlot slot1 = (IRPInstanceSlot)spec1.addNewAggr("InstanceSlot", "Slot1");
// set the slot attribute
slot1.setSlotProperty(att1);

/// Adding an association to an Instance Specification/Slot
IRPPackage pkg2 = (IRPPackage)app.activeProject().addPackage("InstanceSlotWithAssociation");
//the classifier(s)
IRPClass class2 = pkg2.addClass("Class2");
IRPClass class3 = pkg2.addClass("Class3");
IRPRelation assoc = class2.addRelation("Class3", "InstanceSlotWithAssociation", "itsClass3", "Association", "1", "itsClass2", "Association", "1", "test");
// the instance spec
IRPInstanceSpecification spec2 = (IRPInstanceSpecification)pkg2.addNewAggr("InstanceSpecification", "Blah");
// set an instance spec classifier
spec2.setClassifier(class2);
// create an instance slot
IRPInstanceSlot slot2 = (IRPInstanceSlot)spec2.addNewAggr("InstanceSlot", "Slot2");
// set the slot association
slot2.setSlotProperty(assoc);

[{"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","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21694303