Question & Answer
Question
How do you get the ports for a Link or Connector 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
You can use one of the methods below in order to get the ports for a Link or Connector:
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. |
---|
Method 1: For Standard ports connected via link or connector.
For standard ports you can make use of the API calls IRPPort getFromPort() and IRPPort getToPort()
The following code snippet returns the 'from' and 'to' ports correctly and no null pointer exception is thrown.
IRPModelElement moEle = app.getSelectedElement();
IRPLink link = (IRPLink)moEle;
System.out.println(link.getName());
System.out.println(link.getFromPort().getName());
System.out.println(link.getToPort().getName());
]
Method 2: For Flow ports (SysML ports) connected via link or connector. For Flow ports you can make use of the API calls IRPSysMLPort getFromSysMLPort() and IRPSysMLPort getToSysMLPort() The following code snippet returns the from and to Flow [SysML] ports correctly and no null pointer exception is thrown. [
IRPModelElement moEle = app.getSelectedElement();
IRPLink link = (IRPLink)moEle;
System.out.println(link.getName());
System.out.println(link.getFromSysMLPort().getName());
System.out.println(link.getToSysMLPort().getName());
Product Synonym
Rational Rhapsody
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21442664