How to differentiate between different types of relationships?

My objective is to fetch all incoming links and outgoing links to and from any class. These links could include exchange items, associations, compositions, generalizations etc.

I use the semantic browser for simple models but for a general solution or larger models, it is impractical. For example, “Roles”, “Typing Elements” etc. are not consistent enough. It is hard to identify the parent and child of an element.

I tried fetching all contents of the data package folder but I am unable to differentiate between the different types of relationships. For example, in the following image, vce is a composition and class 3 is an aggregation.

How can I identify the type, parent (outgoing link) and child (incoming link) in P4C?

I think some extends are missing for the Property class:

But you can use the Java API:

for property in se.get_all_contents_by_type(Property):
    prt = property.get_java_object()
    print(prt.getName(), "type:" + prt.eClass().getName(), prt.isUnique(), prt.isIsReadOnly(), prt.getAggregationKind().getName())

To get the list of all EStructuralFeatures of the Property EClass you can use the following AQL expression in the Sirius interpreter view:

aql:information::Property.eAllStructuralFeatures

You will probably need to select a CapellaElement before getting the result.

If you need to check the type of an element against an EClass you can use:

roleECls = get_e_classifier("http://www.polarsys.org/capella/core/oa/" + capella_version(), "Role")
roleECls.isInstance(prt)

You can also get an enum literal:

association = get_enum_literal("http://www.polarsys.org/capella/core/information/" + capella_version(), "AggregationKind", "ASSOCIATION")
prt.getAggregationKind() = association

For a complete description of Capella metamodels (EPackages) you can have a look here.
I hope this will get you started with your script.

1 Like