Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » serialize non-containment reference
serialize non-containment reference [message #960939] Sat, 27 October 2012 23:21 Go to next message
Marian Thieme is currently offline Marian ThiemeFriend
Messages: 11
Registered: August 2012
Junior Member
Hello,

I am unable to figure out how to properly work with non-containment references when serializing and loading it. Please consider the following example (based on
www.theserverside.com/news/1364302/Binding-XML-to-Java). This output:

<?xml version="1.0" encoding="ASCII"?>
<tree:rootNode xmlns:tree="http://www.eclipse.org/emf/example/dom/Tree" label="rootNode" references="./document.xml#ref">
  <tree:childNode label="childNode"/></tree:rootNode>


was produced by the following code:

ResourceSet resourceSet = new ResourceSetImpl();

// Register XML Factory implementation to handle .xml files
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
				.put("xml", new XMLResourceFactoryImpl());

// Create empty resource with the given URI
Resource resource = resourceSet.createResource(URI
				.createURI("./document.xml"));

//create instances
DocumentRoot documentRoot=TreeFactory.eINSTANCE.createDocumentRoot();
TreeNode rootNode=TreeFactory.eINSTANCE.createTreeNode();
rootNode.setLabel("rootNode");
documentRoot.setRootNode(rootNode);
TreeNode treeNodeRef=TreeFactory.eINSTANCE.createTreeNode();
treeNodeRef.setLabel("ref");
TreeNode childNode=TreeFactory.eINSTANCE.createTreeNode();
childNode.setLabel("childNode");
rootNode.getChildNodes().add(childNode);
rootNode.getReferences().add(treeNodeRef);


//add object to resource
resource.getContents().add(documentRoot);
//add non containment reference to the source
resource.getContents().addAll(rootNode.getReferences());
//use ext metadata
options.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);

//save (stdout)
((XMLResource)resource).save(System.out, options);
//save to DOM document
Document doc=((XMLResource)resource).save(null, options, null);


Question: How I have to correctly resolve this reference, because when loading it:


//load
XMLResource resource1 = new XMLResourceImpl();
resource1.load(doc, options);
DocumentRoot documentRoot1= (DocumentRoot) resource1.getContents().get(0);
System.out.println(((TreeNode)rootNode.getReferences().get(0)).getLabel());
System.out.println(((TreeNode)documentRoot1.getRootNode().getReferences().get(0)).getLabel());


I only get null for its label attribute.
ref
null


As one can see, in the above xml output, the references attribute points to "./document.xml#ref". So how can I add this "#ref" to the document ?
Or the other way around: what I am missing ?

Thanks a lot,
Marian
Re: serialize non-containment reference [message #961257 is a reply to message #960939] Sun, 28 October 2012 05:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26283
Registered: July 2009
Senior Member
Marian,

Comments below.

On 28/10/2012 1:21 AM, Marian Thieme wrote:
> Hello,
>
> I am unable to figure out how to properly work with non-containment
> references when serializing and loading it. Please consider the
> following example (based on
> www.theserverside.com/news/1364302/Binding-XML-to-Java). This output:
>
>
> <?xml version="1.0" encoding="ASCII"?>
> <tree:rootNode
> xmlns:tree="http://www.eclipse.org/emf/example/dom/Tree"
> label="rootNode" references="./document.xml#ref">
This reference looks odd. I don't generally expect a "." in a URI
formed by EMF when using URI.deresolve between two absolute URIs. That
makes me think you probably are not using absolute URIs when loading
your document.
> <tree:childNode label="childNode"/></tree:rootNode>
>
>
> was produced by the following code:
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> // Register XML Factory implementation to handle .xml files
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
> .put("xml", new XMLResourceFactoryImpl());
>
> // Create empty resource with the given URI
> Resource resource = resourceSet.createResource(URI
> .createURI("./document.xml"));
There you go. This should be an absolute URI if you want cross
document references to be properly converted to relative URIs. I.e.,
URI.createFileURI(new File("document.xml").getAbsolutePath())
>
> //create instances
> DocumentRoot documentRoot=TreeFactory.eINSTANCE.createDocumentRoot();
> TreeNode rootNode=TreeFactory.eINSTANCE.createTreeNode();
> rootNode.setLabel("rootNode");
> documentRoot.setRootNode(rootNode);
> TreeNode treeNodeRef=TreeFactory.eINSTANCE.createTreeNode();
> treeNodeRef.setLabel("ref");
> TreeNode childNode=TreeFactory.eINSTANCE.createTreeNode();
> childNode.setLabel("childNode");
> rootNode.getChildNodes().add(childNode);
> rootNode.getReferences().add(treeNodeRef);
>
>
> //add object to resource
> resource.getContents().add(documentRoot);
> //add non containment reference to the source
> resource.getContents().addAll(rootNode.getReferences());
> //use ext metadata
> options.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>
> //save (stdout)
> ((XMLResource)resource).save(System.out, options);
> //save to DOM document
> Document doc=((XMLResource)resource).save(null, options, null);
>
>
> Question: How I have to correctly resolve this reference, because when
> loading it:
>
>
>
> //load
> XMLResource resource1 = new XMLResourceImpl();
> resource1.load(doc, options);
> DocumentRoot documentRoot1= (DocumentRoot)
> resource1.getContents().get(0);
> System.out.println(((TreeNode)rootNode.getReferences().get(0)).getLabel());
>
> System.out.println(((TreeNode)documentRoot1.getRootNode().getReferences().get(0)).getLabel());
>
>
>
> I only get null for its label attribute.
In this case, you're even loading a resource that doesn't know its own
URI and it's not even in a resource set, so it won't be able to resolve
any cross document references. And because you
>
> ref
> null
>
>
> As one can see, in the above xml output, the references attribute
> points to "./document.xml#ref". So how can I add this "#ref" to the
> document ?
Ensure that all your resources have an absolute URI before you save then
and load them with an absolute URI as well.

Generally you're best off to use a resource set.

If you have a simple model lying around, I'd suggest invoke Generate
Tests and have a look at the generated XyzExample.java to see how best
to save and load resources in a stand alone application.
> Or the other way around: what I am missing ?
>
> Thanks a lot,
> Marian
>
Re: serialize non-containment reference [message #961263 is a reply to message #960939] Sun, 28 October 2012 05:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26283
Registered: July 2009
Senior Member
Marian,

Comments below.

On 28/10/2012 1:21 AM, Marian Thieme wrote:
> Hello,
>
> I am unable to figure out how to properly work with non-containment
> references when serializing and loading it. Please consider the
> following example (based on
> www.theserverside.com/news/1364302/Binding-XML-to-Java). This output:
>
>
> <?xml version="1.0" encoding="ASCII"?>
> <tree:rootNode
> xmlns:tree="http://www.eclipse.org/emf/example/dom/Tree"
> label="rootNode" references="./document.xml#ref">
This reference looks odd. I don't generally expect a "." in a URI
formed by EMF when using URI.deresolve between two absolute URIs. That
makes me think you probably are not using absolute URIs when loading
your document.
> <tree:childNode label="childNode"/></tree:rootNode>
>
>
> was produced by the following code:
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> // Register XML Factory implementation to handle .xml files
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
> .put("xml", new XMLResourceFactoryImpl());
>
> // Create empty resource with the given URI
> Resource resource = resourceSet.createResource(URI
> .createURI("./document.xml"));
There you go. This should be an absolute URI if you want cross
document references to be properly converted to relative URIs. I.e.,
URI.createFileURI(new File("document.xml").getAbsolutePath())
>
> //create instances
> DocumentRoot documentRoot=TreeFactory.eINSTANCE.createDocumentRoot();
> TreeNode rootNode=TreeFactory.eINSTANCE.createTreeNode();
> rootNode.setLabel("rootNode");
> documentRoot.setRootNode(rootNode);
> TreeNode treeNodeRef=TreeFactory.eINSTANCE.createTreeNode();
> treeNodeRef.setLabel("ref");
> TreeNode childNode=TreeFactory.eINSTANCE.createTreeNode();
> childNode.setLabel("childNode");
> rootNode.getChildNodes().add(childNode);
> rootNode.getReferences().add(treeNodeRef);
>
>
> //add object to resource
> resource.getContents().add(documentRoot);
> //add non containment reference to the source
> resource.getContents().addAll(rootNode.getReferences());
> //use ext metadata
> options.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>
> //save (stdout)
> ((XMLResource)resource).save(System.out, options);
> //save to DOM document
> Document doc=((XMLResource)resource).save(null, options, null);
>
>
> Question: How I have to correctly resolve this reference, because when
> loading it:
>
>
>
> //load
> XMLResource resource1 = new XMLResourceImpl();
> resource1.load(doc, options);
> DocumentRoot documentRoot1= (DocumentRoot)
> resource1.getContents().get(0);
> System.out.println(((TreeNode)rootNode.getReferences().get(0)).getLabel());
>
> System.out.println(((TreeNode)documentRoot1.getRootNode().getReferences().get(0)).getLabel());
>
>
>
> I only get null for its label attribute.
In this case, you're even loading a resource that doesn't know its own
URI and it's not even in a resource set, so it won't be able to resolve
any cross document references. And because you
>
> ref
> null
>
>
> As one can see, in the above xml output, the references attribute
> points to "./document.xml#ref". So how can I add this "#ref" to the
> document ?
Ensure that all your resources have an absolute URI before you save then
and load them with an absolute URI as well.

Generally you're best off to use a resource set.

If you have a simple model lying around, I'd suggest invoke Generate
Tests and have a look at the generated XyzExample.java to see how best
to save and load resources in a stand alone application.
> Or the other way around: what I am missing ?
>
> Thanks a lot,
> Marian
>
Re: serialize non-containment reference [message #961270 is a reply to message #960939] Sun, 28 October 2012 05:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26283
Registered: July 2009
Senior Member
Marian,

Comments below.

On 28/10/2012 1:21 AM, Marian Thieme wrote:
> Hello,
>
> I am unable to figure out how to properly work with non-containment
> references when serializing and loading it. Please consider the
> following example (based on
> www.theserverside.com/news/1364302/Binding-XML-to-Java). This output:
>
>
> <?xml version="1.0" encoding="ASCII"?>
> <tree:rootNode
> xmlns:tree="http://www.eclipse.org/emf/example/dom/Tree"
> label="rootNode" references="./document.xml#ref">
This reference looks odd. I don't generally expect a "." in a URI
formed by EMF when using URI.deresolve between two absolute URIs. That
makes me think you probably are not using absolute URIs when loading
your document.
> <tree:childNode label="childNode"/></tree:rootNode>
>
>
> was produced by the following code:
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> // Register XML Factory implementation to handle .xml files
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
> .put("xml", new XMLResourceFactoryImpl());
>
> // Create empty resource with the given URI
> Resource resource = resourceSet.createResource(URI
> .createURI("./document.xml"));
There you go. This should be an absolute URI if you want cross
document references to be properly converted to relative URIs. I.e.,
URI.createFileURI(new File("document.xml").getAbsolutePath())
>
> //create instances
> DocumentRoot documentRoot=TreeFactory.eINSTANCE.createDocumentRoot();
> TreeNode rootNode=TreeFactory.eINSTANCE.createTreeNode();
> rootNode.setLabel("rootNode");
> documentRoot.setRootNode(rootNode);
> TreeNode treeNodeRef=TreeFactory.eINSTANCE.createTreeNode();
> treeNodeRef.setLabel("ref");
> TreeNode childNode=TreeFactory.eINSTANCE.createTreeNode();
> childNode.setLabel("childNode");
> rootNode.getChildNodes().add(childNode);
> rootNode.getReferences().add(treeNodeRef);
>
>
> //add object to resource
> resource.getContents().add(documentRoot);
> //add non containment reference to the source
> resource.getContents().addAll(rootNode.getReferences());
> //use ext metadata
> options.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>
> //save (stdout)
> ((XMLResource)resource).save(System.out, options);
> //save to DOM document
> Document doc=((XMLResource)resource).save(null, options, null);
>
>
> Question: How I have to correctly resolve this reference, because when
> loading it:
>
>
>
> //load
> XMLResource resource1 = new XMLResourceImpl();
> resource1.load(doc, options);
> DocumentRoot documentRoot1= (DocumentRoot)
> resource1.getContents().get(0);
> System.out.println(((TreeNode)rootNode.getReferences().get(0)).getLabel());
>
> System.out.println(((TreeNode)documentRoot1.getRootNode().getReferences().get(0)).getLabel());
>
>
>
> I only get null for its label attribute.
In this case, you're even loading a resource that doesn't know its own
URI and it's not even in a resource set, so it won't be able to resolve
any cross document references. And because you
>
> ref
> null
>
>
> As one can see, in the above xml output, the references attribute
> points to "./document.xml#ref". So how can I add this "#ref" to the
> document ?
Ensure that all your resources have an absolute URI before you save then
and load them with an absolute URI as well.

Generally you're best off to use a resource set.

If you have a simple model lying around, I'd suggest invoke Generate
Tests and have a look at the generated XyzExample.java to see how best
to save and load resources in a stand alone application.
> Or the other way around: what I am missing ?
>
> Thanks a lot,
> Marian
>
Re: serialize non-containment reference [message #961278 is a reply to message #960939] Sun, 28 October 2012 05:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26283
Registered: July 2009
Senior Member
Marian,

Comments below.

On 28/10/2012 1:21 AM, Marian Thieme wrote:
> Hello,
>
> I am unable to figure out how to properly work with non-containment
> references when serializing and loading it. Please consider the
> following example (based on
> www.theserverside.com/news/1364302/Binding-XML-to-Java). This output:
>
>
> <?xml version="1.0" encoding="ASCII"?>
> <tree:rootNode
> xmlns:tree="http://www.eclipse.org/emf/example/dom/Tree"
> label="rootNode" references="./document.xml#ref">
This reference looks odd. I don't generally expect a "." in a URI
formed by EMF when using URI.deresolve between two absolute URIs. That
makes me think you probably are not using absolute URIs when loading
your document.
> <tree:childNode label="childNode"/></tree:rootNode>
>
>
> was produced by the following code:
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> // Register XML Factory implementation to handle .xml files
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
> .put("xml", new XMLResourceFactoryImpl());
>
> // Create empty resource with the given URI
> Resource resource = resourceSet.createResource(URI
> .createURI("./document.xml"));
There you go. This should be an absolute URI if you want cross
document references to be properly converted to relative URIs. I.e.,
URI.createFileURI(new File("document.xml").getAbsolutePath())
>
> //create instances
> DocumentRoot documentRoot=TreeFactory.eINSTANCE.createDocumentRoot();
> TreeNode rootNode=TreeFactory.eINSTANCE.createTreeNode();
> rootNode.setLabel("rootNode");
> documentRoot.setRootNode(rootNode);
> TreeNode treeNodeRef=TreeFactory.eINSTANCE.createTreeNode();
> treeNodeRef.setLabel("ref");
> TreeNode childNode=TreeFactory.eINSTANCE.createTreeNode();
> childNode.setLabel("childNode");
> rootNode.getChildNodes().add(childNode);
> rootNode.getReferences().add(treeNodeRef);
>
>
> //add object to resource
> resource.getContents().add(documentRoot);
> //add non containment reference to the source
> resource.getContents().addAll(rootNode.getReferences());
> //use ext metadata
> options.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>
> //save (stdout)
> ((XMLResource)resource).save(System.out, options);
> //save to DOM document
> Document doc=((XMLResource)resource).save(null, options, null);
>
>
> Question: How I have to correctly resolve this reference, because when
> loading it:
>
>
>
> //load
> XMLResource resource1 = new XMLResourceImpl();
> resource1.load(doc, options);
> DocumentRoot documentRoot1= (DocumentRoot)
> resource1.getContents().get(0);
> System.out.println(((TreeNode)rootNode.getReferences().get(0)).getLabel());
>
> System.out.println(((TreeNode)documentRoot1.getRootNode().getReferences().get(0)).getLabel());
>
>
>
> I only get null for its label attribute.
In this case, you're even loading a resource that doesn't know its own
URI and it's not even in a resource set, so it won't be able to resolve
any cross document references. And because you
>
> ref
> null
>
>
> As one can see, in the above xml output, the references attribute
> points to "./document.xml#ref". So how can I add this "#ref" to the
> document ?
Ensure that all your resources have an absolute URI before you save then
and load them with an absolute URI as well.

Generally you're best off to use a resource set.

If you have a simple model lying around, I'd suggest invoke Generate
Tests and have a look at the generated XyzExample.java to see how best
to save and load resources in a stand alone application.
> Or the other way around: what I am missing ?
>
> Thanks a lot,
> Marian
>
Re: serialize non-containment reference [message #961793 is a reply to message #961257] Sun, 28 October 2012 15:57 Go to previous messageGo to next message
Marian Thieme is currently offline Marian ThiemeFriend
Messages: 11
Registered: August 2012
Junior Member
Thanks for your comments.

Quote:

> Resource resource = resourceSet.createResource(URI
> .createURI("./document.xml"));
There you go. This should be an absolute URI if you want cross
document references to be properly converted to relative URIs. I.e.,
URI.createFileURI(new File("document.xml").getAbsolutePath())


I am wondering if I really have to go with a cross-document reference. (why not just put the reference in to the same document ?) Is it correct that in this case I have to create, save and load 2 resources, and reference the content of B in A.
I did something like this: (The resourceset I am creating as you suggested in the same way as it is created in the generated test code (TreeExample.java) and I am now using absolute URI as you suggested.)


// Create a resource set to hold the resources.
ResourceSet resourceSet = new ResourceSetImpl();
			
// Register the appropriate resource factory to handle all file extensions.
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put
				(Resource.Factory.Registry.DEFAULT_EXTENSION, 
				 new TreeResourceFactoryImpl());

// Register the package to ensure it is available during loading.
resourceSet.getPackageRegistry().put(TreePackage.eNS_URI, 
				 TreePackage.eINSTANCE);
Resource resource = resourceSet.createResource(
					URI.createFileURI(new File("document.xml").getAbsolutePath()));
Resource resourceRef = resourceSet.createResource(
					URI.createFileURI(new File("treeNodeRef.xml").getAbsolutePath()));

//create and init instances
...

//add instance documentRoot
resource.getContents().add(documentRoot);
resourceRef.getContents().add(treeNodeRef);

//save instances
//save to file
((XMLResource)resource).save(options);
((XMLResource)resourceRef).save(options);



Now I have a problem with loading. I want to test loading with a fresh resourceSet, (assuming that I usually cannot use the resourceSet instance used for serializing), and tried this code:

//set up the resourceset (new instance for loading) as before
ResourceSet resourceSetLoad = new ResourceSetImpl();
...

//create resources:
Resource resourceLoad = resourceSetLoad.createResource(
				URI.createFileURI(new File("document.xml").getAbsolutePath()));
Resource resourceRefLoad = resourceSetLoad.createResource(
				URI.createFileURI(new File("treeNodeRef.xml").getAbsolutePath()));

//load
((XMLResource)resourceLoad).load(options);
((XMLResource)resourceRefLoad).load(options);

The last line (loading resourceRefLoad) produce the exception:
Exception in thread "main" org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature 'TreeNode' not found. (file:/usr/home/heinz/workspace/BindingXMLJava/org.eclipse.emf.example.dom/treeNodeRef.xml, 2, 86)
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLLoadImpl.java:83)
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:191)
	at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:242)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1511)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1290)

[Updated on: Sun, 28 October 2012 16:00]

Report message to a moderator

Re: serialize non-containment reference [message #961840 is a reply to message #961793] Sun, 28 October 2012 16:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26283
Registered: July 2009
Senior Member
Marian,

Comments below.

On 28/10/2012 4:57 PM, Marian Thieme wrote:
> Thanks for your comments.
>
> Quote:
>> > Resource resource = resourceSet.createResource(URI
>> > .createURI("./document.xml"));
>> There you go. This should be an absolute URI if you want cross
>> document references to be properly converted to relative URIs. I.e.,
>> URI.createFileURI(new File("document.xml").getAbsolutePath())
>
>
> I am wondering if I really have to go with a cross-document reference.
> Is it correct that in this case I have to create, save and load 2
> resources, and reference the content of B in A.
> I did something like this: (The resourceset I am creating as you
> suggested in the same way as it is created in the generated test code
> (TreeExample.java) and I am now using absolute URI as you suggested.)
>
>
>
> // Create a resource set to hold the resources.
> ResourceSet resourceSet = new ResourceSetImpl();
>
> // Register the appropriate resource factory to handle all file
> extensions.
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put
> (Resource.Factory.Registry.DEFAULT_EXTENSION,
> new TreeResourceFactoryImpl());
>
> // Register the package to ensure it is available during loading.
> resourceSet.getPackageRegistry().put(TreePackage.eNS_URI,
> TreePackage.eINSTANCE);
> Resource resource = resourceSet.createResource(
> URI.createFileURI(new
> File("document.xml").getAbsolutePath()));
> Resource resourceRef = resourceSet.createResource(
> URI.createFileURI(new
> File("treeNodeRef.xml").getAbsolutePath()));
>
> //create and init instances
> ..
>
> //add instance documentRoot
> resource.getContents().add(documentRoot);
What is the purpose of this? A document's elements can't be contained
by a different resource. I'm sure you don't really want to achieve
cross document containment, which is supported, but doesn't make sense
for this case.
> resourceRef.getContents().add(treeNodeRef);
>
> //save instances
> //save to file
> ((XMLResource)resource).save(options);
> ((XMLResource)resourceRef).save(options);
>
>
>
> Now I have a problem with loading. I want to test loading with a fresh
> resourceSet, (assuming that I usually cannot use the resourceSet
> instance used for serializing), and tried this code:
>
>
> //set up the resourceset (new instance for loading) as before
> ResourceSet resourceSetLoad = new ResourceSetImpl();
> ..
>
> //create resources:
> Resource resourceLoad = resourceSetLoad.createResource(
> URI.createFileURI(new
> File("document.xml").getAbsolutePath()));
> Resource resourceRefLoad = resourceSetLoad.createResource(
> URI.createFileURI(new
> File("treeNodeRef.xml").getAbsolutePath()));
>
> //load
> ((XMLResource)resourceLoad).load(options);
> ((XMLResource)resourceRefLoad).load(options);
>
> The last line (loading resourceRefLoad) produce the exception:
>
> Exception in thread "main"
> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature
> 'TreeNode' not found.
> (file:/usr/home/heinz/workspace/BindingXMLJava/org.eclipse.emf.example.dom/treeNodeRef.xml,
> 2, 86)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLLoadImpl.java:83)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:191)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:242)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1511)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1290)
>
>
Re: serialize non-containment reference [message #961868 is a reply to message #961840] Sun, 28 October 2012 17:18 Go to previous messageGo to next message
Marian Thieme is currently offline Marian ThiemeFriend
Messages: 11
Registered: August 2012
Junior Member
Quote:

What is the purpose of this? A document's elements can't be contained
by a different resource. I'm sure you don't really want to achieve
cross document containment, which is supported, but doesn't make sense
for this case.

Right, I actually dont want it, but I dont see how to bring the content of the reference elements (that are referenced by the attribute/value: references="#ref") in to the final xml document. I only managed to produce this

<?xml version="1.0" encoding="ASCII"?>
<tree:rootNode xmlns:tree="http://www.eclipse.org/emf/example/dom/Tree" label="rootNode" references="#ref">
  <tree:childNode label="childNode"/>
</tree:rootNode>


But what I want is something like this:

<?xml version="1.0" encoding="ASCII"?>
<tree:rootNode xmlns:tree="http://www.eclipse.org/emf/example/dom/Tree" label="rootNode" references="#ref">
  <tree:childNode label="childNode"/>
</tree:rootNode>
<ref>
 <tree:TreeNode label="ref"/>
</ref>



Assuming this is approximately what I need for properly restoring the TreeNode objects based on one resource created by a resourceset (which not yet contains the eobjects), how can I generate it ?


Re: serialize non-containment reference [message #961933 is a reply to message #961868] Sun, 28 October 2012 18:31 Go to previous message
Marian Thieme is currently offline Marian ThiemeFriend
Messages: 11
Registered: August 2012
Junior Member
OK, I am now able to manage xml serialization (with non containment references in to one document/resource), based on a simple emf model (two classes, one is noncontainment referenced by the other using multiplicity many), that doesnt have any annoations, and just one default package. The output is what I would expect.
Thanks so far again for your help.

Edit 1: Just noticed that I have serialized as xmi

[Updated on: Sun, 28 October 2012 18:42]

Report message to a moderator

Previous Topic:[CDO] Starting sequence of IAppExtensions
Next Topic:Generating bpmn diagram from xmi file
Goto Forum:
  


Current Time: Fri Dec 19 21:14:55 GMT 2014

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

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