IBM Support

How to draw a statechart via IBM Rational Rhapsody JAVA API

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.

 
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();

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

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21962238