Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Use of ecore2xml mappings
Use of ecore2xml mappings [message #1799002] Wed, 28 November 2018 14:42 Go to next message
The Spoutnik is currently offline The SpoutnikFriend
Messages: 7
Registered: July 2018
Junior Member
Hi,

I would like to have model instances of an ecore metamodel translated in XML as per a third-part XSD schema.

I create an ecore model out of the XSD (xsd2ecore), then add an ecore2ecore mapping and finally I have another ecore2xml.

There is very little documentation/examples on this so I would like to have some help on understanding:
1. if my approach is sound (e.g. having both xsd2ecore and ecore2xml looks strange as it may be about 'same' mapping).
2. how to use this to effectively transform model instances into XML instances.

Thanks.

Re: Use of ecore2xml mappings [message #1799011 is a reply to message #1799002] Wed, 28 November 2018 16:34 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30551
Registered: July 2009
Senior Member
If you create an *.ecore from a *.xsd, then you already have a model that will serialize/deserialize according to that XML Schema; the *.ecore will contain ExtendedMetaData annotations that are used to read and write instances that conform to the XML Schema. A resource factory implementation is generated (with the appropriate load and save options) for that purpose. You don't need anything else and you don't need any mapping models.

But you're saying you have some other *.ecore and you want to transform from that to the *.ecore one that's dervied from an XML Schema? None of these mapping models actually do transformation, i.e., they're not "active", they just represent links between the two representation that some other technology might use for some purpose.
Re: Use of ecore2xml mappings [message #1799019 is a reply to message #1799011] Wed, 28 November 2018 18:33 Go to previous messageGo to next message
The Spoutnik is currently offline The SpoutnikFriend
Messages: 7
Registered: July 2018
Junior Member
First thanks for such a swift answer.

I was indeed hoping that this model mappings were somewhat more "active" i.e. they could be some generic framework(s) to map between these models. This would definitively goes in the same direction as for visual ecore representations.

So, I understood I'll have to implement (reading the mapping info, or not) some code which will populate a target an ecore model (the one from XSD) instance and then serializing it!

Is my understanding correct?

Regards!
Re: Use of ecore2xml mappings [message #1799022 is a reply to message #1799019] Wed, 28 November 2018 20:05 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30551
Registered: July 2009
Senior Member
I'm really still not sure your actual scenario. If you have an XML Schema (a *.xsd) and from that you create an Ecore model (*.ecore), then for any *.xml instance that conforms to the XML Schema you can directly read and write it using the *.ecore you created from the *.xsd. No transformation from one Ecore model to another is involved. Do you have more than one Ecore model, i.e., one you hand wrote and also one you generated from a *.xsd?
Re: Use of ecore2xml mappings [message #1799041 is a reply to message #1799022] Thu, 29 November 2018 09:34 Go to previous messageGo to next message
The Spoutnik is currently offline The SpoutnikFriend
Messages: 7
Registered: July 2018
Junior Member
Yes, I have indeed 2 ecore models, one I wrote and also one I generated from a XSD. To map between these I used the graphical Ecore to Ecore Mapping Editor. I am now looking for a way to use that mapping.

From what I understood, there is no way to 'execute' that mapping. I have to write some code by myself. Do you have sample of this?

Thanks.
Re: Use of ecore2xml mappings [message #1799061 is a reply to message #1799041] Thu, 29 November 2018 13:17 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30551
Registered: July 2009
Senior Member
If your goal is to influence the serialization/deserialization of the original (hand written) Ecore model, you might be best off to add extend metadata annotations to the first model to achieve your goal. As of EMF 2.15 there is specialized support for authoring the extended metadata annotations and you can look at the *.ecore produced from the *.xsd to see how it is annotated. The option org.eclipse.emf.ecore.xmi.XMLResource.OPTION_EXTENDED_META_DATA should be used as both a load and a save option (set in your resource factory) so that the annotations in the Ecore model are used during deserialization and serialization.
Previous Topic:[Edapt] Unexpected behavior by defaultValueLiteral change
Next Topic:[EMF Forms] New custom controls
Goto Forum:
  


Current Time: Sun Oct 20 01:10:25 GMT 2019

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

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

Back to the top