Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Transforming XMI serialization of EReference
Transforming XMI serialization of EReference [message #1156296] Sat, 26 October 2013 12:52 Go to next message
Tuan Nguyen is currently offline Tuan NguyenFriend
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
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 #1158630 is a reply to message #1157316] Mon, 28 October 2013 02:48 Go to previous messageGo to next message
Tuan Nguyen is currently offline Tuan NguyenFriend
Messages: 3
Registered: August 2011
Junior Member
Thanks Ed.

I did change the ID property for the EAttribute to true & reloaded my genmodel. How do I check if that change has been reflected on the generated code? I checked the generated interface (Role) and implementation class (RoleImpl). And I didn't notice any change in the code reflecting that.
Re: Transforming XMI serialization of EReference [message #1158849 is a reply to message #1158630] Mon, 28 October 2013 06:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Tuan,

It's only a flag in the Ecore model so you'll only notice in the
metadata, i.e., the generated XyzPackage and XyzPackageImpl. When an
object has an ID, a reference to in the serialization should use that.


On 28/10/2013 3:48 AM, Tuan Nguyen wrote:
> Thanks Ed.
>
> I did change the ID property for the EAttribute to true & reloaded my
> genmodel. How do I check if that change has been reflected on the
> generated code? I checked the generated interface (Role) and
> implementation class (RoleImpl). And I didn't notice any change in the
> code reflecting that.


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 Go to previous message
Tuan Nguyen is currently offline Tuan NguyenFriend
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

Previous Topic:Net4j Buddies Example
Next Topic:[CDO]Persistent Ecore dynamic model to the database????
Goto Forum:
  


Current Time: Thu Apr 25 09:34:45 GMT 2024

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

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

Back to the top