Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » container vs containment
container vs containment [message #422534] Mon, 08 September 2008 18:22 Go to next message
Cyril Faucher is currently offline Cyril FaucherFriend
Messages: 63
Registered: July 2009
Member
Hi,

Could you explain me the role of the attribute: "container" vs containment ?

Best regards,
Cyril.
Re: container vs containment [message #422535 is a reply to message #422534] Mon, 08 September 2008 18:41 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30646
Registered: July 2009
Senior Member
Cyril,

Containment defines a tree structure (as opposed to a directed acyclic
graph or just a general graph with cycles). EObject.eContents()
represent the collection of all the child EObjects held by containment
references and EObject.eContainer() is the inverse, i.e, each contained
child knows the one object that contains it. There can be at most one
container, so adding an object to a containment reference will remove it
from its current container's containment reference. (This is exactly how
DOM's elements work.) An EReference can have an eOpposite and the
opposite of an ERerence for which isContainment is true, will have
isContainer true.


Cyril Faucher wrote:
> Hi,
>
> Could you explain me the role of the attribute: "container" vs
> containment ?
>
> Best regards,
> Cyril.
Re: container vs containment [message #422538 is a reply to message #422535] Mon, 08 September 2008 19:34 Go to previous messageGo to next message
Cyril Faucher is currently offline Cyril FaucherFriend
Messages: 63
Registered: July 2009
Member
Thank you very much for this precise reply.

Cyril.

Ed Merks a écrit :
> Cyril,
>
> Containment defines a tree structure (as opposed to a directed acyclic
> graph or just a general graph with cycles). EObject.eContents()
> represent the collection of all the child EObjects held by containment
> references and EObject.eContainer() is the inverse, i.e, each contained
> child knows the one object that contains it. There can be at most one
> container, so adding an object to a containment reference will remove it
> from its current container's containment reference. (This is exactly how
> DOM's elements work.) An EReference can have an eOpposite and the
> opposite of an ERerence for which isContainment is true, will have
> isContainer true.
>
>
> Cyril Faucher wrote:
>> Hi,
>>
>> Could you explain me the role of the attribute: "container" vs
>> containment ?
>>
>> Best regards,
>> Cyril.
Re: container vs containment [message #1696037 is a reply to message #422538] Thu, 21 May 2015 10:21 Go to previous messageGo to next message
AMAL AMAL is currently offline AMAL AMALFriend
Messages: 7
Registered: May 2015
Junior Member
Hello,
I have problem with the containment property
I cannot modelize the fact that one EClass belongs to more than one other EClass Sad
For example, "Paper" belongs to Class "Book" and "Notebook" and "Newspaper" !!
But when definning reference of the class Paper in class book and setting containment propoerty to true ==> Problem ; it doesn't accept that one class has more than one container
How can I resolve this problem ?
Re: container vs containment [message #1696070 is a reply to message #1696037] Thu, 21 May 2015 13:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30646
Registered: July 2009
Senior Member
Comments below.


On 21/05/2015 3:03 PM, AMAL AMAL wrote:
> Hello,
> I have problem with the containment property I cannot modelize the
> fact that one EClass belongs to more than one other EClass :(
"Belongs to" meaning what?
> For example, "Paper" belongs to Class "Book" and "Notebook" and
> "Newspaper" !!
So you mean, "contained by". Of course on Paper instance cannot
simultaneously be contained by more than one of these things.
> But when definning reference of the class Paper in class book and
> setting containment propoerty to true ==> Problem ; it doesn't accept
> that one class has more than one container
What specifically is "it" and how does it not "accept" that one class
has more than one container?
> How can I resolve this problem ?
The problem isn't clear. Please describe it with more precision.
Re: container vs containment [message #1696073 is a reply to message #1696070] Thu, 21 May 2015 13:54 Go to previous messageGo to next message
AMAL AMAL is currently offline AMAL AMALFriend
Messages: 7
Registered: May 2015
Junior Member
Well,
I have defined 3 classes A,B and C in my metamodel (ecore)
In the class B, I have Ereferece of type A (containment = true) and in the class C also I define an Ereference of type A , when I modify containment to true I got this problem :
"A containment reference of a type with a container feature org.eclipse.emf.ecore.impl.EReferenceImpl@26dc7d88.... that requires instances to be contained elsewhere cannot be populated "
Re: container vs containment [message #1696083 is a reply to message #1696073] Thu, 21 May 2015 14:41 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30646
Registered: July 2009
Senior Member
Comments below.


On 21/05/2015 3:54 PM, AMAL AMAL wrote:
> Well, I have defined 3 classes A,B and C in my metamodel (ecore)
> In the class B, I have Ereferece of type A (containment = true) and
> in the class C also I define an Ereference of type A , when I modify
> containment to true I got this problem :
You mention a containment feature here.
> "A containment reference of a type with a container feature
> mailto:org.eclipse.emf.ecore.impl.EReferenceImpl@26dc7d88.... that
> requires instances to be contained elsewhere cannot be populated "
This error can only occur if you have container features involved.
You've not mentioned those. Does A have container features defined? I
imagine you have such a feature defined and you've set the lower bound
to be 1 so you require that container to be non-null. But if the object
can be contained in more than one place, one of the two container
features will be null, violating the constraint that it can't be null.
So you must change the lower bound of the container feature(s) to 0.
Re: container vs containment [message #1696084 is a reply to message #1696083] Thu, 21 May 2015 14:50 Go to previous messageGo to next message
AMAL AMAL is currently offline AMAL AMALFriend
Messages: 7
Registered: May 2015
Junior Member
Thank you Smile
It works now
the lower bound was 1
I didn't pay attention
Re: container vs containment [message #1697177 is a reply to message #1696083] Tue, 02 June 2015 08:00 Go to previous messageGo to next message
AMAL AMAL is currently offline AMAL AMALFriend
Messages: 7
Registered: May 2015
Junior Member
Hello,
I have another problem Confused
I will try to explain it clearly :
We have 3 classes A, B and C
A may contain one or more C
B may contain one or more C
So I added an Ereference of type C in both classes A and B with containment = true
upper bound (-1) and lower bound (1)
And in the classe C, I added 2 Ereferences of type A and B respectively and set the EOpposite "c" for both ; lower bound (0) and upper bound (1 ) (container = true automatically)=> adding A to C will automatically add C to A (the same for B)
Now , the ecore is defined and I don't have errors
The problem I have is when trying to create a dynamic instance
I have created one instance of class C named "c"
one of class A "a" and one of class B "b"
the fact that I define that "a" contains "c" eliminates "c" from "b"
So "c" is included in either "a" or "b", and not in both at once ! Crying or Very Sad
Can someone help me please
Thank you

Re: container vs containment [message #1697188 is a reply to message #1697177] Tue, 02 June 2015 08:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30646
Registered: July 2009
Senior Member
Yes, containment is exclusive. An instance can have exactly one
EObject.eContainer. Adding an instance to a containment reference will
always remove it from its current container and make the new destination
the container. So no, an instance can't be shared by two containment
references.


On 02/06/2015 10:00 AM, AMAL AMAL wrote:
> Hello,
> I have another problem :? I will try to explain it clearly :
> We have 3 classes A, B and C A may contain one or more C
> B may contain one or more C So I added an Ereference of type C in both
> classes A and B with containment = true upper bound (-1) and lower
> bound (1) And in the classe C, I added 2 Ereferences of type A and B
> respectively and set the EOpposite "c" for both ; lower bound (0)
> and upper bound (1 ) (container = true automatically)=> adding A to C
> will automatically add C to A (the same for B)
> Now , the ecore is defined and I don't have errors The problem I have
> is when trying to create a dynamic instance I have created one
> instance of class C named "c"
> one of class A "a" and one of class B "b"
> the fact that I define that "a" contains "c" eliminates "c" from "b"
> So "c" is included in either "a" or "b", and not in both at once !
> :cry: Can someone help me please Thank you
>
Re: container vs containment [message #1697190 is a reply to message #1697188] Tue, 02 June 2015 09:00 Go to previous messageGo to next message
AMAL AMAL is currently offline AMAL AMALFriend
Messages: 7
Registered: May 2015
Junior Member
Is there any other solution for modeling this kind of relation( an instance can be shared by two references) ??
thanks
Re: container vs containment [message #1697196 is a reply to message #1697190] Tue, 02 June 2015 11:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30646
Registered: July 2009
Senior Member
Yes, non-containment. But your "shared objects" will need to be
contained somewhere or be root objects in a resource.

On 02/06/2015 11:00 AM, AMAL AMAL wrote:
> Is there any other solution for modeling this kind of relation( an
> instance can be shared by two references) ??
> thanks
Re: container vs containment [message #1697203 is a reply to message #1697196] Tue, 02 June 2015 12:27 Go to previous messageGo to next message
AMAL AMAL is currently offline AMAL AMALFriend
Messages: 7
Registered: May 2015
Junior Member
Can you explain more please ? I can't understand how can I make it non-containment reference ? (means that I need that A contains one or more instances of C )
PS : this is my first example using EMF
Re: container vs containment [message #1697209 is a reply to message #1697203] Tue, 02 June 2015 13:00 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30646
Registered: July 2009
Senior Member
Comments below.

On 02/06/2015 2:27 PM, AMAL AMAL wrote:
> Can you explain more please ?
I can't give personalize help to everyone in the world...
> I can't understand how can I make it non-containment reference ?
In the properties view you can choose what's a containment reference and
what isn't. You must have used this because containment is not the default.
> (means that I need that A contains one or more instances of C )
That has more to do with the upper bound.
> PS : this is my first example using EMF
Perhaps it will be good to by the EMF book and read it.
Re: container vs containment [message #1697319 is a reply to message #1697209] Wed, 03 June 2015 07:29 Go to previous message
AMAL AMAL is currently offline AMAL AMALFriend
Messages: 7
Registered: May 2015
Junior Member
(I mean with " I can't understand how can I make it non-containment reference ? " how non-containment in my case NOT how to do it Wink )
Thank you in any case
Previous Topic:Persisting EAnnotations into an XMI file
Next Topic:Validating Ecore models with independent OCL fragments
Goto Forum:
  


Current Time: Tue Nov 19 23:44:22 GMT 2019

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

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

Back to the top