Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Override eSet()... Should I?
Override eSet()... Should I? [message #885782] Wed, 13 June 2012 11:28 Go to next message
Poissy B. is currently offline Poissy B.
Messages: 30
Registered: June 2012
Member
Hi all EMFers!

Please bare with me since I'm new at EMF. I have a class that maintains two distinct collections of another class (1-many containment relationship). Here's a simplified example:

Class A{
  EList<B> list1;
  Elist<b> list2;
}
Class B{
}


My problem is that I would like to know, for a given instance of B, whether it belongs to list1 or list2 in the container instance A.

Of course, i could simply iterate through list1 and check if my instance of B is part of it. Since it could only be either part of list1 or list2, if it's not present in list1 i can deduce that it's part of list2.

However, this solution seems to be the least effective choice. So I thought having a boolean attribute isInList1 in B that gets set when I add an instance of B to an instance of A.

Going through the generated code, the only place I found to be able to do this is in eSet() (in the switch statement). Am I right?

If so, should I override the eSet method (@generated NOT)? I am worrying that if my model evolves and I change class A, say adding a couple of attributes, EMF won't generate the new eSet() and I could end up with hard to find bugs.

Do you guys could give me any advice on how to do this properly?

Thanks a lot!

Anis


[Updated on: Wed, 13 June 2012 11:30]

Report message to a moderator

Re: Override eSet()... Should I? [message #885787 is a reply to message #885782] Wed, 13 June 2012 11:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26000
Registered: July 2009
Senior Member
Anis,

Comments below.

On 13/06/2012 5:28 PM, Anis B. wrote:
> Hi all EMFers!
>
> Please bare with me since I'm new at EMF. I have a class that
> maintains two distinct collections of another class (1-many
> containment relationship). Here's a simplified example:
>
>
> Class A{
> EList<B> list1;
> Elist<b> list2;
> }
> Class B{
> }
>
>
> My problem is that I would like to know, for a given instance of B,
> whether it belongs to list1 or list2 in the container instance A.
These are containment lists I guess. EObject.eContainmentFeature will
return whether it belongs to the feature for list 1 or 2.
> Of course, i could simply iterate through list1 and check if my
> instance of B is part of it. Since it could only be either part of
> list1 or list2, if it's not present in list1 i can deduce that it's
> part of list2.
> However, this solution seems to be the least effective choice. So I
> thought having a boolean attribute isInList1 in B that gets set when I
> add an instance of B to an instance of A.
> Going through the generated code, the only place I found to be able to
> do this is in eSet() (in the switch statement). Am I right?
No, lists have all their own internal methods; after all, you can add
directly to the list.
>
> If so, should I override the eSet method (@generated NOT)? I am
> worrying that if my model evolves and I change class A, say adding a
> couple of attributes, EMF won't generate the new eSet() and I could
> end up with hard to find bugs.
Yes, not generally a good idea.
> Do you guys could give me any advice on how to do this properly?
I think EObject.eContainmentFeature should be sufficient.
> Thanks a lot!
>
> Poissy
>
>
>
Re: Override eSet()... Should I? [message #885795 is a reply to message #885787] Wed, 13 June 2012 11:56 Go to previous message
Poissy B. is currently offline Poissy B.
Messages: 30
Registered: June 2012
Member
That did the trick! Wasn't aware of that method...

Thanks a lot Ed!
Previous Topic:EMF Development Environment
Next Topic:XMI:ID attributed to several objects ?
Goto Forum:
  


Current Time: Sat Aug 23 15:53:39 EDT 2014

Powered by FUDForum. Page generated in 0.01713 seconds