Question & Answer
Question
How do you draw a statechart including State, Transition, Default Transition using IBM Rational Rhapsody JAVA API?
Cause
You would like to use Java Application Programming Interfaces [API] code to automate the manual task to draw a statechart with in Rational Rhapsody.
Answer
You can use below sample to draw a statechart including State, Transition, Default Transition using Rhapsody JAVA API.
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();
IRPProject iprj = app.activeProject();
IRPPackage ipkg = iprj.addPackage("testPkg");
IRPClass icls = ipkg.addClass("testCls");
IRPStatechart sc = icls.addStatechart();
IRPState rootstate = sc.getRootState();
IRPState action1 = rootstate.addState("action1");
IRPGraphNode gn1 = sc.addNewNodeForElement(action1, 100, 100, 100, 100);
IRPState action2 = rootstate.addState("action2");
IRPGraphNode gn2 = sc.addNewNodeForElement(action2, 300, 100, 100, 100);
IRPState term = rootstate.addTerminationState();
IRPGraphNode gn3 = sc.addNewNodeForElement(term, 500, 150, 0, 0);
IRPTransition defTrans = action1.createDefaultTransition(rootstate);
sc.addNewEdgeForElement((IRPModelElement)defTrans, null, 50, 150, gn1, 100, 150);
IRPTransition trans = action1.addTransition(action2);
sc.addNewEdgeForElement((IRPModelElement)trans, gn1, 200, 150, gn2, 300, 150);
IRPTransition tranTerm = action1.addTransition(action2);
sc.addNewEdgeForElement((IRPModelElement)tranTerm, gn2, 400, 150, gn3, 500, 150);
Product Synonym
Rational Rhapsody
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21962238