Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » One way cross document reference to any EObject
One way cross document reference to any EObject [message #774121] Tue, 03 January 2012 09:55 Go to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
Hi,

I am implementing a simple decoration framework which would allow attaching decorators to any EObject of some ecore model. The model is stored in a model file on the disk and decorators in decorators file. What I need is a general Decorator interface which can reference any EObject contained in some model. This reference should be persisted in the decorators file. Is there some good and clean solution to this? What I am doing now is that in my decorators model I have a data type with instance class EObject and I have overriden convertToString method to return the EObject's URI and createFromString method which simply creates a proxy contaning the URI.

I wonder if this is a good solution according to experienced EMF masters. Of course I need the opposite direction as well - return a correct decorator instance of decorated EObject without the EObject knowing of being decorated. One of two things which come to my mind is to store decoratore in eAdapters list of the EObject. Second one is to use IdentityHashMap which will map EObjects to their decorators and will be stored in the decorators file.

Than you for you opinions
Re: One way cross document reference to any EObject [message #774257 is a reply to message #774121] Tue, 03 January 2012 15:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33146
Registered: July 2009
Senior Member
Martin,

Comments below.

On 03/01/2012 10:55 AM, Martin odloucký wrote:
> Hi,
> I am implementing a simple decoration framework which would allow
> attaching decorators to any EObject of some ecore model. The model is
> stored in a model file on the disk and decorators in decorators file.
> What I need is a general Decorator interface which can reference any
> EObject contained in some model.
An EReference of type EObject...
> This reference should be persisted in the decorators file. Is there
> some good and clean solution to this?
Yes, it should just work.
> What I am doing now is that in my decorators model I have a data type
> with instance class EObject and I have overriden convertToString
> method to return the EObject's URI and createFromString method which
> simply creates a proxy contaning the URI.
I think you want to use the EObject EClass, the one from the Ecore
package, as the type of an EReference and all should work nicely.
> I wonder if this is a good solution according to experienced EMF masters.
No.
> Of course I need the opposite direction as well - return a correct
> decorator instance of decorated EObject without the EObject knowing of
> being decorated. One of two things which come to my mind is to store
> decoratore in eAdapters list of the EObject.
That wouldn't be persistent though. Better you build up a map from
reading in the other direction. Or use an EMap, where the key is a
EReference of type EObject and the value is a containment reference to
the decorator.
> Second one is to use IdentityHashMap which will map EObjects to their
> decorators and will be stored in the decorators file.
> Than you for you opinions


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: One way cross document reference to any EObject [message #774680 is a reply to message #774257] Wed, 04 January 2012 11:53 Go to previous messageGo to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
Thank your very much Ed, this works like a charm. However I alwayes had a doubt about referencing classes from ecore in my model which is to me like referencing a metamodel from its model. This seemed somehow inappropriate to me. Are there some information or advice when such a thing is consdired a good design and where it is a dirty trick?

Ed Merks wrote on Tue, 03 January 2012 10:52
Martin,
> I wonder if this is a good solution according to experienced EMF masters.
No.


Very simple and nice answer, really made me laugh. Smile
Re: One way cross document reference to any EObject [message #774719 is a reply to message #774680] Wed, 04 January 2012 13:22 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33146
Registered: July 2009
Senior Member
Martin,

Comments below.

On 04/01/2012 12:53 PM, Martin odloucký wrote:
> Thank your very much Ed, this works like a charm.
We do this in other models, such as the Change model, so I know it will
work. :-)
> However I alwayes had a doubt about referencing classes from ecore in
> my model which is to me like referencing a metamodel from its model.
Most of the EDataTypes in Ecore, as well as EObject, are really
fundamental things much like the built-in types in Java such as int and
Object...
> This seemed somehow inappropriate to me.
Extending Ecore is a bad idea, but reusing it is fine.
> Are there some information or advice when such a thing is consdired a
> good design and where it is a dirty trick?
Not really. Just ask and you'll get opinions and advice.
>
> Ed Merks wrote on Tue, 03 January 2012 10:52
>> Martin,
>> > I wonder if this is a good solution according to experienced EMF
>> masters. No.
>
>
> Very simple and nice answer, really made me laugh. :)
Not only do we inform, we also entertain. :-P


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:How to create a cluster of model elements with EMF commands
Next Topic:EMF / GWT custom datastore usage
Goto Forum:
  


Current Time: Fri May 10 08:37:20 GMT 2024

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

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

Back to the top