Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » XMI deserialization
XMI deserialization [message #426213] Fri, 19 December 2008 15:48 Go to next message
lars gersmann is currently offline lars gersmannFriend
Messages: 77
Registered: July 2009
Member
hello guys,

i have 2 objects a an b where a references b (b is not contained and not
bidirectional to a - just a plain reference).

they are both saved to different files. the serialization for object b
looks like that:

<?xml version="1.0" encoding="ASCII"?>
<model:GeneroProject xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:model="http://www.fourjs.com/genero/ide/model"
location="/home/lgersman/tmp/testat/unger">
<gdk xsi:type="model:GDK"
href="http://www.fourjs.com/genero/ide/model#//@gdks[name='gdk%201.1']"/>
</model:GeneroProject>

where the gdk element describes object b and generoproject describes
object a.

the serialization of the container installation object looks like this :

<?xml version="1.0" encoding="ASCII"?>
<model:Installations xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:model="http://www.fourjs.com/genero/ide/model"
defaultGdk="//@gdks[name='gdk%201.1']">
<gdks xsi:type="model:GDK" name="gdk 1.1"
location="/home/lgersman/Documents/fourjs/fgl/opt/fgl"
resourceKitFactory="gdk_generic">
<host xsi:type="model:GeneroHost" delegate="Local"/>
<environment xsi:type="model:Environment">
<variables xsi:type="model:EnvironmentVariable" name="New"
value="/home/lgersman/workspace/"/>
</environment>
</gdks>
</model:Installations>

... although its already materialized as ecore object in my code.

now i want to load this file using the following snippet :

...
ResourceSet resourceSet = new ResourceSetImpl();

Resource resource = resourceSet.createResource( EcoreUtil.getURI(
getInstallations().eClass()));
resource.getContents().add( getInstallations());

resource = resourceSet.createResource( EcoreUtil.getURI(
GeneroPackage.Literals.GENERO_PROJECT));

InputStream in = null;
try {
in = fileStore.openInputStream( EFS.NONE, new NullProgressMonitor());

resource.load( in, new HashMap());

gProject = (GeneroProject)resource.getContents().get( 0);
} finally {
IOUtil.close( in);
}
...

unfortunately the deserialzed generoproject instance references not the
existing gdk (provided within the installation object instance) but a
newly created one.

any hints how i can force the deserialization to reference the provided
object within the installations object ?

thanks in advance,

lars
Re: XMI deserialization [message #426219 is a reply to message #426213] Fri, 19 December 2008 17:46 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30911
Registered: July 2009
Senior Member
Lars,

Comments below.

lars gersmann wrote:
> hello guys,
>
> i have 2 objects a an b where a references b (b is not contained and
> not bidirectional to a - just a plain reference).
>
> they are both saved to different files. the serialization for object b
> looks like that:
>
> <?xml version="1.0" encoding="ASCII"?>
> <model:GeneroProject xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:model="http://www.fourjs.com/genero/ide/model"
> location="/home/lgersman/tmp/testat/unger">
> <gdk xsi:type="model:GDK"
> href="http://www.fourjs.com/genero/ide/model#//@gdks[name='gdk%201.1']"/>
> </model:GeneroProject>
>
> where the gdk element describes object b and generoproject describes
> object a.
>
> the serialization of the container installation object looks like this :
>
> <?xml version="1.0" encoding="ASCII"?>
> <model:Installations xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:model="http://www.fourjs.com/genero/ide/model"
> defaultGdk="//@gdks[name='gdk%201.1']">
> <gdks xsi:type="model:GDK" name="gdk 1.1"
> location="/home/lgersman/Documents/fourjs/fgl/opt/fgl"
> resourceKitFactory="gdk_generic">
> <host xsi:type="model:GeneroHost" delegate="Local"/>
> <environment xsi:type="model:Environment">
> <variables xsi:type="model:EnvironmentVariable" name="New"
> value="/home/lgersman/workspace/"/>
> </environment>
> </gdks>
> </model:Installations>
>
> .. although its already materialized as ecore object in my code.
>
> now i want to load this file using the following snippet :
>
> ..
> ResourceSet resourceSet = new ResourceSetImpl();
>
> Resource resource = resourceSet.createResource( EcoreUtil.getURI(
> getInstallations().eClass()));
That looks bad. The URI will have a fragment on it. What are you
trying to do?
> resource.getContents().add( getInstallations());
Hopefully these installations aren't already in a resource, because if
so, you're moving them out of it.
>
> resource = resourceSet.createResource( EcoreUtil.getURI(
> GeneroPackage.Literals.GENERO_PROJECT));
Yet more URIs with fragments...
>
> InputStream in = null;
> try {
> in = fileStore.openInputStream( EFS.NONE, new NullProgressMonitor());
>
> resource.load( in, new HashMap());
>
> gProject = (GeneroProject)resource.getContents().get( 0);
> } finally {
> IOUtil.close( in);
> }
> ..
I'm quite confused by all this URI stuff you're doing...
>
> unfortunately the deserialzed generoproject instance references not
> the existing gdk (provided within the installation object instance)
> but a newly created one.
>
> any hints how i can force the deserialization to reference the
> provided object within the installations object ?
The href is to a resource with URI
http://www.fourjs.com/genero/ide/model so you'd better have a resource
with that URI around...

Maybe you could take a step back and describe what you're trying to
accomplish with all this URI fiddling...
>
>
> thanks in advance,
>
> lars
>
Previous Topic:Re: Multi root EPackages support
Next Topic:CDO feature bug? FeatureNotFoundException
Goto Forum:
  


Current Time: Wed Feb 26 17:01:50 GMT 2020

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

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

Back to the top