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:
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 Synonym
Rational Rhapsody
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21600113