Question & Answer
Question
How do you update association relation after reverse engineering 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.
Answer
In order to update association relation after Reverse Engineering using JAVA API in Rational Rhapsody you can use the below code 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.util.Iterator;
import com.telelogic.rhapsody.core.IRPApplication;
import com.telelogic.rhapsody.core.IRPAttribute;
import com.telelogic.rhapsody.core.IRPClass;
import com.telelogic.rhapsody.core.IRPModelElement;
import com.telelogic.rhapsody.core.IRPProject;
import com.telelogic.rhapsody.core.IRPRelation;
import com.telelogic.rhapsody.core.RhapsodyAppServer;
public class createAssociations {
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 IRPAttribute) {
IRPAttribute myAtt = (IRPAttribute) myObj;
String Temp = myAtt.getDeclaration();
if(Temp.contains("* *")) {
String subTemp = Temp.substring(0,Temp.indexOf(' '));
IRPModelElement myEle = myPrj.findNestedElementRecursive(subTemp,"Class");
IRPClass myCls2 = null;
if(myEle==null)
myCls2 = (IRPClass) myAtt.getOwner().getOwner().addNewAggr("Class", subTemp);
else
myCls2 = (IRPClass) myEle;
IRPClass myCls1 = (IRPClass) myAtt.getOwner();
IRPRelation myRel = myCls1.addRelation(myCls2.getName(), myCls2.getOwner().getName(), myAtt.getName(), "Association", "", "","Association", "", "Test");
myRel.makeUnidirect();
myAtt.deleteFromProject();
}
}
}
}
}
Product Synonym
Rational Rhapsody
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21579162