Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Modeling (top-level project) » serialize ecore references into container
serialize ecore references into container [message #640132] Fri, 19 November 2010 09:25 Go to next message
Flo  is currently offline Flo Friend
Messages: 2
Registered: November 2010
Junior Member
Hi,

suppose I have this metamodel:

class Chair has a reference named "parts" of type "Part". Part is
superclass to classes Leg and Arm.

by default a model instance gets serialized to this:

<chair:Chair xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:chair="chair.de">
<parts xsi:type="chair:Arm"/>
<parts xsi:type="chair:Leg"/>
</chair:Chair>

What I would like is:

<Chair>
<Parts>
<Arm/>
<Leg/>
</Parts>
</Chair>

What is the way to go?

Thanks, Ed, for pointing me at your article on substitution groups
(http://ed-merks.blogspot.com/2007/12/winters-icy-grip.html) .
However, that does not give me the container tag, in my case <parts>, right?

Best regards, thanks in advance,

FLO
Re: serialize ecore references into container [message #640140 is a reply to message #640132] Fri, 19 November 2010 09:57 Go to previous messageGo to next message
Philip Langer is currently offline Philip LangerFriend
Messages: 31
Registered: July 2009
Member
Hi,

please see below...

On 2010-11-19 10:25, Florian Marienfeld wrote:
> Hi,
>
> suppose I have this metamodel:
>
> class Chair has a reference named "parts" of type "Part". Part is
> superclass to classes Leg and Arm.
>
> by default a model instance gets serialized to this:
>
> <chair:Chair xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:chair="chair.de">
> <parts xsi:type="chair:Arm"/>
> <parts xsi:type="chair:Leg"/>
> </chair:Chair>

This XML format is conforming to the XMI standard. In XMI you always have

<$referenceName xsi:type="$type" ($attributes)*>...</$referenceName>

>
> What I would like is:
>
> <Chair>
> <Parts>
> <Arm/>
> <Leg/>
> </Parts>
> </Chair>
>
> What is the way to go?

If you want to change that format without touching the metamodel, I
guess, you would have to write your own Resource/ResourceFactory
implementation and register it before serializing your model rather than
using XMIResources.

But you could also write an XML schema according to your needs and
generate the corresponding ecore model and then use the
GenericXMLResourceFactoryImpl as, I guess, Ed suggested (cf. end of
article [1]).

>
> Thanks, Ed, for pointing me at your article on substitution groups
> (http://ed-merks.blogspot.com/2007/12/winters-icy-grip.html) .
> However, that does not give me the container tag, in my case <parts>, right?
>
> Best regards, thanks in advance,
>
> FLO
>

HTH,

Philip

[1] http://www.devx.com/Java/Article/29093/1954
Re: serialize ecore references into container [message #640194 is a reply to message #640132] Fri, 19 November 2010 14:21 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
Florian,

I've not found the time to complete the work for
https://bugs.eclipse.org/bugs/show_bug.cgi?id=201662


Florian Marienfeld wrote:
> Hi,
>
> suppose I have this metamodel:
>
> class Chair has a reference named "parts" of type "Part". Part is
> superclass to classes Leg and Arm.
>
> by default a model instance gets serialized to this:
>
> <chair:Chair xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:chair="chair.de">
> <parts xsi:type="chair:Arm"/>
> <parts xsi:type="chair:Leg"/>
> </chair:Chair>
>
> What I would like is:
>
> <Chair>
> <Parts>
> <Arm/>
> <Leg/>
> </Parts>
> </Chair>
>
> What is the way to go?
>
> Thanks, Ed, for pointing me at your article on substitution groups
> (http://ed-merks.blogspot.com/2007/12/winters-icy-grip.html) .
> However, that does not give me the container tag, in my case <parts>, right?
>
> Best regards, thanks in advance,
>
> FLO
>
>
Previous Topic:serialize ecore references into container
Next Topic:EMF SOAP questions
Goto Forum:
  


Current Time: Fri Dec 19 06:33:13 GMT 2014

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

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