Gettings the Components Ports from Components exchanges and the Use of capella_query_by_name

Hello,
I obtained a component port (logical) on a variable:

org.polarsys.capella.core.data.fa.impl.ComponentExchangeImpl@4f10be65 (id: eed

I also have the python object, let’s call it “CP_py”,
Metamodel shows the following:

I would like to get its logical ports:

  1. I could try sourcePort or targetPort:
CP_py.get_java_object().sourcePort

Broken → Generates a javaMember!

  1. I figured I could use capella_query_by_name maybe?

The API shows things like:

def get_allocated_functional_exchanges(self):
        """
        """
        return capella_query_by_name(self, "Allocated Functional Exchanges")`Preformatted text`

I thought I could use the same:
Source=capella_query_by_name(CP_py, "Source Port")
→ I obtain an empty list.
Question: How do you figure which string to put inside (capella_query_by_name)?
The metamodel shows “allocatedFunctionalExchanges” as being an operation/function I guess, whereas “sourcePort” was only an attribute? That’s why it did not work? Any method to call that attribute without getting a javaMember? I don’t see eInverse being used here is it?

  1. There is a function that should get you the components ports:
def get_connected_component_ports(self):
        """
        """
        return create_e_list(self.get_java_object().getConnectedComponentPorts(), ComponentPort)`Preformatted text`

This one seem to produce errors, especially: “getConnectedComponentPorts()”.

Thanks for any help.

Hi Kabe,
(just to mention that at the beginning of your message, what you got is a Component Exchange, not a port, just a typo I suppose)

1 - If you see sourcePort in the Interpreter view, the method in Java will be getSourcePort (same for target)

2 - to know what query you can call on an object, select your element in the project explorer and send it to the Semantic Browser. There you will see the queries you can make on this element… and the results you will get.

3 - I just logged an issue regarding this one hour before your post… PhysicalLink: get_connected_physical_ports does not work · Issue #163 · labs4capella/python4capella · GitHub

Stephane Lacrampe
Obeo Canada

2 Likes

Hey thanks a lot for the answer,

So for ANY paramater/attribute i see in the interpreter, let’s say “attributeAttribute”, i can assume that a method similar to the following exists:
.getAttributeAttribute() ?
As for methods shown on the interpreter, let’s say “methodMethodMethod” you can use the capella querry by inserting a string similar to the following:
“Method Method Method” (assuming that “methodMethodMethod” is the name of the method) → adding spaces and capitalizing the first letter.

Sending to the semantic browser, what do you mean exaclty by that?
Are you talking about this:

I am asking because when i selected this, i got a view that would not show any queries, instead it showed: current element, referenced elements and referencing elements. Maybe I missed one step.

  1. Thanks! It seems we are doing the same work haha

as for the first typo, you are right I meant component exchange.

Thanks again it works.
Final note, I am thinking I could have found that method by going to CS maybe and making a component exchange variable then CTRL+SPACE maybe…

Hi Kabe,
More answers:

1 - “So for ANY paramater/attribute i see in the interpreter, let’s say “attributeAttribute”, i can assume that a method similar to the following exists:
.getAttributeAttribute() ?” → Yes that’s how it works. And Yes because what you displayed in your image is the eClass of the current object. That works for all the attributes and properties on your object.
If instead, you use the completion on “self.” in the interpreted view, the completion is giving you more method like “siblings”, “eResource”… For these ones, rules are a little bit different I think, eResource would be eResource() in java (not adding the get in front)

"As for methods shown on the interpreter, let’s say “methodMethodMethod” you can use the capella querry by inserting a string similar to the following:
“Method Method Method” (assuming that “methodMethodMethod” is the name of the method) → adding spaces and capitalizing the first letter." → Absolutely not. I am not even sure what you mean by “method” here, but the only thing you can call with a query are the queries in from the semantic Browser - this is what capella_query_by_name is done for

2 - Yes I am talking about “Show in Sematic Browser”. For example, these are the queries you can call on a PC Behavior:
querries2

Note that this may not be exhaustive, as queries that do not give any result are not displayed in the semantic browser view (for example, if I don’t have any function allocated on my component, then I would not see the query “Allocated Physical Functions”).

Stephane

1 Like

Very interesting!
You know that you, me and @YvanLussaud, are the only 3 people in the forum with a particular badge? Thank You - Eclipse Capella Forum (mbse-capella.org)

I was quite susprised to get that :slight_smile:


You mentioned self. offering more results, such as siblings or eRessources.
Are ‘siblings’ linked somehow to super types on the class diagram / ecore… of the metamodel?

  1. Just for the sake of curiosity/mastery, could you give me an example of a sibling for a component exchange (or in your case a physical component)? If there are any.
  2. Same for an eResource, if there are any.

I meant “operation” or “function”,
I assumed that all these (eReferences?) were functions:

And when I saw the Capella API having a function that makes use “capella_query” with the following string: “Allocated Functional Exchanges”, I assumed wrongfully we could do the same with all the elements in the picture above:

  • capella_query_by_name(self, “Incoming Component Exchange Realizations”)
  • capella_query_by_name(self, “categories”)

There is no other method to “know” what are all the strings accepted in capella_query_by_name, other than the semantic browser?

1 Like
  • “I was quite happy to get that :slight_smile:” → Did not see that, awesome!! And thanks for helping on the forum!!
  • siblings/eResource: I do not really know/I am unsure, maybe Yvan can provide some insights here
  • “There is no other method to “know” what are all the strings accepted in capella_query_by_name, other than the semantic browser?” → There probably is, one would be to look into the Capella code, but again maybe Yvan has some insights on that.

Stephane

1 Like

Some services offered by the completion comes from the runtime library of AQL. Some of them directly expose EMF methods to AQL users, but some other are specific to AQL. For the specific ones you will need to make your own implementation.

  1. siblings are all objects in the same container as the current object:
  • O
    • O1
      • O11
    • O2
    • O3

O2.siblings() will return a collection with O1 and O2 and O2.followingSiblings() will return a collection containing O3.

  1. the resource is an object containing a model in EMF. If can be an XMI file but it can also be a resource in a CDO server or … Its URI give a way to access it from a ResourceSet.

EMF generate Java classes from a metamodel (.ecore file) and those classes declares methods corresponding to EStructuralFeatures of the EClass. The generation use a naming pattern:

  • getFeatureName : for all features
  • setFeatureName : for single value features

All methods starting with “e” are EMF specific features that mainly allows:

  • navigating from the model to its metamodel to query its structure
  • navigating the modele without knowning its structure

The capella_query_by_name() allows to launch queries from the semantic browser of Capella, using the section name displayed in it.

To know all the possible names, you will need to check plugin.xml files (of Capella and addons) for the following extension contribution:

org.polarsys.capella.common.ui.toolkit.browser.contentProviderCategory

There is an utility class that does that in the M2Doc Capella extensions. It produce the code form the semantic browser services. You can use this class to see a list of available queries. But the name is only available in the plugin.xml (see this example).

1 Like

I forgot, there is one method to do this with Python4Capella:

available_query_names(myEObject)
1 Like

Quite poweful responses in this forum thread! Thanks a lot
I will investigate it, check the function, but also check that contentProviderCategory thing when I can.

.

I am grateful for the explanation, dont get me wrong , but: are all complexe programs like that? It seems Capella contain SO MANY java files that are connected with so many classes from so many components, I remember reading about description of Capella, it has a image showing Kitalpha(/sirius?) and other things. Then I later heard of GMF, oh and let’s not forget EMF for eclipse based programs, and Extended Editing Framework (EEF ) .

Yes Capella provide a metamodel that is a bit complex and also rely on other frameworks related to EMF:

  • Kitalpha provides an extension mecanism to Capella
  • Sirius provides graphical editors. It rely on GMF.
  • EEF extends features from EMF Edit. It helps creating forms and dialogs to edit EMF models. It’s also integrated with Sirius.
1 Like

Hello,
Sorry could not watch the webinar today, maybe someone is still here today,
here my follow up question:
Is there a reason “capella querry by name” uses syntaxes with “S” and sometimes without?
Let me illustrate:
image

Here we have these 2 features ending with “S”,
But when using the function capella query, I found that “S” had to be removed from the first one but not from the second one:

I wondered if there was any reason, if yes I could predict the right strings to put incapella_query moving forwards maybe.

There is absolutely NO RELATION between queries from the Semantic Browser and the queries you are doing using the Sirius interpreter.

  • Queries you do with the Sirius Interpreter navigate the Capella meta-model.
  • Queries from the Semantic Browser have their own coding/business logic (sometimes pretty complex) and hide some complexity of the Capella meta-model.

So absolutely no relation between these two things. Therefore no relation in naming.