Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Change class of a given EObject
Change class of a given EObject [message #755126] Mon, 07 November 2011 13:25 Go to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 333
Registered: July 2009
Senior Member
Hi there,

is there any practical way to change the class of a given EObject to a
subclass of that object?

e.g. I have a class "Person" and subclasses "Man" and "Woman".

For some reason I have an instance "Foo" of "Person", yet not knowing
the gender. Later I get the information that "Foo" is male but my model
has no gender attribute but uses subclasses for the gender.

Is there a way to "upgrade" the class of Foo from Person to Man?

A workaround would be to create a new Man, copy all attributes and
replace it in the containment hierarchy of Foo. However, there might be
cross-references to Foo which I also would need to switch to the new Man
instance.
Is there a good way to find all foreign references to Foo so I can
switch them to the new instance?

Rationale: I encounter quite often MM that code information in
subclasses rather than in attributes. This is nice for using
polymorphism, but bad for changing the objects as discussed above.

Any hint how to handle that?

Cheers,
Hauke
Re: Change class of a given EObject [message #755134 is a reply to message #755126] Mon, 07 November 2011 13:41 Go to previous messageGo to next message
Tatiana Fesenko is currently offline Tatiana FesenkoFriend
Messages: 62
Registered: July 2009
Member
Hi Hauke,

I think ATL refine transformation is something that can help you. Using
ATL in refinement mode is well documented. For example, in this ATL
tutorial -
http://www.slideshare.net/wpiers/modelt-to-model-transformation-withatl .

Cheers,
--
Tatiana Fesenko
ModelSolv, Inc.
Model-Oriented Solutions for Service Integration
Re: Change class of a given EObject [message #755136 is a reply to message #755134] Mon, 07 November 2011 13:45 Go to previous messageGo to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 333
Registered: July 2009
Senior Member
Am 07.11.2011 14:41, schrieb Tatiana Fesenko:
> I think ATL refine transformation is something that can help you. Using
> ATL in refinement mode is well documented. For example, in this ATL
> tutorial -
> http://www.slideshare.net/wpiers/modelt-to-model-transformation-withatl .

Hi Tatiana,

thanks for the hint to ATL. Looks like they were also considering this
as a common use case.

However, I'm using this from Xtend2 transformations and hence would
require a pure Java or Xtend solution. Maybe "refinement" would be a
good feature request for xtend then.

Cheers,
Hauke
Re: Change class of a given EObject [message #755179 is a reply to message #755126] Mon, 07 November 2011 15:38 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Hauke,

Comments below.

On 07/11/2011 2:25 PM, Hauke Fuhrmann wrote:
> Hi there,
>
> is there any practical way to change the class of a given EObject to a
> subclass of that object?
No.
>
> e.g. I have a class "Person" and subclasses "Man" and "Woman".
>
> For some reason I have an instance "Foo" of "Person", yet not knowing
> the gender. Later I get the information that "Foo" is male but my
> model has no gender attribute but uses subclasses for the gender.
>
> Is there a way to "upgrade" the class of Foo from Person to Man?
No.
>
> A workaround would be to create a new Man, copy all attributes and
> replace it in the containment hierarchy of Foo. However, there might
> be cross-references to Foo which I also would need to switch to the
> new Man instance.
> Is there a good way to find all foreign references to Foo so I can
> switch them to the new instance?
EcoreUtil has UsageCrossReferencer. You could look at DeleteCommand to
see how it's used.
>
> Rationale: I encounter quite often MM that code information in
> subclasses rather than in attributes. This is nice for using
> polymorphism, but bad for changing the objects as discussed above.
>
> Any hint how to handle that?
>
> Cheers,
> Hauke
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Ordered property not taken into account for equality checks ?
Next Topic:EMF and Xpath
Goto Forum:
  


Current Time: Tue Apr 16 07:14:19 GMT 2024

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

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

Back to the top