Question & Answer
Question
How do you get Activity Diagram elements information using JAVA API in IBM Rational Rhapsody?
Cause
You would like to use Java Application Programming Interfaces [API] code to automate the manual task to be performed with in Rational Rhapsody or to achieve something that is not possible through the Rhapsody GUI.
Answer
In order to get Activity Diagram elements information using JAVA API in Rational Rhapsody you can use the below code as a reference. The code can be enhanced to include other specific element types.
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. |
---|
import java.util.Iterator;
import com.telelogic.rhapsody.core.IRPApplication;
import com.telelogic.rhapsody.core.IRPSwimlane;
import com.telelogic.rhapsody.core.IRPState;
import com.telelogic.rhapsody.core.IRPTag;
import com.telelogic.rhapsody.core.IRPTransition;
import com.telelogic.rhapsody.core.IRPStereotype;
import com.telelogic.rhapsody.core.IRPModelElement;
import com.telelogic.rhapsody.core.RhapsodyAppServer;
public class ActivityDiagramInfo {
public static void main (String[] args) {
IRPApplication myApp = RhapsodyAppServer.getActiveRhapsodyApplication();
IRPModelElement myEle = myApp.getSelectedElement();
System.out.print("Activity Diagram --> ");
System.out.println(myEle.getName());
Iterator sterIter = myEle.getStereotypes().toList().iterator();
while(sterIter.hasNext()){
Object contEleObj = sterIter.next();
IRPStereotype stereotype = (IRPStereotype) contEleObj;
System.out.print("Stereotype --> ");
System.out.println(stereotype.getName());
}
Iterator contEleIter = myEle.getNestedElementsRecursive().toList().iterator();
while(contEleIter.hasNext()){
Object contEleObj = contEleIter.next();
if (contEleObj instanceof IRPTag) {
IRPTag tag = (IRPTag) contEleObj;
System.out.print("Tag --> ");
System.out.print(tag.getName());
System.out.print("(Value: ");
System.out.print(tag.getValue());
System.out.println(")");
}
if (contEleObj instanceof IRPSwimlane) {
IRPSwimlane flow = (IRPSwimlane) contEleObj;
System.out.print("Swimlane --> ");
System.out.println(flow.getDisplayName());
}
if (contEleObj instanceof IRPTransition) {
IRPTransition flow = (IRPTransition) contEleObj;
System.out.print("Flow --> ");
System.out.println(flow.getDisplayName());
}
if (contEleObj instanceof IRPState) {
IRPState action = (IRPState) contEleObj;
if(action.getName().contains("ROOT"))
continue;
System.out.print("Action --> ");
System.out.println(action.getName());
}
}
}
}
Product Synonym
Rational Rhapsody
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21609850