IBM Support

How to use Rhapsody Java API to set value to a tag

Question & Answer


Question

How do you use IBM Rational Rhapsody Java API to set value to a tag?

Cause

Rhapsody model allows you defining String or Rhapsody model element as the tag type. Besides, model element can have local tags and tags which are coming from assigned stereotype.

Answer

If you want to add a String value to tag, call API addStringDefaultValue(String newDefaultValue).

If you want to add Rhapsody model element as the value of tag, call API addElementDefaultValue(IRPModelElement newDefaultValue) instead.

Sample code for adding tags to class element 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;
IRPTag baseTag, newTag;

app = RhapsodyAppServer.getActiveRhapsodyApplication();


prj = app.activeProject();

//Find the element(class_0), you want to add tag with values.


IRPClass class_0 = (IRPClass)(prj.findNestedElementRecursive("class_0", "Class"));


//In order to set a value for a tag that comes from a stereotype, you need to quote
//the stereotype(stereotype_0)'s tag(tag_0) as its "base" tag
IRPStereotype stereotype_0 = (IRPStereotype)(prj.findNestedElementRecursive("stereotype_0", "Stereotype"));
baseTag = stereotype_0.getTag("tag_0");

//Return the newly created tag with value "value_A" and set it to class_0


newTag = class_0.setTagValue(baseTag, "value_A");

//Add other tags with different value to class_0, if the multiplicity > 1


newTag.addStringDefaultValue("value_B");
newTag.addStringDefaultValue("value_C");

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

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21663329