Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » When is an eObject's container set?
When is an eObject's container set? [message #1708200] Mon, 14 September 2015 15:13 Go to next message
erwin de ley is currently offline erwin de leyFriend
Messages: 49
Registered: August 2013
Member
Hi,

I would need to be able to keep an EMF model instance in sync with a matching Ptolemy II model, which also follows a strong container/containment approach. E.g. each time a model object is added in the EMF model, I would need to do the similar thing in Ptolemy.

Ptolemy details are not important for this topic, except that in there a model object needs to know its container at construction time. The container is mandatory in the constructor of each type of model element (except for the root element of course).

So I would need to figure out how I can plugin a listener or interceptor or so, at the right place in the EMF generated code, so it gets invoked after the EMF model object is constructed, and its eContainer has been set.

Can anyone point me out how this can be done?

Alternatively I could try to intercept the addition of a child object in its container, and work from there?

Remark that I could not find a way to implement the container as a model feature, related to a limitation in EMF/Ecore to override container types for subclasses... So I found that using eContainer was the simplest/only option to represent the container relationship. But it is not clear for me when an eContainer is set/"known" in the eObject's construction process.

thanks
erwin
Re: When is an eObject's container set? [message #1708227 is a reply to message #1708200] Mon, 14 September 2015 18:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30366
Registered: July 2009
Senior Member
Erwin,

Comments below.

On 14/09/2015 5:13 PM, erwin de ley wrote:
> Hi,
>
> I would need to be able to keep an EMF model instance in sync with a
> matching Ptolemy II model, which also follows a strong
> container/containment approach. E.g. each time a model object is added
> in the EMF model, I would need to do the similar thing in Ptolemy.
>
> Ptolemy details are not important for this topic, except that in there
> a model object needs to know its container at construction time. The
> container is mandatory in the constructor of each type of model
> element (except for the root element of course).
>
> So I would need to figure out how I can plugin a listener or
> interceptor or so, at the right place in the EMF generated code, so it
> gets invoked after the EMF model object is constructed, and its
> eContainer has been set.
The container being set and the object being constructed are completely
independent.
>
> Can anyone point me out how this can be done?
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eBasicSetContainer(InternalEObject,
int) is what sets the container.
>
> Alternatively I could try to intercept the addition of a child object
> in its container, and work from there?
>
> Remark that I could not find a way to implement the container as a
> model feature, related to a limitation in EMF/Ecore to override
> container types for subclasses...
I'm not sure I understand. You can model a container reference; it must
be the eOpposite of a containment reference.
> So I found that using eContainer was the simplest/only option to
> represent the container relationship. But it is not clear for me when
> an eContainer is set/"known" in the eObject's construction process.
It's never set during construction. It's set when an object is added to
(set into) a containment reference...
>
> thanks
> erwin
Re: When is an eObject's container set? [message #1708237 is a reply to message #1708227] Mon, 14 September 2015 20:46 Go to previous message
erwin de ley is currently offline erwin de leyFriend
Messages: 49
Registered: August 2013
Member
Ed,

Thanks for the prompt response, and apologies for not being complete.

The EMF model represents a deep containment structure representing a hierarchy of a root element, containing a collection of child entities where each such entity can contain further nested child-collections etc. So my question was about the situation where I add a child to a one-to-many containment association in its container, e.g. using a standard EMF/ecore editor.

I was getting lost a bit in the add and inverseAdd flows. The pointer to the eBasicSetContainer() method was what I needed.

thanks again,
erwin
Previous Topic:CDOLock notifications
Next Topic:best practice displaying EMF-elements in tables
Goto Forum:
  


Current Time: Fri Aug 23 02:06:34 GMT 2019

Powered by FUDForum. Page generated in 0.02177 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top