Rhapsody Automation: How to add InterfaceBlock for ProxyPort using java program?
I am trying to do some automation in Rhapsody for creating Internal Block Diagram.
As a part of it, i have created Blocks, InterfaceBlocks and ProxyPorts using java program.
If i try to add InterfaceBlock with ProxyPort, i am getting the error.
Please find the code snippet and error below.
Code:
IRPPackage rpPackage= findPackage(project, "Package2"); IRPPort port= (IRPPort)rpPackage.findNestedElementRecursive("Proxy_Ports_1", "ProxyPort"); IRPClass element = (IRPClass)rpPackage.findNestedElementRecursive("TESTINTERFACEBLOCK", "InterfaceBlock"); port.addProvidedInterface(element);
Error: Exception in thread "main" com.telelogic.rhapsody.core.RhapsodyRuntimeException: Cannot modify read only element (or element with read only owner) C:\ProgramData\IBM\Rational\Rhapsody\8.3x64\Share\Profiles\SysML\SysMLProfile_rpy\SysML.sbs.
at com.telelogic.rhapsody.core.RPPort.addProvidedInterfaceNative(Native Method)
at com.telelogic.rhapsody.core.RPPort.addProvidedInterface(Unknown Source)
Note: I have manually added the InterfaceBlock with ProxyPort and trying the fetch the information through program. It is working as expected and find the code used to fetch the information.
IRPCollection providedInterfaces = element.getProvidedInterfaces(); IRPModelElement item2 = (IRPModelElement) providedInterfaces.getItem(1);
System.out.println(item2.getName());
As I have used the same API(ProvidedInterface) to add InterfaceBlock, it should work as expected. Kindly guide me to resolve the error. |
One answer
Code: IRPPackage rpPackage= findPackage(project, "Package2"); IRPPort port= (IRPPort)rpPackage.findNestedElementRecursive("Proxy_Ports_1", "ProxyPort"); IRPClass element = (IRPClass)rpPackage.findNestedElementRecursive("TESTINTERFACEBLOCK", "InterfaceBlock"); port.addProvidedInterface(element);
In the above code, instead of addProvidedInterface method, use setContract. Then it is working as expected. "port.setContract(interfaceBlock);"
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.
Comments
Is there any updates on the reported query?