IBM Support

How to use Rhapsody Java API to retrieve the model element set in a tag

Question & Answer


Question

How do you use IBM Rational Rhapsody Java API to retrieve the model element which is set in a tag element?

Cause

You can call IRPTag.getValue() to obtain element name set in a tag or call IRPTag.getDeclaration() to further retrieve the element metaclass info; however, this is still not sufficient for you to easily retrieve the element itself which is set in a model tag.

Answer

You should call IRPTag.getValueSpecifications() and parse the returned collection into IRPInstanceValue data type. Sample code is shown as below.

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.


--------------------------------------Start---------------------------------------

IRPProject prj;

IRPApplication app;

IRPModelElement sel, elem;

IRPInstanceValue ins;

IRPTag tag;

IRPCollection valSpecs;

Iterator looper;

app = RhapsodyAppServer.getActiveRhapsodyApplication();

prj = app.activeProject();

sel = (IRPModelElement)app.getSelectedElement();

//if the selected element is an instance of Tag

if (sel instanceof IRPTag){

tag = (IRPTag)sel;

//call getValueSpecifications() to retrieve tag value collection

valSpecs = tag.getValueSpecifications();

looper = valSpecs.toList().iterator();

//call getValue() to retrieve each element instance set as the tag value

while (looper.hasNext()){

ins = (IRPInstanceValue)looper.next();

elem = ins.getValue();

}

}

---------------------------------------End---------------------------------------

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

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21655043