Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Generating custom composite IDs
Generating custom composite IDs [message #766289] Thu, 15 December 2011 14:03 Go to next message
Aleksandar Shterev is currently offline Aleksandar ShterevFriend
Messages: 2
Registered: December 2011
Junior Member
Hi everyone,

I'm almost sure this was probably asked before - but I had no luck finding the right search query Neutral

I am trying to load a XML file (generated from 3rd party software) using EMF, which is usually a relatively easy task to do. The problem is that the IDs in the original file relate to the data type of the models:

<imageInstance id="10">...<imageInstance>
<textInstance id="10">...<textInstance>

Where the first line refers to the ImageModel with id=10 and the second line to the TextModel with id=10.

I'm currently considering implementing a custom XMLHandler and then overwriting the IDs to contain both the target data type and the respective ID:
e.g. <textInstance id="TextModel:10">...<textInstance>
Of course this should happen before handleForwardReferences(true) is called.

So, am I on the right track and if not - what whould be the better way to do this?


Thanks for any suggestions and hints!

Cheers,
Alex
Re: Generating custom composite IDs [message #766367 is a reply to message #766289] Thu, 15 December 2011 16:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Aleksandar,

Comments below.

On 15/12/2011 3:03 PM, Aleksandar Shterev wrote:
> Hi everyone,
>
> I'm almost sure this was probably asked before - but I had no luck
> finding the right search query :|
>
> I am trying to load a XML file (generated from 3rd party software)
> using EMF, which is usually a relatively easy task to do. The problem
> is that the IDs in the original file relate to the data type of the
> models:
>
> <imageInstance id="10">...<imageInstance>
> <textInstance id="10">...<textInstance>
That's a problem. IDs are supposed to be unique across all instances.
XML Schema certainly dictates that for things of type xsd:ID...
>
> Where the first line refers to the ImageModel with id=10 and the
> second line to the TextModel with id=10.
>
> I'm currently considering implementing a custom XMLHandler and then
> overwriting the IDs to contain both the target data type and the
> respective ID:
> e.g. <textInstance id="TextModel:10">...<textInstance> Of course this
> should happen before handleForwardReferences(true) is called.
>
> So, am I on the right track and if not - what whould be the better way
> to do this?
Hmmm. Let's see. Maybe for each type you could define a special
EDataType that prefixes the type for createFromString and strips it for
convertToString so that in the model you end up with <Prefix><ID> and in
the serialization end up with just <ID>. I'm not sure though how your
references are looking right now. Can one place with a reference to
"10" refer to a different thing than a reference to "10" elsewhere? I.e.,
>
>
> Thanks for any suggestions and hints!
>
> Cheers,
> Alex


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Generating custom composite IDs [message #766808 is a reply to message #766367] Fri, 16 December 2011 13:15 Go to previous messageGo to next message
Aleksandar Shterev is currently offline Aleksandar ShterevFriend
Messages: 2
Registered: December 2011
Junior Member
Hi Ed,

thank you for replying.

Ed Merks wrote on Thu, 15 December 2011 11:27
I'm not sure though how your references are looking right now. Can one place with a reference to
"10" refer to a different thing than a reference to "10" elsewhere? I.e.,


Yes, that's exactly how it works, I know it's weird.. If I try to load the file in a resource like I normally would, I get a number of ClassCastExceptions because an ImageModel is resolved for a reference where a TextModel should have been. And in the model, the IDs are indeed ambiguous.

Therefore I was looking for a way to add prefices as a sort of namespaces. I actually got it working and now I'm looking to any inconsistencies. My idea is to change the IDs, save (and essentially "fix") the original resources, so they are all valid EMF models from this point on.

But I'll definitely look into the EDataType prefix - sooner or later I would probably have to do this conversion backwards as well..


Thanks again,
Alex
Re: Generating custom composite IDs [message #767189 is a reply to message #766808] Sat, 17 December 2011 09:07 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Aleksandar,

Comments below.

On 16/12/2011 2:15 PM, Aleksandar Shterev wrote:
> Hi Ed,
>
> thank you for replying.
> Ed Merks wrote on Thu, 15 December 2011 11:27
>> I'm not sure though how your references are looking right now. Can
>> one place with a reference to "10" refer to a different thing than a
>> reference to "10" elsewhere? I.e.,
>
>
> Yes, that's exactly how it works, I know it's weird..
It's certainly not something you can specify with XML Schema (other than
perhaps with keyref).
> If I try to load the file in a resource like I normally would, I get a
> number of ClassCastExceptions because an ImageModel is resolved for a
> reference where a TextModel should have been. And in the model, the
> IDs are indeed ambiguous.
> Therefore I was looking for a way to add prefices as a sort of
> namespaces. I actually got it working and now I'm looking to any
> inconsistencies. My idea is to change the IDs, save (and essentially
> "fix") the original resources, so they are all valid EMF models from
> this point on.
That's probably better in the long term.
>
> But I'll definitely look into the EDataType prefix - sooner or later I
> would probably have to do this conversion backwards as well..
I asked about the references because the data type thing only helps with
the IDs themselves. To fix references you'd probably want to defer all
ID resolution and then modify the handleForwardReferences so that the
prefix is added based on the feature from which the reference occurs.
>
>
> Thanks again,
> Alex


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:GSoC 2011 idea "EMF - ProtocolBuffer EMF Serialization"
Next Topic:DnD on a custom tree
Goto Forum:
  


Current Time: Fri Apr 26 02:42:24 GMT 2024

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

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

Back to the top