IBM Support

How to find a nested model element using JAVA API in Rational Rhapsody

Question & Answer


Question

How do you find a nested model element 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.

Answer

In order to find a nested model element in Rational Rhapsody you can use the following API calls available for IRPModelElement interface:

  1. findNestedElement(java.lang.String name, java.lang.String metaClass)


  2. findNestedElementRecursive(java.lang.String name, java.lang.String metaClass)

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.



The first API call method searches only at the specific level where it is being called whereas the second API call method searches at the level it is being called as well as all levels below it recursively.


Below is a code snippet illustrating the use of the above API methods:


IRPApplication myApp = RhapsodyAppServer.getActiveRhapsodyApplication();
IRPProject myPrj = myApp.activeProject();
myPrj.findNestedElement("package_0", "Package");
myPrj.findNestedElementRecursive("class_5", "Class");

[{"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.5;7.5.0.1;7.5.1;7.5.1.1;7.5.2;7.5.2.1;7.5.3;7.5.3.1;7.5.3.2;7.6;7.6.0.1","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21497908