IBM Support

How to create a Sequence Diagrams with Java API in IBM Rational Rhapsody

Question & Answer


Question

How do you create a Sequence Diagram and add a realized message between two classifier roles?

Cause

The sequence diagram can not be created directly from IRPApplication.

Answer

You need to create a Collaboration object first, then add the classes and operations to that object.

Procedure:

  1. // setup objects for sequence diagram
    IRPApplication app = RhapsodyAppServer.getActiveRhapsodyApplication();
    IRPPackage pkg = (IRPPackage)app.getSelectedElement();
    IRPClass ClassA = pkg.addClass("ClassA");
    IRPClass ClassB = pkg.addClass("ClassB");
    IRPOperation OpB = ClassB.addOperation("OperationB");

  2. //create collaboration for SD behaviour
    IRPCollaboration Collab = app.activeProject().getNewCollaboration();

  3. // add objects to collab object
    IRPClassifierRole crClassA = Collab.addClassifierRole("ClassA", ClassA);
    IRPClassifierRole crClassB = Collab.addClassifierRole("ClassB", ClassB);
    IRPMessage msg = Collab.addMessage(OpB, "", crClassA, crClassB);

  4. // Create sequence diagram from collaboration object
    IRPSequenceDiagram SD = Collab.generateSequence("MySD", pkg);

[{"Product":{"code":"SSB2MU","label":"IBM Engineering Systems Design Rhapsody"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Documentation","Platform":[{"code":"PF033","label":"Windows"},{"code":"PF016","label":"Linux"}],"Version":"7.5;7.5.0.1;7.5.1;7.5.1.1;7.5.2;7.5.2.1;7.5.3;7.5.3.1;7.5.3.2;7.5.3.3;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;8.0;8.0.1;8.0.2;8.0.3;8.0.4","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21642098