Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Support for establishing a containment reference to an object
Support for establishing a containment reference to an object [message #651559] Mon, 31 January 2011 16:19 Go to next message
AJ  is currently offline AJ Friend
Messages: 77
Registered: July 2009
Member
Is it still true that there is no support in EMF (no CDO) for establishing a containment reference to an object in an existing resource?

Containment proxies set to true:

ObjectA can belong to ResourceA and ObjectA.eContainer belongs to ResourceB.

[Updated on: Mon, 31 January 2011 16:23]

Report message to a moderator

Re: Support for establishing a containment reference to an object [message #651595 is a reply to message #651559] Mon, 31 January 2011 19:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30551
Registered: July 2009
Senior Member
AJ,

If you have Containment Proxies set to true in the GenModel and you set
resolveProxies to true for a particular containment reference, then that
containment reference can hold an object that's at the root of a
different resource. It's always the case that there can only be one
EObject.eContainer, so that's the reason for my comment about the
contained thing being at the root of a different resource...


AJ wrote:
> Is still true that there is no support for establishing a containment
> reference to an object in an existing resource?
>
> Containment proxies set to true:
>
> ObjectA can belong to ResourceA and ObjectA.eContainer belongs to
> ResourceB.
Re: Support for establishing a containment reference to an object [message #651646 is a reply to message #651595] Tue, 01 February 2011 03:19 Go to previous messageGo to next message
AJ  is currently offline AJ Friend
Messages: 77
Registered: July 2009
Member
Ed,

Could the containment reference hold an object that's not at the root of a different resource (e.g. a child element of the root)?

If ObjectA and ObjectB belong to Resource1, can their containment reference point to objects contained within Resource2 and it still be lazily loaded when only ObjectA is selected? Or will it better create a resource for each object the containment reference is holding (e.g. Resource2a and Resource2b)?

Thanks!
Re: Support for establishing a containment reference to an object [message #651652 is a reply to message #651646] Tue, 01 February 2011 04:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30551
Registered: July 2009
Senior Member
AJ,

Comments below.

AJ wrote:
> Ed,
>
> Could the containment reference hold an object that's not at the root
> of a different resource (e.g. a child element of the root)?
No, that would be the point of my last sentence. There can be only one
container, so if it's not at the root, it already has a container.
>
> If ObjectA and ObjectB belong to Resource1, can their containment
> reference point to objects contained within Resource2 and it still be
> lazily loaded when only ObjectA is selected?
I'm not sure I understand the relation between ObjectA and ObjectB.
Containment proxies are lazily resolved like any other proxy...
> Or will it better create a resource for each object the containment
> reference is holding (e.g. Resource2a and Resource2b)?
I'm quite lost now...
>
> Thanks!
>
Re: Support for establishing a containment reference to an object [message #651660 is a reply to message #651652] Tue, 01 February 2011 07:33 Go to previous messageGo to next message
AJ  is currently offline AJ Friend
Messages: 77
Registered: July 2009
Member
Sorry Ed, I failed to read your last sentence carefully. It makes sense now.

Let me use an example to explain my other question.

I've created these 2 ecore models:

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="plan"
nsURI=" platform:/resource/org.eclipse.emf.crossdocument/model/Plann ing.ecore "
nsPrefix="org.eclipse.emf.crossdocument">
<eClassifiers xsi:type="ecore:EClass" name="EPlanElement">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="data" eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EObject"
containment="true"/>
</eClassifiers>
</ecore:EPackage>

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="data"
nsURI=" platform:/resource/org.eclipse.emf.crossdocument/model/Data. ecore " nsPrefix="org.eclipse.emf.crossdocument">
<eClassifiers xsi:type="ecore:EClass" name="EMFObject" instanceClassName="org.eclipse.emf.ecore.EObject"/>
</ecore:EPackage>

//---------------

Then, I modified the PlanExample.java like this:

Resource resource1 = resourceSet.createResource(URI.createFileURI(new File("Resource1.plan").getAbsolutePath()));
EPlanElement root1 = PlanFactory.eINSTANCE.createEPlanElement();
root1.setName("ELEMENT1");
resource1.getContents().add(root1);

EPlanElement root2 = PlanFactory.eINSTANCE.createEPlanElement();
root2.setName("ELEMENT2");
resource1.getContents().add(root2);

Resource resource2 = resourceSet.createResource(URI.createFileURI(new File("Resource2.data").getAbsolutePath()));
EObject object1 = DataFactory.eINSTANCE.createEMFObject();
resource2.getContents().add(object1);

root1.setData(object1);

EObject object2 = DataFactory.eINSTANCE.createEMFObject();
resource2.getContents().add(object2);

root2.setData(object2);

resource1.save(System.out, null);
resource2.save(System.out, null);

//------------

To produce this output which shows two(2) cross document references persisted as root elements within the same resource (i.e. Resource2.data):

<?xml version="1.0" encoding="ASCII"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:org.eclipse.emf.crossdocument=" platform:/resource/org.eclipse.emf.crossdocument/model/Plann ing.ecore ">
<org.eclipse.emf.crossdocument:EPlanElement name="ELEMENT1">
<data href="Resource2.data#/0"/>
</org.eclipse.emf.crossdocument:EPlanElement>
<org.eclipse.emf.crossdocument:EPlanElement name="ELEMENT2">
<data href="Resource2.data#/1"/>
</org.eclipse.emf.crossdocument:EPlanElement>
</xmi:XMI>
<?xml version="1.0" encoding="ASCII"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:org.eclipse.emf.crossdocument=" platform:/resource/org.eclipse.emf.crossdocument/model/Data. ecore ">
<org.eclipse.emf.crossdocument:EMFObject/>
<org.eclipse.emf.crossdocument:EMFObject/>
</xmi:XMI>

//----------------

Do you see any problem with the above approach? Or should I persist each target object within its own resource (e.g. Resource2.data and Resource3.data) so when one accesses ELEMENT1, then only Resource2.data is demand loaded and the proxy resolved?

Thanks again, Ed!
Re: Support for establishing a containment reference to an object [message #651764 is a reply to message #651660] Tue, 01 February 2011 13:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30551
Registered: July 2009
Senior Member
AJ,

Comments below.


AJ wrote:
> Sorry Ed, I failed to read your last sentence carefully. It makes
> sense now.
>
> Let me use an example to explain my other question.
>
> I've created these 2 ecore models:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="plan"
> nsURI="
> platform:/resource/org.eclipse.emf.crossdocument/model/Plann ing.ecore "
> nsPrefix="org.eclipse.emf.crossdocument">
> <eClassifiers xsi:type="ecore:EClass" name="EPlanElement">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> lowerBound="1" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="data"
> eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EObject"
> containment="true"/>
> </eClassifiers>
> </ecore:EPackage>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="data"
> nsURI="
> platform:/resource/org.eclipse.emf.crossdocument/model/Data. ecore "
> nsPrefix="org.eclipse.emf.crossdocument">
> <eClassifiers xsi:type="ecore:EClass" name="EMFObject"
> instanceClassName="org.eclipse.emf.ecore.EObject"/>
> </ecore:EPackage>
>
> //---------------
>
> Then, I modified the PlanExample.java like this:
>
> Resource resource1 = resourceSet.createResource(URI.createFileURI(new
> File("Resource1.plan").getAbsolutePath()));
> EPlanElement root1 = PlanFactory.eINSTANCE.createEPlanElement();
> root1.setName("ELEMENT1");
> resource1.getContents().add(root1);
>
> EPlanElement root2 = PlanFactory.eINSTANCE.createEPlanElement();
> root2.setName("ELEMENT2");
> resource1.getContents().add(root2);
>
> Resource resource2 = resourceSet.createResource(URI.createFileURI(new
> File("Resource2.data").getAbsolutePath()));
> EObject object1 = DataFactory.eINSTANCE.createEMFObject();
> resource2.getContents().add(object1);
>
> root1.setData(object1);
>
> EObject object2 = DataFactory.eINSTANCE.createEMFObject();
> resource2.getContents().add(object2);
>
> root2.setData(object2);
>
> resource1.save(System.out, null);
> resource2.save(System.out, null);
>
> //------------
>
> To produce this output which shows two(2) cross document references
> persisted as root elements within the same resource (i.e.
> Resource2.data):
>
> <?xml version="1.0" encoding="ASCII"?>
> <xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:org.eclipse.emf.crossdocument="
> platform:/resource/org.eclipse.emf.crossdocument/model/Plann ing.ecore ">
> <org.eclipse.emf.crossdocument:EPlanElement name="ELEMENT1">
> <data href="Resource2.data#/0"/>
> </org.eclipse.emf.crossdocument:EPlanElement>
> <org.eclipse.emf.crossdocument:EPlanElement name="ELEMENT2">
> <data href="Resource2.data#/1"/>
> </org.eclipse.emf.crossdocument:EPlanElement>
> </xmi:XMI>
> <?xml version="1.0" encoding="ASCII"?>
> <xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:org.eclipse.emf.crossdocument="
> platform:/resource/org.eclipse.emf.crossdocument/model/Data. ecore ">
> <org.eclipse.emf.crossdocument:EMFObject/>
> <org.eclipse.emf.crossdocument:EMFObject/>
> </xmi:XMI>
>
> //----------------
>
> Do you see any problem with the above approach?
No.
> Or should I persist each target object within its own resource (e.g.
> Resource2.data and Resource3.data) so when one accesses ELEMENT1, then
> only Resource2.data is demand loaded and the proxy resolved?
It's a matter of the granularity of loading that you'd like for your
particular application. You could in principle put every object in its
own resource and therefore load at most one object at a time. That
might seem good, but in a client/server application this might result in
a large set of small messages were a smaller set of larger message might
produce better performance. There's no absolute right/best answer for
all applications.
>
> Thanks again, Ed!
Re: Support for establishing a containment reference to an object [message #651784 is a reply to message #651764] Tue, 01 February 2011 15:39 Go to previous messageGo to next message
AJ  is currently offline AJ Friend
Messages: 77
Registered: July 2009
Member
Ed,

Thanks again for taking the time and reviewing this.

Smaller set of larger message is not an issues since it is not a client/server application. Although one question still remains.

What to do with the target when ELEMENT1 is deleted? I don't think EMF will do that automatically so I guess I will have to explicitly delete the target in Resource2.data using the href.
Re: Support for establishing a containment reference to an object [message #651793 is a reply to message #651784] Tue, 01 February 2011 15:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30551
Registered: July 2009
Senior Member
AJ,

DeleteCommand will handle removing all references from any resources
loaded in the resource set. EcoreUtil.delete does the same thing, again
with the qualification that it only considers all resources loaded into
the resource set.


AJ wrote:
> Ed,
>
> Thanks again for taking the time and reviewing this.
>
> Smaller set of larger message is not an issues since it is not a
> client/server application. Although one question still remains.
>
> What to do with the target when ELEMENT1 is deleted? I don't think
> EMF will do that automatically so I guess I will have to explicitly
> delete the target in Resource2.data using the href.
Re: Support for establishing a containment reference to an object [message #651950 is a reply to message #651793] Wed, 02 February 2011 08:18 Go to previous messageGo to next message
AJ  is currently offline AJ Friend
Messages: 77
Registered: July 2009
Member
Why is only the last target persisted when I change the Resource Type in the genmodel to XML?

As XML, it only persists the last target:

<?xml version="1.0" encoding="ASCII"?>
<org.eclipse.emf.crossdocument:EPlanElement xmlns:org.eclipse.emf.crossdocument=" platform:/resource/org.eclipse.emf.crossdocument/model/Plann ing.ecore " name="ELEMENT1">
<data href="Resource2.data#/0"/>
</org.eclipse.emf.crossdocument:EPlanElement>

<?xml version="1.0" encoding="ASCII"?>
<org.eclipse.emf.crossdocument:EMFObject xmlns:org.eclipse.emf.crossdocument=" platform:/resource/org.eclipse.emf.crossdocument/model/Plann ing.ecore "/>

-----------------

But as XMI, both targets are persisted:

<?xml version="1.0" encoding="ASCII"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:org.eclipse.emf.crossdocument=" platform:/resource/org.eclipse.emf.crossdocument/model/Plann ing.ecore ">
<org.eclipse.emf.crossdocument:EPlanElement name="ELEMENT1">
<data href="Resource2.data#/0"/>
</org.eclipse.emf.crossdocument:EPlanElement>
<org.eclipse.emf.crossdocument:EPlanElement name="ELEMENT2">
<data href="Resource2.data#/1"/>
</org.eclipse.emf.crossdocument:EPlanElement>
</xmi:XMI>

<?xml version="1.0" encoding="ASCII"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:org.eclipse.emf.crossdocument=" platform:/resource/org.eclipse.emf.crossdocument/model/Plann ing.ecore ">
<org.eclipse.emf.crossdocument:EMFObject/>
<org.eclipse.emf.crossdocument:EMFObject/>
</xmi:XMI>
Re: Support for establishing a containment reference to an object [message #651987 is a reply to message #651950] Wed, 02 February 2011 10:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30551
Registered: July 2009
Senior Member
AJ,

Comments below.

AJ wrote:
> Why is only the last target persisted when I change the Resource Type
> in the genmodel to XML?
XML always has to have a single root element. XMIResourceImpl will
introduce an root XMI element to hold the multiple contents of the
resource, but XMLResourceImpl can only serialize a single root.
>
> As XML, it only persists the last target:
>
> <?xml version="1.0" encoding="ASCII"?>
> <org.eclipse.emf.crossdocument:EPlanElement
> xmlns:org.eclipse.emf.crossdocument="
> platform:/resource/org.eclipse.emf.crossdocument/model/Plann ing.ecore
> " name="ELEMENT1">
> <data href="Resource2.data#/0"/>
> </org.eclipse.emf.crossdocument:EPlanElement>
>
> <?xml version="1.0" encoding="ASCII"?>
> <org.eclipse.emf.crossdocument:EMFObject
> xmlns:org.eclipse.emf.crossdocument="
> platform:/resource/org.eclipse.emf.crossdocument/model/Plann ing.ecore
> "/>
>
> -----------------
>
> But as XMI, both targets are persisted:
>
> <?xml version="1.0" encoding="ASCII"?>
> <xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:org.eclipse.emf.crossdocument="
> platform:/resource/org.eclipse.emf.crossdocument/model/Plann ing.ecore ">
> <org.eclipse.emf.crossdocument:EPlanElement name="ELEMENT1">
> <data href="Resource2.data#/0"/>
> </org.eclipse.emf.crossdocument:EPlanElement>
> <org.eclipse.emf.crossdocument:EPlanElement name="ELEMENT2">
> <data href="Resource2.data#/1"/>
> </org.eclipse.emf.crossdocument:EPlanElement>
> </xmi:XMI>
>
> <?xml version="1.0" encoding="ASCII"?>
> <xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:org.eclipse.emf.crossdocument="
> platform:/resource/org.eclipse.emf.crossdocument/model/Plann ing.ecore ">
> <org.eclipse.emf.crossdocument:EMFObject/>
> <org.eclipse.emf.crossdocument:EMFObject/>
> </xmi:XMI>
>
Re: Support for establishing a containment reference to an object [message #652080 is a reply to message #651987] Wed, 02 February 2011 15:58 Go to previous messageGo to next message
AJ  is currently offline AJ Friend
Messages: 77
Registered: July 2009
Member
Ed,

Let me see if I understand.

If I use XMLResourceImpl, then do I need to introduce my own root or do I need to save each target into its own file so it can be the only root?

It is confusing since XMIResourceImpl seems to contradict your early statement, "there can be only one container, so if it's not at the root, it already has a container." So if XMIResourceImpl introduces its own root, then the targets will have a container.

Thanks again!
Re: Support for establishing a containment reference to an object [message #652195 is a reply to message #652080] Thu, 03 February 2011 00:29 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30551
Registered: July 2009
Senior Member
AJ,

Comments below.

AJ wrote:
> Ed,
>
> Let me see if I understand.
>
> If I use XMLResourceImpl, then do I need to introduce my own root or
> do I need to save each target into its own file so it can be the only
> root?
Yes, you'd have to do one of the two.
>
> It is confusing since XMIResourceImpl seems to contradict your early
> statement, "there can be only one container, so if it's not at the
> root, it already has a container."
These are statements about EObject and EObject.eContainer.
> So if XMIResourceImpl introduces its own root, then the targets will
> have a container.
It dumps "noise" in the XML to satisfy XML's constraint that there be
only one root element. It doesn't introduce new EObjects.
>
> Thanks again!
Previous Topic:[EMF Query 2]Strange stacktrace at shutdown
Next Topic:Generated collection access
Goto Forum:
  


Current Time: Sat Oct 19 10:47:28 GMT 2019

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

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

Back to the top