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.
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 Synonym
Rational Rhapsody
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21655043