It's all about the answers!

Ask a question

Rhapsody Automation: How to add InterfaceBlock for ProxyPort using java program?


Vijayanand Karunanithi (1527) | asked Feb 26 '19, 7:50 a.m.
edited Mar 05 '19, 3:22 a.m.

 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.


Comments
Vijayanand Karunanithi commented Mar 06 '19, 12:52 a.m.

 Is there any updates on the reported query?


One answer



permanent link
Vijayanand Karunanithi (1527) | answered Mar 08 '19, 1:48 a.m.

 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


Register or to post 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.