IBM Support

How to create a part with type of a nested block in IBM Rational Rhapsody using Java API

Question & Answer


Question

How do you create a part with type of a nested block in IBM Rational Rhapsody by using Java API.

Cause

RhapsodyRuntimeException would occur when calling below Java API to create a part in the model with type of a nested block.


RPPackage.addGlobalObject(java.lang.String name, java.lang.String otherClassName, java.lang.String otherClassPackageName)

Answer

Follow below code snippet to create a new part with type of a nested block.

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 proj = app.activeProject();

//find the nested block you want to create part from
IRPClass nestedBlock = (IRPClass)proj.findNestedElementRecursive("block_2","Class");

//find the package you want to add the part to
IRPPackage ownerPkg = (IRPPackage)proj.findNestedElementRecursive("pkg_0","Package");

//First add a new part with implicit type to the package
ownerPkg.addImplicitObject("partOfNestedBlock");

//Then update the part type to the nested block
IRPInstance insPart = (IRPInstance)proj.findNestedElementRecursive("partOfNestedBlock","Object");
insPart.setOtherClass((IRPClassifier)nestedBlock);

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

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21700234