Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Ecore containment property.
Ecore containment property. [message #1832999] Wed, 30 September 2020 13:07 Go to next message
Radu Socaciu is currently offline Radu SocaciuFriend
Messages: 2
Registered: May 2019
Junior Member
Hello,

This is my first time posting here :).
I am using EMF and I have some issues in my design because of how the containment property works. From what I've read, if you add an instance to a containment reference, it will remove it from the current containment. This does not help me because I want to model the following scenario

Class A
Class B - contains a EList<A> -> containment true
Class C - contains a EList<A> -> containment true

Both ELists have to stay in sync all the time.
If the containment property is not set to true for both Lists I get an error when I try to serialize the model.

My idea to model this is to create an ID attribute for class A and instead of having an EList<A> I could have an EList<String> of IDs.

From your experience is there a better way to model this scenario using the existing features of EMF?

Thank you in advance for your answer.
Re: Ecore containment property. [message #1833021 is a reply to message #1832999] Wed, 30 September 2020 18:12 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Radu,

Would it be sufficient for your purpose that the lists in classes B and C be plain references (not containment) and the instances of A be contained independently of the Bs and Cs? What object contains Bs and Cs? It could also contain the As and then the Bs and Cs would just cross-reference a subset of the As, and your application can take whatever steps are necessary to reference the same As in a matched B/C pair.

HTH,
Christian
Re: Ecore containment property. [message #1833140 is a reply to message #1833021] Sat, 03 October 2020 11:33 Go to previous messageGo to next message
Radu Socaciu is currently offline Radu SocaciuFriend
Messages: 2
Registered: May 2019
Junior Member
Hi Christian,

Sorry for the late replay. I will try next week to use your suggestion. My only concern with what you've suggested is the serialization of the model. I do not have a lot of experience with EMF, but from what I've observed if you have in a class a refrence to a Elist<CustomClass> and the containment flag is not set to true, when you try to serialize this you get an error (Do not remember the exact exepcion -> object is not contained in a resource).

Have a nice weekend,
Radu
Re: Ecore containment property. [message #1833141 is a reply to message #1833140] Sat, 03 October 2020 11:58 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is why Christian is asking about what contains the Bs and the Cs. In general you need to ensure that all objects are directly or indirectly contained by a Resource. So if B's and C's don't contain the As, but only reference them, then something else needs to contain the As, i.e., directly in some Resource.getContents() (the same one as contains the Bs and Cs) or by virtue of being contained by something else for which this recursively is true. I other words, all the reachable objects must have eResource() != null for the overall serialization to work.

Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:How to find out reference and references of a EClass?
Next Topic:[CDO] Official Releases
Goto Forum:
  


Current Time: Thu Apr 25 10:53:50 GMT 2024

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

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

Back to the top