Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Ecore UUID serialization doubles id
Ecore UUID serialization doubles id [message #727484] Wed, 21 September 2011 11:06 Go to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 333
Registered: July 2009
Senior Member
Hi there,

I'm using an Ecore model with XML serialization using UUIDs for unique
identifiers.

I do this by overriding the useUUIDs() method in the corresponding
XMLResourceImpl with returning true.

Now the "id" property of a model is just another EMF feature and hence,
I can change it manually. If I do so, e.g. set an id to "foo23" and save
the model in the sample tree editor, it will save an xml element with
two id attributes, i.e. invalid XML like this

<myReference xsi:type="foo:MyType" id="_WIWryuRAEeC_QIwRrW2zOQ" id="foo23">
</myReference>

I found out, that the additional ID is assigned when loading the model.
So I also overwrote addignIDsWhileLoading() with false in the
XMLResourceImpl.

Now when I programmatically do a resource.save(), I again get the
doubled id Attribute this time from

org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(EObject o)

because it is nowhere checked whether the element might already have
feature called "id" that is already set.

Is this behavior a bug or a feature?


Rationale: I want to use UUIDs, but in some cases, I create my model by
a M2M transformation from some other language where I would like to
preserve the UUIDs from the origin model. So I copy them to the target
model semantically as "id" is just another business property in my model.



Cheers,
Hauke
Re: Ecore UUID serialization doubles id [message #727485 is a reply to message #727484] Wed, 21 September 2011 11:28 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Hauke,

Comments below.

On 21/09/2011 7:06 AM, Hauke Fuhrmann wrote:
> Hi there,
>
> I'm using an Ecore model with XML serialization using UUIDs for unique
> identifiers.
>
> I do this by overriding the useUUIDs() method in the corresponding
> XMLResourceImpl with returning true.
>
> Now the "id" property of a model is just another EMF feature and
> hence, I can change it manually. If I do so, e.g. set an id to "foo23"
> and save the model in the sample tree editor, it will save an xml
> element with two id attributes, i.e. invalid XML like this
>
> <myReference xsi:type="foo:MyType" id="_WIWryuRAEeC_QIwRrW2zOQ"
> id="foo23">
> </myReference>
>
> I found out, that the additional ID is assigned when loading the
> model. So I also overwrote addignIDsWhileLoading() with false in the
> XMLResourceImpl.
>
> Now when I programmatically do a resource.save(), I again get the
> doubled id Attribute this time from
>
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(EObject o)
>
> because it is nowhere checked whether the element might already have
> feature called "id" that is already set.
>
> Is this behavior a bug or a feature?
The extrinsic IDs and intrinsic IDs are two different things and there
is a general assumption that you use one or the other, but not both. It
clearly don't make sense to have more than one ID, so you should decide
on one approach (let resource assign and manage them) or the other
(model them in the objects themselves and let them control and manage them).
>
>
> Rationale: I want to use UUIDs, but in some cases, I create my model
> by a M2M transformation from some other language where I would like to
> preserve the UUIDs from the origin model.
XMLResource.setID can be used to assign an ID of your choice.
> So I copy them to the target model semantically as "id" is just
> another business property in my model.
There's no support for mixing the two approaches.

Maybe you look into specializing XMLResourceImpl to avoid generating a
UUID for objects with an intrinsic ID. Not sure how best to do that...
Maybe getID would return the intrinsic ID if there is one... Or maybe
attachedHelper should ignore objects with an intrinsic ID...
>
>
>
> Cheers,
> Hauke


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Xcore, Ecore and Genmodel in other DSLs
Next Topic:[CDO] Launching server programmatically
Goto Forum:
  


Current Time: Thu Mar 28 15:23:53 GMT 2024

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

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

Back to the top