|
Re: get all contained objects by EReference name [message #694026 is a reply to message #693816] |
Thu, 07 July 2011 16:33 |
Ed Merks Messages: 33133 Registered: July 2009 |
Senior Member |
|
|
Mirko,
Comments below.
On 07/07/2011 2:00 AM, forums-noreply@eclipse.org wrote:
> Hello,
> let's assume we have an Ecore model with a class ERoot. ERoot has two
> containment references "children1" of class EChild1 and "children2" of
> class EChild2.
>
> With the following code I reconstruct the two names "children1" and
> "children2" for the references of the root object (root is an ERootImpl):
>
> EList<Ereference> contains=root.eClass().getEAllContainments();
> for (EReference ref: contains){
> System.err.println(ref.getName());
> }
> But how can I get the EObjects referenced through "children{1,2}"
> inside the for-loop?
root.eGet(ref).
> Of course, I could use Java reflection, create the method name
> "getChildren1" from the name "children1" and invoke the method by this
> name string on the object root. But I would like to avoid using Java
> reflection. Instead of the methods root.get<ReferenceName>() I would
> need something like root.getObjectsByReferenceName("children1").
Given you know the name of the feature, do you really not know it's an ERoot
>
> Does EMF offer a method to find all EObjects referenced by a certain
> reference name or by a certain EReference? Can you point me to some
> article which answers questions like this?
Look at EObject.eGet. You might also be interested in the
EcoreUtil.CrossReferencers.
>
> Best,
> Mirko
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.01543 seconds