Question & Answer
Question
How do you achieve pointer (*) type modeling for argument types 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 Rational Rhapsody GUI.
Answer
In order to achieve pointer (*) type modeling of argument types you can use the description field.
The following script leverages this idea of modeling argument types (using the description field) as pointer, constant, pointer pointer, etc and as per the modeling technique used specific argument properties are updated to generate the desired code.
The script understands the following modeling constructs (in the description field) for an argument:
- @Constant - constant type
- @Pointer - pointer type
- @*Pointer - pointer pointer type
- @*Constant - constant pointer type
- Absence of above constructs - default type
The workflow for achieving the desired code generation:
- Model the arguments in the model using the constructs as mentioned above
- Once the desired modeling technique is achieved run the java script
- Once the script execution is complete, generate the code
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.IRPArgument;
import com.telelogic.rhapsody.core.IRPProject;
import com.telelogic.rhapsody.core.RhapsodyAppServer;
public class argTypeGen {
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 IRPArgument) {
IRPArgument myArg = (IRPArgument) myObj;
String argDesc = myArg.getDescription();
String argDir = myArg.getArgumentDirection();
String inPrpKey = "C_CG.Type.In";
String outPrpKey = "C_CG.Type.Out";
String inoutPrpKey = "C_CG.Type.InOut";
String cnstPrpVal = "const $type";
String pntrPrpVal = "$type*";
String pntrPntrPrpVal = "$type**";
String pntrCnstPrpVal = "const $type*";
String prpVal = "$type";
if(argDesc.contains("@Constant")) {
if(argDir.equals("In"))
myArg.setPropertyValue(inPrpKey, cnstPrpVal);
else if(argDir.equals("Out"))
myArg.setPropertyValue(outPrpKey, cnstPrpVal);
else
myArg.setPropertyValue(inoutPrpKey, cnstPrpVal);
}
else if(argDesc.contains("@Pointer")) {
if(argDir.equals("In"))
myArg.setPropertyValue(inPrpKey, pntrPrpVal);
else if(argDir.equals("Out"))
myArg.setPropertyValue(outPrpKey, pntrPrpVal);
else
myArg.setPropertyValue(inoutPrpKey, pntrPrpVal);
}
else if(argDesc.contains("@*Pointer")) {
if(argDir.equals("In"))
myArg.setPropertyValue(inPrpKey, pntrPntrPrpVal);
else if(argDir.equals("Out"))
myArg.setPropertyValue(outPrpKey, pntrPntrPrpVal);
else
myArg.setPropertyValue(inoutPrpKey, pntrPntrPrpVal);
}
else if(argDesc.contains("@*Constant")) {
if(argDir.equals("In"))
myArg.setPropertyValue(inPrpKey, pntrCnstPrpVal);
else if(argDir.equals("Out"))
myArg.setPropertyValue(outPrpKey, pntrCnstPrpVal);
else
myArg.setPropertyValue(inoutPrpKey, pntrCnstPrpVal);
}
else {
if(argDir.equals("In"))
myArg.setPropertyValue(inPrpKey, prpVal);
else if(argDir.equals("Out"))
myArg.setPropertyValue(outPrpKey, prpVal);
else
myArg.setPropertyValue(inoutPrpKey, prpVal);
}
}
}
}
}
Product Synonym
Rational Rhapsody
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21586838