How to Retrieve Relationships from Models Using API

A relationship is a connection between model elements, which indicate model elements physically or logically related to each other. Different relationships in UML have their own semantics, and different model elements may have different sets of relationships which can apply to it. This article will show you the types of relationships in VP and how to retrieve them from your model elements.

Understanding types of relationships

There are mainly 2 types of relationship models; they are Simple Relationship and End Relationship. The Simple Relationship, as it name, it is the most simple form or relationship. It is just a relationship model directly connected to 2 model elements.

Simple Relationship

Simple Relationship

The End Relationship, on the other hand, is totally different to Simple Relationship. It is not directly connect to the source/destination model element. In fact, there is a Relationship End model element between the source/destination, and the relationship itself. The Relationship End may carry extra property for the relationships, i.e. the navigability of an association.

End Relationship

End Relationship

Most of the relationships in VP are Simple Relationships, except:

IAssociation: The most common relationships in UML, mainly used in Class Diagram

IInteractionLifeLineLink: The link used to connect lifeline in Communication Diagram

IMessage: Messages in Sequence Diagram

IConnector: Used in Composition Structure Diagram

Retrieve relationships from model element

Different types of relationships will have different methods for retrieve them. For the Simple Relationship, you can retrieve them by calling

IModelElement.fromRelationshipIterator()IModelElement.toRelationshipIterator()

For End Relationship, you can retrieve them by calling

IModelElement.fromRelationshipEndIterator()IModelElement.toRelationshipEndIterator()

These methods will return an iterator for the relationships. Besides retrieve through iterator, you can also use the ToArray() method to retrieve the elements in array form.

Navigation in relationships

You can use the getFrom() and getTo() methods to retrieve the connected model elements, no matter you are using Simple Relationship or End Relationship. But in End Relationship, you can also navigate by go through the relationship end. You can retrieve the relationship end by calling getFromEnd() and getToEnd().

Sample plugins

This sample plugin demonstrate how to retrieve relationships from a model element. Once you have deployed the plugin into VP Application, you can then right click on a shape and select Show Relationships – DEMO from popup menu.

Trigger plugin to show relationships

Trigger plugin to show relationships

By clicking this menu, a dialog will show up and list out both Simple Relationship and End  Relationship for the selected model element.

List out all the relationships of the selected element

List out all the relationships of the selected element

Download Sample Plugin

Related Articles

1277 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply