Question & Answer
Question
I have a sequence diagram and need to use the JAVA API to find all of the other sequence diagrams that are referenced in the current sequence diagram.
Answer
Use getGraphicalElements() on the top level sequence diagram and look for graphic element associated with a metatype = InteractionOccurence.
See example code:
public class test {
static Boolean foundRefSeqDiagram = false;
public static void main(String[] args) {
IRPApplication app = RhapsodyAppServer.getActiveRhapsodyApplication();
IRPModelElement el = app.getSelectedElement();
// get selected sequence diagram
if (el instanceof IRPSequenceDiagram)
{
IRPSequenceDiagram sd = (IRPSequenceDiagram)el;
System.out.println("Searching sequence diagram: " + sd.getName());
//get all graphic elements from sequence diagram
@SuppressWarnings("unchecked")
List<Object> graphObjList = sd.getGraphicalElements().toList();
for(Object graphObj : graphObjList)
{
if(graphObj instanceof IRPGraphNode)
{
IRPGraphNode graphNode = (IRPGraphNode)graphObj;
// try to find the associated model element
try
{
IRPModelElement graphModelElement = graphNode.getModelObject();
System.out.println("\tFound " + graphModelElement.getMetaClass());
// look for nested ref seq diagram
if(graphModelElement instanceof IRPInteractionOccurrence)
{
IRPInteractionOccurrence io = (IRPInteractionOccurrence)graphModelElement;
IRPSequenceDiagram refSeqDiagram = io.getReferenceSequenceDiagram();
System.out.println("\t\tFound reference (nested) sequence diagram: " + refSeqDiagram.getFullPathName());
// highlight the item in the Rhapsody UI
app.highLightElement(refSeqDiagram);
foundRefSeqDiagram = true;
}
}
catch(Exception e)
{
// the graphic element is graphical only e.g. a note or anchor. skip it.
System.out.println("\tNo model element for " + graphNode.getGraphicalProperty("Type").getValue());
}
}
}
if(!foundRefSeqDiagram)
{
System.out.println("\tNo reference sequence diagrams found! Try a different diagram?");
}
}
else
{
System.out.println("Please select a sequence diagram and try again.");
}
}
}
[{"Line of Business":{"code":"LOB59","label":"Sustainability Software"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSB2MU","label":"IBM Engineering Systems Design Rhapsody"},"ARM Category":[{"code":"a8m50000000CjZTAA0","label":"Rhapsody->Tools->Java API"}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Version(s)"}]
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
ibm16382836