Question & Answer
Question
How do you extract operations from specific packages using JAVA Application Programming Interfaces (API) in IBM Rational Rhapsody?
Cause
You would like to use Java API code to automate the manual task to be performed with in Rational Rhapsody.
Answer
In order to extract operations from specific packages using JAVA API in Rational Rhapsody you can use the below code snippet as a 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.RhapsodyAppServer;
import com.telelogic.rhapsody.core.IRPApplication;
import com.telelogic.rhapsody.core.IRPOperation;
import com.telelogic.rhapsody.core.IRPProject;
import com.telelogic.rhapsody.core.IRPPackage;
import com.telelogic.rhapsody.core.IRPModule;
public class getOperations
{
public static void main(String[] args)
{
try
{
BufferedWriter out = new BufferedWriter(new FileWriter("C:\\Temp\\FunctionsList.txt"));
String scrPkg = null, destPkg = null;
System.out.print("Enter the source package name : ");
BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
try
{
scrPkg = br1.readLine();
}
catch (IOException ioe)
{
System.out.println("IO error !!");
System.exit(1);
}
System.out.print("Enter the destination package name : ");
BufferedReader br2 = new BufferedReader(new InputStreamReader(System.in));
try
{
destPkg = br2.readLine();
}
catch (IOException ioe)
{
System.out.println("IO error !!");
System.exit(1);
}
IRPApplication app = RhapsodyAppServer.getActiveRhapsodyApplication();
IRPProject actPro = app.activeProject();
for(Object o1:actPro.getPackages().toList())
for(Object o3:((IRPPackage)o1).getPackages().toList())
{
if(((IRPPackage)o3).getName().equals(scrPkg) || ((IRPPackage)o3).getName().equals(destPkg))
{
System.out.println("\n"+((IRPPackage)o3).getName()+"\n");
out.write("\n"+((IRPPackage)o3).getName()+"\n");out.newLine();
for(Object o2:((IRPPackage)o3).getModules().toList())
{
System.out.println("-----------------------------------------------------------");
for(Object o4:((IRPModule)o2).getNestedElementsRecursive().toList())
if(o4 instanceof IRPOperation)
{
System.out.print(((IRPOperation)o4).getOwner().getName()+" --> ");
System.out.println(((IRPOperation)o4).getName());
out.write(((IRPOperation)o4).getOwner().getName()+" --> ");
out.write(((IRPOperation)o4).getName());out.newLine();
}
System.out.println("-----------------------------------------------------------");
}
}
}
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
swg21439151