eContainer() OK with Python4Capella--> What about eContainer(eClass)?

I am trying to reproduce the eContainer(eClass) in Python4Capella.
This helps to obtain the eContainer element when you don’t know priori where the targeted class is located.
It can be used to find the Logical Architeture in top of a vert low level sub logical component. Or to find the Capella Module of a Capella Requirement. etc.

Let’s say my tree is like this:

I want to obtain the Capella Module, starting from the REQ (which text is “Any Random…”).

Let’s say our REQ variable is A:


org.polarsys.kitalpha.vp.requirements.Requirements.impl.FolderImpl@5a215b15 (id: 8a40b2b2-9aae-427b-a26f-f60a3304cc35) (ReqIFIdentifier: null, ReqIFDescription: null, ReqIFLongName: null) (ReqIFName: Folder, ReqIFPrefix: null, ReqIFChapterName: null, ReqIFForeignID: null, ReqIFText: null, requirementTypeProxy: null)

Now let’s say we don’t know where is the Capella Module is located, we can’t use a double “eContainer()”.

What is obvious would be to try the following:

  1. A.eContainer(Requirements::Module)
  2. A.eContainer("Requirements::Module")
  3. A.eContainer(variableContainingCapellaModule*)

(*) = org.eclipse.emf.ecore.impl.EClassImpl@5a9bb7dd (name: CapellaModule) (instanceClassName: null) (abstract: false, interface: false)

  1. A.eContainer(variableContainingCapellaModule_Eclass**)

(*2) = org.polarsys.capella.vp.requirements.CapellaRequirements.impl.CapellaModuleImpl@48acdfe0 (id: 14187bb6-a635-4a3c-9d6e-371b45254adc) (ReqIFIdentifier: null, ReqIFDescription: null, ReqIFLongName: null) (ReqIFName: null, ReqIFPrefix: null)

As you might expect, this failed.

How could we tackle this? There must be a way to reproduce the “eContainer(eClass)” other than iterating multiple "eContainer()"s and checking their eClass name, what do you think?

Thanks a lot.

Best regards,

You will need to loop over all eContainer() until your container is None or it is of the wanted type. You can add such method in the EObject class in the file. You can have a look at the implementation of get_all_contents_by_type() to see how the type checking can be done.

I opened the following issue:

1 Like