Question & Answer
Question
How do you use $name macro in properties not supporting the macro 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 or to achieve something that is not possible through the Rhapsody GUI.
Answer
In order to use $name macro in properties not supporting the macro, using JAVA API in Rational Rhapsody you can use the below code as a reference.
The script below works for the properties C_CG.Type.InOut, C_CG.Type.Out, C_CG.Type.In and the $name macro, but you can extend the same to other properties and macros as per need
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. |
---|
import java.util.Iterator;
import com.telelogic.rhapsody.core.IRPApplication;
import com.telelogic.rhapsody.core.IRPModelElement;
import com.telelogic.rhapsody.core.IRPProject;
import com.telelogic.rhapsody.core.RhapsodyAppServer;
public class nameMacro {
public static void main(String[] args) {
IRPApplication myApp = RhapsodyAppServer.getActiveRhapsodyApplication();
IRPProject myPrj = myApp.activeProject();
Iterator myIter = myPrj.getNestedElementsRecursive().toList().iterator();
while(myIter.hasNext()) {
Object myObj = myIter.next();
if(myObj instanceof IRPModelElement) {
IRPModelElement myEle = (IRPModelElement) myObj;
String myInPrp = myEle.getPropertyValue("C_CG.Type.In");
String myOutPrp = myEle.getPropertyValue("C_CG.Type.Out");
String myInOutPrp = myEle.getPropertyValue("C_CG.Type.InOut");
if(myInPrp.contains("$name"))
myEle.setPropertyValue("C_CG.Type.In", myInPrp.replace("$name", myEle.getName()));
if(myOutPrp.contains("$name"))
myEle.setPropertyValue("C_CG.Type.Out", myInPrp.replace("name", myEle.getName()));
if(myInOutPrp.contains("$name"))
myEle.setPropertyValue("C_CG.Type.InOut", myInOutPrp.replace("$name", myEle.getName()));
}
}
}
}
Product Synonym
Rational Rhapsody
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21609844