Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [xcore] Dynamic instance deserialization problem(A second Ecore package seems to be loaded during resource deserialization.)
[xcore] Dynamic instance deserialization problem [message #1407721] Wed, 13 August 2014 09:50 Go to next message
Csaba Koncz is currently offline Csaba KonczFriend
Messages: 49
Registered: July 2009
Member
Hi All,

I am trying to perform validation on "dynamic" instances created from Xcore models.

I went through the forum discussion mentioned in https://bugs.eclipse.org/bugs/show_bug.cgi?id=387010 and was able to define invariants in my Xcore model which worked well when using the generated package.

However, when loading the dynamic instance XMI into the Reflective Ecore Editor, the invariants are no longer recognized.
The reason is that the EPackage of the dynamic instance refers to a newly loaded Ecore package and not to the generated one. As a result EcoreUtil.isInvariant() returns false because it checks reference equality (and not EcorePackage.Literals.EBOOLEAN.equals(..))

I am attaching a sample Xcore project that contains a SerializationTest (that needs to be run as a plugin test).
The test methods of the test class demonstrate the two use cases: when
using the generated classes, the operation is recognized as an invariant,
in the "dynamic" case, it is not.

What could be the solution?

Thank you in advance,
Csaba
  • Attachment: dynmodel1.zip
    (Size: 16.75KB, Downloaded 118 times)
Re: [xcore] Dynamic instance deserialization problem [message #1407754 is a reply to message #1407721] Wed, 13 August 2014 11:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Csaba,

Comments below.

On 13/08/2014 11:50 AM, Csaba Koncz wrote:
> Hi All,
>
> I am trying to perform validation on "dynamic" instances created from Xcore models.
>
> I went through the forum discussion mentioned in https://bugs.eclipse.org/bugs/show_bug.cgi?id=387010 and was able to define invariants in my Xcore model which worked well when using the generated package.
>
> However, when loading the dynamic instance XMI into the Reflective Ecore Editor, the invariants are no longer recognized.
No, there's no support for that.
>
> The reason is that the EPackage of the dynamic instance refers to a newly loaded Ecore package and not to the generated one. As a result EcoreUtil.isInvariant() returns false because it checks reference equality (and not EcorePackage.Literals.EBOOLEAN.equals(..))
It wouldn't matter because it's an EObject and EObject's don't override
equals...
>
> I am attaching a sample Xcore project that contains a SerializationTest (that needs to be run as a plugin test).
> The test methods of the test class demonstrate the two use cases: when
> using the generated classes, the operation is recognized as an invariant,
> in the "dynamic" case, it is not.
>
> What could be the solution?
The problem is that all the existing validation infrastructure pass
around strings that are expected to be passed to an interpreter, but
that doesn't work for Xcore because we must compile the Xbase body in
the full context of the containing Xcore constructs. So while one can
invoke operations dynamically, the underlying validation infrastructure
doesn't try to do that.

Trying to make this all work is several weeks of effort...
>
> Thank you in advance,
> Csaba
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [xcore] Dynamic instance deserialization problem [message #1407770 is a reply to message #1407754] Wed, 13 August 2014 12:11 Go to previous messageGo to next message
Csaba Koncz is currently offline Csaba KonczFriend
Messages: 49
Registered: July 2009
Member
Hi Ed,

Thank you for the quick reply.
I think I was not clear enough.

I did not expect the framework to pick up my invariants and interpret them (which would be nice, of course, but saw from the previous forum posts that it is not implemented yet).

Instead, registered my own ValidationDelegate implementation and expected DynamicEClassValidator to provide me with the the expression string that needs to be interpreted. (I thought it might be not that difficult to implement Xbase evaluation, but after your comments I will reconsider that.)

The problem was that I did not get to the point where the ValidationDelegate.evaluate() method is invoked because of the issue described earlier: when inspecting the EOperations of the dynamic instance class,
some EBoolean data type is found which is not the same as EcorePackage.LITERALS.EBOOLEAN.
I think the Ecore.ecore package is somehow deserialized during the dynamic instance loading and I get references to the latter instances instead to the ones stored in EcorePackage.LITERALS.

Csaba


Ed Merks wrote on Wed, 13 August 2014 07:20
Csaba,

Comments below.

On 13/08/2014 11:50 AM, Csaba Koncz wrote:
> Hi All,
>
> I am trying to perform validation on "dynamic" instances created from Xcore models.
>
> I went through the forum discussion mentioned in https://bugs.eclipse.org/bugs/show_bug.cgi?id=387010 and was able to define invariants in my Xcore model which worked well when using the generated package.
>
> However, when loading the dynamic instance XMI into the Reflective Ecore Editor, the invariants are no longer recognized.
No, there's no support for that.
>
> The reason is that the EPackage of the dynamic instance refers to a newly loaded Ecore package and not to the generated one. As a result EcoreUtil.isInvariant() returns false because it checks reference equality (and not EcorePackage.Literals.EBOOLEAN.equals(..))
It wouldn't matter because it's an EObject and EObject's don't override
equals...
>
> I am attaching a sample Xcore project that contains a SerializationTest (that needs to be run as a plugin test).
> The test methods of the test class demonstrate the two use cases: when
> using the generated classes, the operation is recognized as an invariant,
> in the "dynamic" case, it is not.
>
> What could be the solution?
The problem is that all the existing validation infrastructure pass
around strings that are expected to be passed to an interpreter, but
that doesn't work for Xcore because we must compile the Xbase body in
the full context of the containing Xcore constructs. So while one can
invoke operations dynamically, the underlying validation infrastructure
doesn't try to do that.

Trying to make this all work is several weeks of effort...
>
> Thank you in advance,
> Csaba
>

Re: [xcore] Dynamic instance deserialization problem [message #1407781 is a reply to message #1407770] Wed, 13 August 2014 12:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Csaba,

Comments below.

On 13/08/2014 2:11 PM, Csaba Koncz wrote:
> Hi Ed,
>
> Thank you for the quick reply.
> I think I was not clear enough.
>
> I did not expect the framework to pick up my invariants and interpret
> them (which would be nice, of course, but saw from the previous forum
> posts that it is not implemented yet).
>
> Instead, registered my own ValidationDelegate implementation and
> expected DynamicEClassValidator to provide me with the the expression
> string that needs to be interpreted. (I thought it might be not that
> difficult to implement Xbase evaluation, but after your comments I
> will reconsider that.)
I see, and for that the current implementation that expects models to
use the generated Ecore model is problematic... I don't think a
validation delegate specialized for Xcore (to invoke invariant
operations reflectively) would be so difficult, it's just the
generalizing all this to support things (classifier constraints) other
than invariants that's quite challenging...
>
> The problem was that I did not get to the point where the
> ValidationDelegate.evaluate() method is invoked because of the issue
> described earlier: when inspecting the EOperations of the dynamic
> instance class, some EBoolean data type is found which is not the same
> as EcorePackage.LITERALS.EBOOLEAN. I think the Ecore.ecore package is
> somehow deserialized during the dynamic instance loading and I get
> references to the latter instances instead to the ones stored in
> EcorePackage.LITERALS.
No, with Xcore we consistently use the development time version of
Ecore. Please open a bugzilla and I'll look at how to make
org.eclipse.emf.ecore.util.EcoreUtil.isInvariant(EOperation) permit the
development time version(s) of Ecore. Please include your test case in
the bugzilla.
>
> Csaba
>
>
> Ed Merks wrote on Wed, 13 August 2014 07:20
>> Csaba,
>>
>> Comments below.
>>
>> On 13/08/2014 11:50 AM, Csaba Koncz wrote:
>> > Hi All,
>> >
>> > I am trying to perform validation on "dynamic" instances created
>> from Xcore models.
>> >
>> > I went through the forum discussion mentioned in
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=387010 and was able to
>> define invariants in my Xcore model which worked well when using the
>> generated package.
>> >
>> > However, when loading the dynamic instance XMI into the Reflective
>> Ecore Editor, the invariants are no longer recognized.
>> No, there's no support for that.
>> > > The reason is that the EPackage of the dynamic instance refers
>> to a newly loaded Ecore package and not to the generated one. As a
>> result EcoreUtil.isInvariant() returns false because it checks
>> reference equality (and not EcorePackage.Literals.EBOOLEAN.equals(..))
>> It wouldn't matter because it's an EObject and EObject's don't
>> override equals...
>> >
>> > I am attaching a sample Xcore project that contains a
>> SerializationTest (that needs to be run as a plugin test).
>> > The test methods of the test class demonstrate the two use cases: when
>> > using the generated classes, the operation is recognized as an
>> invariant,
>> > in the "dynamic" case, it is not.
>> >
>> > What could be the solution?
>> The problem is that all the existing validation infrastructure pass
>> around strings that are expected to be passed to an interpreter, but
>> that doesn't work for Xcore because we must compile the Xbase body in
>> the full context of the containing Xcore constructs. So while one
>> can invoke operations dynamically, the underlying validation
>> infrastructure doesn't try to do that.
>>
>> Trying to make this all work is several weeks of effort...
>> >
>> > Thank you in advance,
>> > Csaba
>> >
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [xcore] Dynamic instance deserialization problem [message #1407800 is a reply to message #1407781] Wed, 13 August 2014 13:35 Go to previous messageGo to next message
Csaba Koncz is currently offline Csaba KonczFriend
Messages: 49
Registered: July 2009
Member
Hi Ed,

Thank you again, and here is the bugzilla: https://bugs.eclipse.org/bugs/show_bug.cgi?id=441688

In the meantime I got a bit closer to the mystery, I think. I exported my xcore to ecore to see if the problem is Xcore related, and discovered that the ecore has references like these:

eType="ecore:EDataType ../../org.eclipse.emf.ecore/model/Ecore.ecore#//EBoolean"

If I replace this reference with
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"

then the dynamic instance created from the Ecore model works as expected (i.e. the correct EBoolean from EcorePackage.Literals is used).

Best regards,
Csaba
Re: [xcore] Dynamic instance deserialization problem [message #1407840 is a reply to message #1407800] Wed, 13 August 2014 15:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Csaba,

Yes, Xcore consistently uses the development time version of Ecore,
which is reflected in what you see when you export it.


On 13/08/2014 3:35 PM, Csaba Koncz wrote:
> Hi Ed,
>
> Thank you again, and here is the bugzilla:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=441688
>
> In the meantime I got a bit closer to the mystery, I think. I exported
> my xcore to ecore to see if the problem is Xcore related, and
> discovered that the ecore has references like these:
>
>
> eType="ecore:EDataType
> ../../org.eclipse.emf.ecore/model/Ecore.ecore#//EBoolean"
>
> If I replace this reference with
>
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"
>
> then the dynamic instance created from the Ecore model works as
> expected (i.e. the correct EBoolean from EcorePackage.Literals is used).
>
> Best regards,
> Csaba
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [xcore] Dynamic instance deserialization problem [message #1408074 is a reply to message #1407840] Thu, 14 August 2014 07:08 Go to previous messageGo to next message
Csaba Koncz is currently offline Csaba KonczFriend
Messages: 49
Registered: July 2009
Member
Hi Ed,

What I see is then the correct behavior?

I mean that deserializing this Ecore XML snippet
<eStructuralFeatures xsi:type="ecore:EAttribute" name="booleanAtt"
  eType="ecore:EDataType ../../org.eclipse.emf.ecore/model/Ecore.ecore#//EBoolean"
/>

now results in two Ecore packages being referenced:
1. the eClass of the created attribute belongs to the "runtime" Ecore package in resource http://www.eclipse.org/emf/2002/Ecore
2. the eType of the attribute belongs to the "development" Ecore package in resource platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore

So do we have to be prepared to encounter multiple instances of the Ecore package when reading .ecore or .xcore files?

Thank you,
Csaba


Re: [xcore] Dynamic instance deserialization problem [message #1408154 is a reply to message #1408074] Thu, 14 August 2014 11:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Csaba,

Comments below.

On 14/08/2014 9:08 AM, Csaba Koncz wrote:
> Hi Ed,
>
> What I see is then the correct behavior?
Yes.
>
> I mean that deserializing this Ecore XML snippet
>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="booleanAtt"
> eType="ecore:EDataType
> ../../org.eclipse.emf.ecore/model/Ecore.ecore#//EBoolean"
> />
>
> now results in two Ecore packages being referenced: 1. the eClass of
> the created attribute belongs to the "runtime" Ecore package in
> resource http://www.eclipse.org/emf/2002/Ecore
> 2. the eType of the attribute belongs to the "development" Ecore
> package in resource
> platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore
Yes, that's right. This is always a possibility, even when not using
Xcore. In fact, models that use things from Ecore (other than
EDataTypes or the EObject EClass), generally will use the development
time version...
>
> So do we have to be prepared to encounter multiple instances of the
> Ecore package when reading .ecore or .xcore files?
Yes.
>
> Thank you,
> Csaba
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [xcore] Dynamic instance deserialization problem [message #1408182 is a reply to message #1408154] Thu, 14 August 2014 12:52 Go to previous messageGo to next message
Csaba Koncz is currently offline Csaba KonczFriend
Messages: 49
Registered: July 2009
Member
Hi Ed,

Thank you for clarifying this.
My last question (I think) would be: are then the checks using reference equality like those in EcoreUtil.isInvariant() conceptually wrong?
Should we use comparison methods like
boolean areTheSame(EClassifier c1, EClassifier c2){
  //wrong: return c1==c2;
  boolean haveSameName=c1.getName().equals(c2.getName());
  boolean haveSameNs=c1.getEPackage().getNsURI().equals(c2.getEPackage().getNsURI());
  return haveSameName && haveSameNs;
}
instead?

Regards,
Csaba
Re: [xcore] Dynamic instance deserialization problem [message #1408195 is a reply to message #1408182] Thu, 14 August 2014 13:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Csaba,

Comments below.

On 14/08/2014 2:52 PM, Csaba Koncz wrote:
> Hi Ed,
>
> Thank you for clarifying this.
> My last question (I think) would be: are then the checks using
> reference equality like those in EcoreUtil.isInvariant() conceptually
> wrong?
Yes, if we're going to permit dynamic versions of Ecore to support this...
> Should we use comparison methods like
>
> boolean areTheSame(EClassifier c1, EClassifier c2){
> //wrong: return c1==c2;
> boolean haveSameName=c1.getName().equals(c2.getName());
> boolean
> haveSameNs=c1.getEPackage().getNsURI().equals(c2.getEPackage().getNsURI());
> return haveSameName && haveSameNs;
> }
> instead?
Yes, or we might check that they have the expected instance class like this:

return eOperation.getEType().getInstanceClass() == boolean.class &&
eOperation.getEParameters().size() == 2 &&
eOperation.getEParameters().get(0).getEType().getInstanceClass() ==
DiagnosticChain.class &&
eOperation.getEParameters().get(1).getEType().getInstanceClass() ==
Map.class;

After all, it's more the real Java signature of the operation that
matters rather than that it's using very specific EDataTypes.
>
> Regards,
> Csaba
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [xcore] Dynamic instance deserialization problem [message #1408209 is a reply to message #1408195] Thu, 14 August 2014 13:55 Go to previous message
Csaba Koncz is currently offline Csaba KonczFriend
Messages: 49
Registered: July 2009
Member
Ed, thank you a lot!
Best regards,
Csaba
Previous Topic:EMF Forms to RCP App
Next Topic:How do I download source code emf project?
Goto Forum:
  


Current Time: Fri Mar 29 12:39:45 GMT 2024

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

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

Back to the top