IBM Support

How to import ARXML file from another application to Rational Rhapsody using Java API

Question & Answer


Question

How do you import ARXML file from another application (OEMs) to IBM Rational Rhapsody using Java API?

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 import ARXML file from another application to Rational Rhapsody using JAVA API you can use the below code as a 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.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;

import com.telelogic.rhapsody.core.IRPApplication;
import com.telelogic.rhapsody.core.IRPModelElement;
import com.telelogic.rhapsody.core.IRPProject;
import com.telelogic.rhapsody.core.IRPTag;
import com.telelogic.rhapsody.core.RhapsodyAppServer;

public class ImportE2Es {

public static void main(String[] args) {

IRPApplication myApp = RhapsodyAppServer.getActiveRhapsodyApplication();
IRPProject myPrj = myApp.activeProject();
String file = "<Path to ARXML file>";
String tagValue = null;
String Name = null;

try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
int found = 0;
while ((line = br.readLine()) != null) {
   
if(line.contains("E2E")) {
found = 1;
tagValue = line.substring(line.indexOf('\"')+1, line.indexOf('>')-1);
}

if(line.contains("SHORT-NAME") && found == 1 ) {
Name = line.substring(line.indexOf('>')+1, line.indexOf('/')-1);
found = 0;

IRPModelElement myEle = myPrj.findNestedElementRecursive(Name, "ApplicationSoftwareComponentType");
Iterator myIter = myEle.getNestedElementsRecursive().toList().iterator();
while (myIter.hasNext()) {

IRPModelElement myEle1 = (IRPModelElement) myIter.next();
if(myEle1.getUserDefinedMetaClass().equals("Sdg")) {

IRPTag myTag = (IRPTag) myEle1.addNewAggr("Tag", "E2E");
myTag.setValue(tagValue);
}
}
}

}
br.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
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":"8.0;8.0.1;8.0.2","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21640710