When is an eObject's container set? [message #1708200] |
Mon, 14 September 2015 15:13 |
Erwin De Ley Messages: 52 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 |
Ed Merks Messages: 33141 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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.03577 seconds