Home » Modeling » EMF » Transforming XMI serialization of EReference
Transforming XMI serialization of EReference [message #1156296] |
Sat, 26 October 2013 12:52 |
Tuan Nguyen Messages: 3 Registered: August 2011 |
Junior Member |
|
|
Hi all,
I need to generate an XML representation of my model that is semantically similar but not identical to the XMI serialization. For this, I am using XSLT to transform the XMI serialization to the new format. However, I don't know how to transform the XMI serialization of EReference.
Let me give you an example. In my metamodel, a Contract references two Roles, called RoleA & RoleB. As the result of default XMI serialization, I have the following info:
<Contract RoleA="//@Composite/@Role.1" RoleB="//@Composite/@Role.2" ...>
I need to generate the following info
<Contract RoleA="Role1_Name" RoleB="Role2_Name" ...>
So instead of representing a link path, I need to show the name of the elements which are linked.
I don't know how I can achieve this with XSLT. Firstly, the serialization of EReference is similar but is not identical to XPath. Secondly, I haven't found a way in XSLT to process this value to derive the name of the elements.
I understand that I might achieve my objective by generating XML document from the dynamic model. By this way, I can traverse all model elements & generate appropriate information. However, I have been half-way though completing my XSLT transformation & would like to stick to that solution if possible. And honestly, I am afraid I might encounter other unexpected problems if I use the accessing
dynamic model approach. So any advise on this aspect is also appreciated.
|
|
|
Re: Transforming XMI serialization of EReference [message #1157316 is a reply to message #1156296] |
Sun, 27 October 2013 05:34 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Tuan,
Comments below.
On 26/10/2013 7:28 PM, Tuan Nguyen wrote:
> Hi all,
>
> I need to generate an XML representation of my model that is
> semantically similar but not identical to the XMI serialization. For
> this, I am using XSLT to transform the XMI serialization to the new
> format. However, I don't know how to transform the XMI serialization
> of EReference.
>
> Let me give you an example. In my metamodel, a Contract references two
> Roles, called RoleA & RoleB. As the result of default XMI
> serialization, I have the following info:
>
> <Contract RoleA="//@Composite/@Role.1" RoleB="//@Composite/@Role.2" ...>
>
> I need to generate the following info
>
> <Contract RoleA="Role1_Name" RoleB="Role2_Name" ...>
That's more as if the role's name is an ID. Would it make sense to mark
it's EAttribute is isID true and serializing that way?
>
> So instead of representing a link path, I need to show the name of the
> elements which are linked.
>
> I don't know how I can achieve this with XSLT. Firstly, the
> serialization of EReference is similar but is not identical to XPath.
> Secondly, I haven't found a way in XSLT to process this value to
> derive the name of the elements.
>
> I understand that I might achieve my objective by generating XML
> document from the dynamic model. By this way, I can traverse all model
> elements & generate appropriate information. However, I have been
> half-way though completing my XSLT transformation & would like to
> stick to that solution if possible. And honestly, I am afraid I might
> encounter other unexpected problems if I use the accessing dynamic
> model approach.
You don't have the generated model for it? It would seem more
straightforward to have a specialized resource implementation where you
specialize
org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getIDREF(EObject) to
produce the desired serialization.
> So any advise on this aspect is also appreciated.
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | |
Re: Transforming XMI serialization of EReference [message #1160154 is a reply to message #1158849] |
Tue, 29 October 2013 01:33 |
Tuan Nguyen Messages: 3 Registered: August 2011 |
Junior Member |
|
|
Thanks a lot Ed. I did it. There are actually some changes in annotations as noted below.
Just a memo for other people who have the same question as mine.
When you change the ID of an EAttribute, say name, of an EClass, say Role (as in my case), to true, you'll notice the following changes in the generated code.
1. the annotation for getName() in Role interface will change to
* @model id="true" required="true"
with additional information stating that id is true.
2. Within function initializePackageContents() of XYZPackageImpl.java, you'll notice
initEAttribute(getRole_Name(), ecorePackage.getEString(), "id", null, 1, 1, Role.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
same as above you can see that IS_ID is set.
Also as Ed said, when you set an attribute's ID to true, default XMI serialization will pick that attribute instead of the relative path. However, if the value for that attribute is empty, the relative path will be used.
[Updated on: Tue, 29 October 2013 01:34] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Thu Apr 25 10:18:08 GMT 2024
Powered by FUDForum. Page generated in 0.03629 seconds
|