IBM Support

How to create a file of dependency list using JAVA API in Rational Rhapsody

Question & Answer


Question

How do you create a file of dependency list 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 create a file of dependency list using JAVA API you can use the below code as reference:

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.io.*;

import com.telelogic.rhapsody.core.IRPApplication;
import com.telelogic.rhapsody.core.IRPDependency;
import com.telelogic.rhapsody.core.IRPModule;
import com.telelogic.rhapsody.core.IRPClassifier;
import com.telelogic.rhapsody.core.IRPClass;
import com.telelogic.rhapsody.core.IRPModelElement;
import com.telelogic.rhapsody.core.IRPPackage;
import com.telelogic.rhapsody.core.IRPProject;
import com.telelogic.rhapsody.core.IRPOperation;
import com.telelogic.rhapsody.core.RhapsodyAppServer;

public class CreateDependencyList {
 public static void main(String[] args) {
  try {
   BufferedWriter out = new BufferedWriter(new FileWriter("C:\\Temp\\DepList.txt"));
   IRPApplication app = RhapsodyAppServer.getActiveRhapsodyApplication();
   IRPModelElement selectedElem = (IRPModelElement)app.getSelectedElement();
   if(selectedElem.getMetaClass().equals("Package")) {
    IRPPackage pkg = (IRPPackage)selectedElem;
    for(Object o:pkg.getNestedElementsRecursive().toList()) {
     if(o instanceof IRPDependency) {
      IRPDependency dep = (IRPDependency)o;
      IRPModule  dependentmod =null;
      IRPModule  dependsOnmod =null;
       try {
if(dep.getDependent().getUserDefinedMetaClass().equals("Class"))
dependentmod = (IRPModule)dep.getDependent().getOwner();
else
dependentmod = (IRPModule)dep.getDependent().getOwner().getOwner();
if(dep.getDependsOn().getUserDefinedMetaClass().equals("Class"))
dependsOnmod=(IRPModule)dep.getDependsOn().getOwner();
else
dependsOnmod= (IRPModule)dep.getDependsOn().getOwner().getOwner();
       } catch (ClassCastException e) {
       continue;
      }

     String flowName = dependentmod.getName()+" "+dependsOnmod.getName();
     System.out.println(flowName);
     out.write(flowName);out.newLine();

     IRPClassifier myCls = (IRPClassifier) (dependentmod.getOfClass());
     IRPModelElement myEle = myCls.getOwner().findNestedElementRecursive(dependentmod.getName(), "Class");
     IRPClass myCls1 = (IRPClass) myEle;
     for(Object o1:myCls1.getOperations().toList()) {
      System.out.print(((IRPOperation)o1).getName()+" ");
      out.write(((IRPOperation)o1).getName()+" ");
     }
     IRPClassifier myCls2 = (IRPClassifier) (dependsOnmod.getOfClass());
     IRPModelElement myEle2 = myCls2.getOwner().findNestedElementRecursive(dependsOnmod.getName(), "Class");
     IRPClass myCls3 = (IRPClass) myEle2;
     for(Object o2:myCls3.getOperations().toList()) {
      System.out.print(((IRPOperation)o2).getName()+" ");
      out.write(((IRPOperation)o2).getName()+" ");
     }
    System.out.println();out.newLine();
   }
  }
 }
 else
  System.out.println("OOPS !!! Package not selected.");
  out.close();
 } catch (IOException e) {
 System.err.println("Something went wrong");
 e.printStackTrace();
 }
 }
}

[{"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

swg21600113