De-serialization of extended eCore models [message #658314] |
Mon, 07 March 2011 15:33  |
Eclipse User |
|
|
|
I am looking for advice on how to approach extending an existing eCore model to add an EAttribute to an EClass. Besides extending and generating my own model, what else is required so that the model will load?
Below is a psuedo representation of a serialized model as it currently is.
<uri1:parent
xmlns:uri1="URI1"
xmlns:xx="SomeTypeURI"
xsi:noNamespaceSchema="URI1"
...
>
<child id="A">
<gchild xsi:type="xx:SomeType">SOMEVALUE</gchild>
</child>
</parent>
I wish to add a new "myAttr" attribute to the "child" element such that I have:
<uri1:parent
xmlns:uri1="URI1"
xmlns:xx="SomeTypeURI"
xsi:noNamespaceSchema="URI1"
...
xmlns:uri2="MyModelURI"
>
<!-- Preferred option but doubt that this is possible -->
<child id="A" myAttr="something">
<gchild xsi:type="xx:SomeType">SOMEVALUE</gchild>
</child>
<!-- OR -->
<child xsi:type="uri2:childSubclass" id="A" myAttr="something">
<gchild xsi:type="xx:SomeType">SOMEVALUE</gchild>
</child>
<!-- OR -->
<uri2:childSubclass id="A" myAttr="something">
<gchild xsi:type="xx:SomeType">SOMEVALUE</gchild>
</uri2:childSubclass>
</parent>
All of my many attempts so far have failed to successfully load a model and I am not sure where the problem is. Either the child subclass does not load correctly, or the gchild value does not. I have not been successful in finding a post or set of posts that can assist me with the steps involved.
Many thanks in advance.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: De-serialization of extended eCore models [message #660099 is a reply to message #660080] |
Wed, 16 March 2011 15:28  |
Eclipse User |
|
|
|
JK,
Comments below.
JK wrote:
> Thanks Ed. Let me try again.
>>> The reason I created the uri2 eCore model and extended the uri1
>>> eClasses was because I cannot alter the uri1 eCore model to add
>>> attributes.
>> Why not?
>
> In my case, the base eCore model is coming from open source. Even if
> it wasn't, I would imagine that there are plenty of times that people
> would like to enhance an eCore model without modifying it.
Indeed.
>
>> Yet you're asking for precisely something that's XML which can't be
>> processed in a standard way...
>
> That's a fair criticism.
>> ... It's not clear why, though. Is it just an aesthetic thing? XML is
>> after all horribly ugly and barely fit for human consumption so
>> trying to make it prettier is a bit like putting lipstick on a pig. ...
>
> The instances of our models are static files that are always read
> only. They have either been created using xml editors, or generated
> as xml from other sources.
So they're being created in a way that conforms to no schemas...
> They are not created using generated EMF editors.
> We are taking existing model instances and decorating a handful of the
> elements with new attributes.
Because the base model didn't anticipate a need for
annotations/decorations...
> But in the absence of that attribute, a default value is implied.
> It would be so much cleaner to have instances of the child subclass
> after a load for that reason. The particular reason I would like to
> avoid adding an xsi:type attribute to every element is because it
> would make comparing the original model with the decorated one very
> difficult since there may be hundreds of child elements in the xml file.
Or you could look at it as just one more attribute; one that indicates
there will be decorations and what model those decorations conform to,
which seems like a good thing...
>
>> Is there some existing generated model over which you have no control?
>
> Are you asking if we could create our own genmodel for the base eCore
> model?
Yes. Or your own modified copy of that. In any case, to achieve what
you want, you'd have to do things like specialize
XMLSaveImpl.saveTypeAttribute to skip doing that in certain cases and
you could specialize XMLHelperImpl.createObject to substitute a derived
class for certain cases. Trying setting a breakpoint in these places
and see how they're invoked when loading and saving...
|
|
|
Powered by
FUDForum. Page generated in 0.05862 seconds