Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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.

0 votes

Comments

 Is there any updates on the reported query?




One answer

Permanent link

 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);"


0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 11,079
× 1,729
× 419
× 1

Question asked: Feb 26 '19, 7:50 a.m.

Question was seen: 6,853 times

Last updated: Mar 08 '19, 1:48 a.m.

Confirmation Cancel Confirm