IBM Support

How to achieve array parameter type modeling for argument types using JAVA API in Rational Rhapsody

Question & Answer


Question

How do you achieve array parameter 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 the Rhapsody GUI.

Answer

In order to achieve array parameter type modeling of argument types we can use the description field.

The below script leverages this idea of modeling argument types (using @Array in the description field) as a array parameter.


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.



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";
    String arrPrpVal = "$type";

    if(argDesc.contains("@Array")) {
     int startPos = argDesc.indexOf('[');
     int endPos = argDesc.indexOf(']');
     arrPrpVal += "[" + argDesc.substring(startPos + 1, endPos) + "]";
     if(argDir.equals("In"))
      myArg.setPropertyValue(inPrpKey, arrPrpVal);
      else if(argDir.equals("Out"))
       myArg.setPropertyValue(outPrpKey, arrPrpVal);
      else
       myArg.setPropertyValue(inoutPrpKey, arrPrpVal);
    }
   }
  }
 }
}

[{"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.5;7.5.0.1;7.5.1;7.5.1.1;7.5.2;7.5.2.1;7.5.3;7.5.3.1;7.5.3.2;7.6;7.6.0.1;7.6.1;7.6.1.1","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21589057