Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » What's a good way of serializing/deserializing models with embedded EPackage
What's a good way of serializing/deserializing models with embedded EPackage [message #894817] Tue, 10 July 2012 16:04 Go to next message
Tas Frangoullides is currently offline Tas FrangoullidesFriend
Messages: 16
Registered: July 2009
Junior Member
Hi all,

I have a use case where I would like to dynamically create an EPackage, create dynamic instances and then persist both within the same XML resource. I've done most of the work in the metamodel and editor and the resulting serialization file looks something like the one below. The EPackage is embedded in the publishedPackages feature and the EObject is in the feature "propertyValues" near the end. Ignore the strange "http-.." style url, that's becuase I couldn't post links.

When I try to open the file with the though I get an exception:
org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'httpe://model.xxx.xxx.com/myapp/properties/1.0/scripts/1' not found.
....

What seems to be happening is that the refernece to embedded EPackage is not relative and attempt is made to resolve it. Of course this package is not registered anywhere so we get the exception. So I'm thinking I need to either register the embedded packages (in the ResourceSet?) as the resource is loaded or or need to make the reference to the ePackage from the EObject relative. I'm not really sure how to do either of these and overall not sure if the approach is correct to start with.

Does anyone know a good way to get this to work?

Thanks for your help.
Tas

<?xml version="1.0" encoding="UTF-8"?>
<bmc:DeploymentConfiguration xmlns:xsi="http-www.w3.org/2001/XMLSchema-instance" xmlns:bmc="http-model.xxx.xxx.com/myapp/config/2.3" xmlns:bmp="http-model.xxx.xxx.com/buildmonkey/properties/1.0" xmlns:ecore="http-www.eclipse.org/emf/2002/Ecore" xmlns:scripts_1="http-model.xxx.xxx.com/myapp/properties/1.0/scripts/1">
<propertyModels ModelId="scripts">
<enumerations Name="ShellType">
<literals Name="Sh"/>
<literals Name="Bash"/>
</enumerations>
<properties xsi:type="bmp:PrimitiveProperty" Name="Id"/>
<properties xsi:type="bmp:EnumerationProperty" Name="type" type="ShellType"/>
<publishedPackages name="scripts" nsURI="http-model.xxx.xxx.com/myapp/properties/1.0/scripts/1" nsPrefix="scripts_1">
<eClassifiers xsi:type="ecore:EEnum" name="ShellType">
<eLiterals name="Sh"/>
<eLiterals name="Bash"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="scripts">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="Id">
<eType xsi:type="ecore:EDataType" href="http-www.eclipse.org/emf/2002/Ecore#//EString"/>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="type" eType="//@propertyModels.0/@publishedPackages.0/ShellType"/>
</eClassifiers>
</publishedPackages>
</propertyModels>
<environments name="MyEnvironment">
<deployments xsi:type="bmc:CustomBundleDeployment">
<filesystemTarget/>
<propertyValues xsi:type="scripts_1:scripts"/>
</deployments>
</environments>
</bmc:DeploymentConfiguration>
Re: What's a good way of serializing/deserializing models with embedded EPackage [message #894916 is a reply to message #894817] Wed, 11 July 2012 05:50 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30353
Registered: July 2009
Senior Member
Tas,

Comments below.

On 10/07/2012 6:04 PM, Tas Frangoullides wrote:
> Hi all,
>
> I have a use case where I would like to dynamically create an
> EPackage, create dynamic instances and then persist both within the
> same XML resource.
We used to do something like that for SDO data graphs. But it required
specialized handling during loading; in particular, the package needs to
be registered without there being an xsi:schemaLocation and so needs to
come before the data.
> I've done most of the work in the metamodel and editor and the
> resulting serialization file looks something like the one below. The
> EPackage is embedded in the publishedPackages feature and the EObject
> is in the feature "propertyValues" near the end. Ignore the strange
> "http-.." style url, that's becuase I couldn't post links.
It's hard to imagine how that can work. You can't process the content
without knowing the model, but the model is at the end of the content...
>
> When I try to open the file with the though I get an exception:
> org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri
> 'httpe://model.xxx.xxx.com/myapp/properties/1.0/scripts/1' not found. ...
>
> What seems to be happening is that the refernece to embedded EPackage
> is not relative and attempt is made to resolve it.
Definitely. It's needed.
> Of course this package is not registered anywhere so we get the
> exception. So I'm thinking I need to either register the embedded
> packages (in the ResourceSet?) as the resource is loaded or or need to
> make the reference to the ePackage from the EObject relative. I'm not
> really sure how to do either of these and overall not sure if the
> approach is correct to start with.
>
> Does anyone know a good way to get this to work?
I think you have to accept that you'll need the model before you can
process instances.
>
> Thanks for your help.
> Tas
>
> <?xml version="1.0" encoding="UTF-8"?>
> <bmc:DeploymentConfiguration
> xmlns:xsi="http-www.w3.org/2001/XMLSchema-instance"
> xmlns:bmc="http-model.xxx.xxx.com/myapp/config/2.3"
> xmlns:bmp="http-model.xxx.xxx.com/buildmonkey/properties/1.0"
> xmlns:ecore="http-www.eclipse.org/emf/2002/Ecore"
> xmlns:scripts_1="http-model.xxx.xxx.com/myapp/properties/1.0/scripts/1">
> <propertyModels ModelId="scripts">
> <enumerations Name="ShellType">
> <literals Name="Sh"/>
> <literals Name="Bash"/>
> </enumerations>
> <properties xsi:type="bmp:PrimitiveProperty" Name="Id"/>
> <properties xsi:type="bmp:EnumerationProperty" Name="type"
> type="ShellType"/>
> <publishedPackages name="scripts"
> nsURI="http-model.xxx.xxx.com/myapp/properties/1.0/scripts/1"
> nsPrefix="scripts_1">
> <eClassifiers xsi:type="ecore:EEnum" name="ShellType">
> <eLiterals name="Sh"/>
> <eLiterals name="Bash"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="scripts">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="Id">
> <eType xsi:type="ecore:EDataType"
> href="http-www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="type"
> eType="//@propertyModels.0/@publishedPackages.0/ShellType"/>
> </eClassifiers>
> </publishedPackages>
> </propertyModels>
> <environments name="MyEnvironment">
> <deployments xsi:type="bmc:CustomBundleDeployment">
> <filesystemTarget/>
> <propertyValues xsi:type="scripts_1:scripts"/>
> </deployments>
> </environments>
> </bmc:DeploymentConfiguration>
>
Re: What's a good way of serializing/deserializing models with embedded EPackage [message #894923 is a reply to message #894817] Wed, 11 July 2012 06:16 Go to previous messageGo to next message
Tas Frangoullides is currently offline Tas FrangoullidesFriend
Messages: 16
Registered: July 2009
Junior Member
Hi Ed,
Thanks for the response. Maybe I did't explain too well the file contents. The EPackage does come before the instances of the eClass declared within it. I can understand that it needs to be that way. So to do the loading it sounds like registering the EPackage as it is encountered is the way to go. My question is really asking the right way to do that. Should I use an XML handler?

Thanks,
Tas.
Re: What's a good way of serializing/deserializing models with embedded EPackage [message #894944 is a reply to message #894923] Wed, 11 July 2012 08:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30353
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Tas,<br>
<br>
Comments below.<br>
<br>
<br>
<div class="moz-cite-prefix">On 11/07/2012 8:16 AM, Tas
Frangoullides wrote:<br>
</div>
<blockquote cite="mid:jtj5nd$ikb$1@xxxxxxxxe.org" type="cite">Hi
Ed,
<br>
Thanks for the response. Maybe I did't explain too well the file
contents. The EPackage does come before the instances of the
eClass declared within it.</blockquote>
Sorry, my fault, I didn't look so closely.<br>
<blockquote cite="mid:jtj5nd$ikb$1@xxxxxxxxe.org" type="cite"> I
can understand that it needs to be that way. So to do the loading
it sounds like registering the EPackage as it is encountered is
the way to go. My question is really asking the right way to do
that. Should I use an XML handler?
<br>
</blockquote>
I wonder if just using this option will solve the problem...<small><br>
</small>
<blockquote><small>  /**</small><br>
<small>   * Produce an
xsi:schemaLocation/xsi:noNamespaceSchemaLocation in the saved
result.</small><br>
<small>   */</small><br>
<small>  String OPTION_SCHEMA_LOCATION = "SCHEMA_LOCATION";</small><br>
</blockquote>
I'd expect to result in an xsi:schemaLocation attribute that
specifies the location of the package within this resource and that
by the time it needs to be resolved, i.e., while processing the
xsi:type in &lt;propertyValues xsi:type="scripts_1:scripts"/&gt;, it
should be attached to the resource's content tree and be available
for use.<br>
<br>
Please try that first and let me know who it goes.<br>
<blockquote cite="mid:jtj5nd$ikb$1@xxxxxxxxe.org" type="cite">Thanks,
<br>
Tas.
<br>
</blockquote>
<br>
<br>
</body>
</html>
icon14.gif  Re: What's a good way of serializing/deserializing models with embedded EPackage [message #894973 is a reply to message #894944] Wed, 11 July 2012 10:02 Go to previous message
Tas Frangoullides is currently offline Tas FrangoullidesFriend
Messages: 16
Registered: July 2009
Junior Member
Great! Simply adding the OPTION_SCHEMA_LOCATION option works.

Everytime I think I'm going to do a bit of interesting customisation an existing feature spoils my fun Razz

Previous Topic:problem with Map and EType Parameter
Next Topic:[EMF Validation] EMF Validation Framework
Goto Forum:
  


Current Time: Mon Aug 19 18:15:19 GMT 2019

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

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

Back to the top