Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » eGet(ref) does not return a collection but only its first element
eGet(ref) does not return a collection but only its first element [message #500495] Thu, 26 November 2009 11:43 Go to next message
Patrick Konemann is currently offline Patrick KonemannFriend
Messages: 116
Registered: July 2009
Senior Member
Hi Newsgroup,

I'm trying to validate some constraints on my model using EMF Reflection.
However, a call on eGet does not return a collection of referenced elements (as expected) but only the first element.
Let me show the effect (using the OCL Console):

Evaluating:
self.modelElement.eGet(self.ref)
Results:
Entity Added

If I don't use reflection but access the model directly, I get the expected result:

Evaluating:
self.modelElement.oclAsType(mymodel::Entity).multiReference
Results:
Entity Added
Entity subAdded
Entity root


mymodel::Entity is just an EClass which has a reference (multiReference) to itself with cardinality *.

The context element (self) has a reference to the EReference Entity.multiReference ('ref') and to EObject ('modelElement').

I guess the problem is that EObject.eGet(EStructuralFeature) as defined in the ecore model returns java.lang.Object?
Thus ocl does not now how to treat the result correctly?
I also tried to cast it somehow (...eGet(self.ref)->asSet(), ...eGet(self.ref).oclAsType(...)), but no success yet.

I need that feature, because I want to define the constraints without knowing the exact model (mymodel in this case).

Any help is appreciated.

Best regards
Patrick
Re: eGet(ref) does not return a collection but only its first element [message #500523 is a reply to message #500495] Thu, 26 November 2009 14:22 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 844
Registered: July 2009
Senior Member
--=-M6uyN/wZxXDrNQkv6XY8
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi, Patrick,

You are correct: the Object return signature means that OCL thinks the
eGet operation is a scalar value. The multiplicity of a feature
determines whether it is a collection value, and if so, which kind of
collection.

In the OCL 2.0 language specification, collection types are quite
different from all others. In particular, there is no facility for
testing type conformance of collections nor for casting objects to a
collection type. Collections are a completely distinct type hierarchy.

The OCL 2.1 specification will change that, and it appears from previous
traffic in this newsgroup that Ed W. is working hard to update the MDT
OCL implementation for 2.1 conformance. OCL 2.1 (the language, not the
release) will allow the cast to collection type that you need. Whether
that will actually be available in Helios is a question for the MDT OCL
committers to answer. You might check their project plan and bugzilla
for more details on what to expect.

Cheers,

Christian


On Thu, 2009-11-26 at 12:43 +0100, Patrick K=C3=B6nemann wrote:

> Hi Newsgroup,
>=20
> I'm trying to validate some constraints on my model using EMF Reflection.
> However, a call on eGet does not return a collection of referenced elemen=
ts (as expected) but only the first element.
> Let me show the effect (using the OCL Console):
>=20
> Evaluating:
> self.modelElement.eGet(self.ref)
> Results:
> Entity Added
>=20
> If I don't use reflection but access the model directly, I get the expect=
ed result:
>=20
> Evaluating:
> self.modelElement.oclAsType(mymodel::Entity).multiReference
> Results:
> Entity Added
> Entity subAdded
> Entity root
>=20
>=20
> mymodel::Entity is just an EClass which has a reference (multiReference) =
to itself with cardinality *.
>=20
> The context element (self) has a reference to the EReference Entity.multi=
Reference ('ref') and to EObject ('modelElement').
>=20
> I guess the problem is that EObject.eGet(EStructuralFeature) as defined i=
n the ecore model returns java.lang.Object?
> Thus ocl does not now how to treat the result correctly?
> I also tried to cast it somehow (...eGet(self.ref)->asSet(), ...eGet(self=
..ref).oclAsType(...)), but no success yet.
>=20
> I need that feature, because I want to define the constraints without kno=
wing the exact model (mymodel in this case).
>=20
> Any help is appreciated.
>=20
> Best regards
> Patrick

--=-M6uyN/wZxXDrNQkv6XY8
Content-Type: text/html; charset="utf-8"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, Patrick,<BR>
<BR>
You are correct:&nbsp; the Object return signature means that OCL thinks the eGet operation is a scalar value.&nbsp; The multiplicity of a feature determines whether it is a collection value, and if so, which kind of collection.<BR>
<BR>
In the OCL 2.0 language specification, collection types are quite different from all others.&nbsp; In particular, there is no facility for testing type conformance of collections nor for casting objects to a collection type.&nbsp; Collections are a completely distinct type hierarchy.<BR>
<BR>
The OCL 2.1 specification will change that, and it appears from previous traffic in this newsgroup that Ed W. is working hard to update the MDT OCL implementation for 2.1 conformance.&nbsp; OCL 2.1 (the language, not the release) will allow the cast to collection type that you need.&nbsp; Whether that will actually be available in Helios is a question for the MDT OCL committers to answer.&nbsp; You might check their project plan and bugzilla for more details on what to expect.<BR>
<BR>
Cheers,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Thu, 2009-11-26 at 12:43 +0100, Patrick K&#246;nemann wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Hi Newsgroup,

I'm trying to validate some constraints on my model using EMF Reflection.
However, a call on eGet does not return a collection of referenced elements (as expected) but only the first element.
Let me show the effect (using the OCL Console):

Evaluating:
self.modelElement.eGet(self.ref)
Results:
Entity Added

If I don't use reflection but access the model directly, I get the expected result:

Evaluating:
self.modelElement.oclAsType(mymodel::Entity).multiReference
Results:
Entity Added
Entity subAdded
Entity root


mymodel::Entity is just an EClass which has a reference (multiReference) to itself with cardinality *.

The context element (self) has a reference to the EReference Entity.multiReference ('ref') and to EObject ('modelElement').

I guess the problem is that EObject.eGet(EStructuralFeature) as defined in the ecore model returns java.lang.Object?
Thus ocl does not now how to treat the result correctly?
I also tried to cast it somehow (...eGet(self.ref)-&gt;asSet(), ...eGet(self.ref).oclAsType(...)), but no success yet.

I need that feature, because I want to define the constraints without knowing the exact model (mymodel in this case).

Any help is appreciated.

Best regards
Patrick
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-M6uyN/wZxXDrNQkv6XY8--
Re: eGet(ref) does not return a collection but only its first element [message #500526 is a reply to message #500495] Thu, 26 November 2009 14:27 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 844
Registered: July 2009
Senior Member
--=-WXkZaqhsdrp91rS7yT4b
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi, Patrick,

In the mean-time, you can work around this problem by implementing a
helper operation in a custom OCL environment. You would probably need
to do it in Java; see the "Customizing the Environment" page in the OCL
Developer Guide documentation for the example of adding a regex
"matches(String) : boolean" operation to the String primitive type. You
could similarly add an "eGetCollection(EStructuralFeature) :
Collection(OclAny)" operation to OclAny that always returns a
collection, even if it is just a singleton containing the feature's
scalar value. You still won't be able to work around the absence of a
cast operation.

HTH,

Christian


On Thu, 2009-11-26 at 12:43 +0100, Patrick K=C3=B6nemann wrote:

> Hi Newsgroup,
>=20
> I'm trying to validate some constraints on my model using EMF Reflection.
> However, a call on eGet does not return a collection of referenced elemen=
ts (as expected) but only the first element.
> Let me show the effect (using the OCL Console):
>=20
> Evaluating:
> self.modelElement.eGet(self.ref)
> Results:
> Entity Added
>=20
> If I don't use reflection but access the model directly, I get the expect=
ed result:
>=20
> Evaluating:
> self.modelElement.oclAsType(mymodel::Entity).multiReference
> Results:
> Entity Added
> Entity subAdded
> Entity root
>=20
>=20
> mymodel::Entity is just an EClass which has a reference (multiReference) =
to itself with cardinality *.
>=20
> The context element (self) has a reference to the EReference Entity.multi=
Reference ('ref') and to EObject ('modelElement').
>=20
> I guess the problem is that EObject.eGet(EStructuralFeature) as defined i=
n the ecore model returns java.lang.Object?
> Thus ocl does not now how to treat the result correctly?
> I also tried to cast it somehow (...eGet(self.ref)->asSet(), ...eGet(self=
..ref).oclAsType(...)), but no success yet.
>=20
> I need that feature, because I want to define the constraints without kno=
wing the exact model (mymodel in this case).
>=20
> Any help is appreciated.
>=20
> Best regards
> Patrick

--=-WXkZaqhsdrp91rS7yT4b
Content-Type: text/html; charset="utf-8"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, Patrick,<BR>
<BR>
In the mean-time, you can work around this problem by implementing a helper operation in a custom OCL environment.&nbsp; You would probably need to do it in Java; see the &quot;Customizing the Environment&quot; page in the OCL Developer Guide documentation for the example of adding a regex &quot;matches(String) : boolean&quot; operation to the String primitive type.&nbsp; You could similarly add an &quot;eGetCollection(EStructuralFeature) : Collection(OclAny)&quot; operation to OclAny that always returns a collection, even if it is just a singleton containing the feature's scalar value.&nbsp; You still won't be able to work around the absence of a cast operation.<BR>
<BR>
HTH,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Thu, 2009-11-26 at 12:43 +0100, Patrick K&#246;nemann wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Hi Newsgroup,

I'm trying to validate some constraints on my model using EMF Reflection.
However, a call on eGet does not return a collection of referenced elements (as expected) but only the first element.
Let me show the effect (using the OCL Console):

Evaluating:
self.modelElement.eGet(self.ref)
Results:
Entity Added

If I don't use reflection but access the model directly, I get the expected result:

Evaluating:
self.modelElement.oclAsType(mymodel::Entity).multiReference
Results:
Entity Added
Entity subAdded
Entity root


mymodel::Entity is just an EClass which has a reference (multiReference) to itself with cardinality *.

The context element (self) has a reference to the EReference Entity.multiReference ('ref') and to EObject ('modelElement').

I guess the problem is that EObject.eGet(EStructuralFeature) as defined in the ecore model returns java.lang.Object?
Thus ocl does not now how to treat the result correctly?
I also tried to cast it somehow (...eGet(self.ref)-&gt;asSet(), ...eGet(self.ref).oclAsType(...)), but no success yet.

I need that feature, because I want to define the constraints without knowing the exact model (mymodel in this case).

Any help is appreciated.

Best regards
Patrick
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-WXkZaqhsdrp91rS7yT4b--
Re: eGet(ref) does not return a collection but only its first element [message #500536 is a reply to message #500526] Thu, 26 November 2009 14:41 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1639
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050403020707000205070003
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Patrick, Christian,

Compliance with OCL 2.1 will not allow usage of eGet() because of a flaw
in the code itself.

bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=287052 describes the
same problem and the exact location of the code rejecting all other
values other than the first of the returned collection.

----------8<----------
if (value instanceof Collection) {
Collection<?> collection = (Collection<?>) value;
return collection.isEmpty() ? null : collection.iterator().next();
}
---------->8----------

I wanted to get rid of this bug, yet haven't found a more intelligent
workaround than the patch attached to that bug. And it seems I didn't
manage to convince Ed that this not working was an issue.

Laurent Goubet
Obeo

Christian W. Damus wrote:
> Hi, Patrick,
>
> In the mean-time, you can work around this problem by implementing a
> helper operation in a custom OCL environment. You would probably need
> to do it in Java; see the "Customizing the Environment" page in the OCL
> Developer Guide documentation for the example of adding a regex
> "matches(String) : boolean" operation to the String primitive type. You
> could similarly add an "eGetCollection(EStructuralFeature) :
> Collection(OclAny)" operation to OclAny that always returns a
> collection, even if it is just a singleton containing the feature's
> scalar value. You still won't be able to work around the absence of a
> cast operation.
>
> HTH,
>
> Christian
>
>
> On Thu, 2009-11-26 at 12:43 +0100, Patrick Könemann wrote:
>> Hi Newsgroup,
>>
>> I'm trying to validate some constraints on my model using EMF Reflection.
>> However, a call on eGet does not return a collection of referenced elements (as expected) but only the first element.
>> Let me show the effect (using the OCL Console):
>>
>> Evaluating:
>> self.modelElement.eGet(self.ref)
>> Results:
>> Entity Added
>>
>> If I don't use reflection but access the model directly, I get the expected result:
>>
>> Evaluating:
>> self.modelElement.oclAsType(mymodel::Entity).multiReference
>> Results:
>> Entity Added
>> Entity subAdded
>> Entity root
>>
>>
>> mymodel::Entity is just an EClass which has a reference (multiReference) to itself with cardinality *.
>>
>> The context element (self) has a reference to the EReference Entity.multiReference ('ref') and to EObject ('modelElement').
>>
>> I guess the problem is that EObject.eGet(EStructuralFeature) as defined in the ecore model returns java.lang.Object?
>> Thus ocl does not now how to treat the result correctly?
>> I also tried to cast it somehow (...eGet(self.ref)->asSet(), ...eGet(self.ref).oclAsType(...)), but no success yet.
>>
>> I need that feature, because I want to define the constraints without knowing the exact model (mymodel in this case).
>>
>> Any help is appreciated.
>>
>> Best regards
>> Patrick


--------------050403020707000205070003
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------050403020707000205070003--
Re: eGet(ref) does not return a collection but only its first element [message #500541 is a reply to message #500536] Thu, 26 November 2009 15:05 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 844
Registered: July 2009
Senior Member
--=-Fvyo5utFkOeY6l0l5y0l
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Laurent,

Support for OCL 2.1 will have to revise this code. It is only as it is
now because of the need to coerce a collection value to a scalar.
Probably when support for casting to CollectionTypes is implemented,
this coercion of collection values should be eliminated altogether.

The actual reason why it was implemented in the first place (I think)
was to support the "indeterminate upper bound" (-2) of
EStructuralFeatures in feature maps (XSD-isms).

Cheers,

Christian

On Thu, 2009-11-26 at 15:41 +0100, Laurent Goubet wrote:

> Patrick, Christian,
>
> Compliance with OCL 2.1 will not allow usage of eGet() because of a flaw
> in the code itself.
>
> bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=287052 describes the
> same problem and the exact location of the code rejecting all other
> values other than the first of the returned collection.
>
> ----------8<----------
> if (value instanceof Collection) {
> Collection<?> collection = (Collection<?>) value;
> return collection.isEmpty() ? null : collection.iterator().next();
> }
> ---------->8----------
>
> I wanted to get rid of this bug, yet haven't found a more intelligent
> workaround than the patch attached to that bug. And it seems I didn't
> manage to convince Ed that this not working was an issue.
>
> Laurent Goubet
> Obeo
>
> Christian W. Damus wrote:


--------8<--------

--=-Fvyo5utFkOeY6l0l5y0l
Content-Type: text/html; charset="utf-8"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, Laurent,<BR>
<BR>
Support for OCL 2.1 will have to revise this code.&nbsp; It is only as it is now because of the need to coerce a collection value to a scalar.&nbsp; Probably when support for casting to CollectionTypes is implemented, this coercion of collection values should be eliminated altogether.<BR>
<BR>
The actual reason why it was implemented in the first place (I think) was to support the &quot;indeterminate upper bound&quot; (-2) of EStructuralFeatures in feature maps (XSD-isms).<BR>
<BR>
Cheers,<BR>
<BR>
Christian<BR>
<BR>
On Thu, 2009-11-26 at 15:41 +0100, Laurent Goubet wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Patrick, Christian,

Compliance with OCL 2.1 will not allow usage of eGet() because of a flaw
in the code itself.

bug <A HREF="https://bugs.eclipse.org/bugs/show_bug.cgi?id=287052">https://bugs.eclipse.org/bugs/show_bug.cgi?id=287052</A> describes the
same problem and the exact location of the code rejecting all other
values other than the first of the returned collection.

----------8&lt;----------
if (value instanceof Collection) {
Collection&lt;?&gt; collection = (Collection&lt;?&gt;) value;
return collection.isEmpty() ? null : collection.iterator().next();
}
----------&gt;8----------

I wanted to get rid of this bug, yet haven't found a more intelligent
workaround than the patch attached to that bug. And it seems I didn't
manage to convince Ed that this not working was an issue.

Laurent Goubet
Obeo

Christian W. Damus wrote:
</PRE>
</BLOCKQUOTE>
<BR>
--------8&lt;--------
</BODY>
</HTML>

--=-Fvyo5utFkOeY6l0l5y0l--
Re: eGet(ref) does not return a collection but only its first element [message #500547 is a reply to message #500526] Thu, 26 November 2009 15:45 Go to previous message
Patrick Konemann is currently offline Patrick KonemannFriend
Messages: 116
Registered: July 2009
Senior Member
Hi Christian

Thank you for the information, that was helpful.
The eGetCollection workaround works fine :-)

Cheers
Patrick


On 26-11-2009 15:27, Christian W. Damus wrote:
> Hi, Patrick,
>
> In the mean-time, you can work around this problem by implementing a
> helper operation in a custom OCL environment. You would probably need to
> do it in Java; see the "Customizing the Environment" page in the OCL
> Developer Guide documentation for the example of adding a regex
> "matches(String) : boolean" operation to the String primitive type. You
> could similarly add an "eGetCollection(EStructuralFeature) :
> Collection(OclAny)" operation to OclAny that always returns a
> collection, even if it is just a singleton containing the feature's
> scalar value. You still won't be able to work around the absence of a
> cast operation.
>
> HTH,
>
> Christian
>
>
> On Thu, 2009-11-26 at 12:43 +0100, Patrick Könemann wrote:
>> Hi Newsgroup,
>>
>> I'm trying to validate some constraints on my model using EMF Reflection.
>> However, a call on eGet does not return a collection of referenced elements (as expected) but only the first element.
>> Let me show the effect (using the OCL Console):
>>
>> Evaluating:
>> self.modelElement.eGet(self.ref)
>> Results:
>> Entity Added
>>
>> If I don't use reflection but access the model directly, I get the expected result:
>>
>> Evaluating:
>> self.modelElement.oclAsType(mymodel::Entity).multiReference
>> Results:
>> Entity Added
>> Entity subAdded
>> Entity root
>>
>>
>> mymodel::Entity is just an EClass which has a reference (multiReference) to itself with cardinality *.
>>
>> The context element (self) has a reference to the EReference Entity.multiReference ('ref') and to EObject ('modelElement').
>>
>> I guess the problem is that EObject.eGet(EStructuralFeature) as defined in the ecore model returns java.lang.Object?
>> Thus ocl does not now how to treat the result correctly?
>> I also tried to cast it somehow (...eGet(self.ref)->asSet(), ...eGet(self.ref).oclAsType(...)), but no success yet.
>>
>> I need that feature, because I want to define the constraints without knowing the exact model (mymodel in this case).
>>
>> Any help is appreciated.
>>
>> Best regards
>> Patrick
Previous Topic:how to define operations?
Next Topic:implemented usecases
Goto Forum:
  


Current Time: Thu Dec 18 07:32:18 GMT 2014

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

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