Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Using getValue(Stereotype, String) with Collections. Possible bug? (I can only manage to retrieve the first element of a collection)
Using getValue(Stereotype, String) with Collections. Possible bug? [message #540251] Tue, 15 June 2010 13:30 Go to next message
Adrian Noguero is currently offline Adrian NogueroFriend
Messages: 18
Registered: July 2009
Junior Member
Dear all,

I am trying to construct an OCL constraint that has to navigate all the elements of a property in a stereotype with [0..*] multiplicity. However, the following code returns true when two elements are included in the property list:

(The context is a UML Element)

self.getValue(self.getAppliedStereotype('Qualified::Name'), 'property')->size() = 1

However, if the collection is empty, the I do get a false in the query. Is this a bug or am I doing something incorrectly?

Thanks in advance!

Adrian
Re: Using getValue(Stereotype, String) with Collections. Possible bug? [message #540321 is a reply to message #540251] Tue, 15 June 2010 15:40 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------080508090106060504050903
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi Adrian,

This is a know bug : https://bugs.eclipse.org/bugs/show_bug.cgi?id=287052 .

In short, the "Element::getValue()" UML operation is defined to return
an "EJavaObject", and OCL will discard any value other than the very
first of Collection returned by such operations. If you use pure OCL, I
can't propose any workaround.

However, if you're using OCL through Acceleo templates, you can delegate
the call to the UML EOperation by using a Java service which explicitely
returns a Collection.

Laurent Goubet
Obeo

Adrián Noguero wrote:
> Dear all,
>
> I am trying to construct an OCL constraint that has to navigate all the
> elements of a property in a stereotype with [0..*] multiplicity.
> However, the following code returns true when two elements are included
> in the property list:
>
> (The context is a UML Element)
>
> self.getValue(self.getAppliedStereotype('Qualified::Name'),
> 'property')->size() = 1
>
> However, if the collection is empty, the I do get a false in the query.
> Is this a bug or am I doing something incorrectly?
>
> Thanks in advance!
>
> Adrian


--------------080508090106060504050903
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=
--------------080508090106060504050903--
Re: Using getValue(Stereotype, String) with Collections. Possible bug? [message #541072 is a reply to message #540321] Fri, 18 June 2010 08:53 Go to previous messageGo to next message
Adrian Noguero is currently offline Adrian NogueroFriend
Messages: 18
Registered: July 2009
Junior Member

Many thanks Laurent, sadly I have to use plain OCL in my project. I'll try to figure out some other walkaround and if I find it I will post it here.

Thanks again and best regards!

Adrian
Re: Using getValue(Stereotype, String) with Collections. Possible bug? [message #541110 is a reply to message #540321] Fri, 18 June 2010 12:07 Go to previous messageGo to next message
Adrian Noguero is currently offline Adrian NogueroFriend
Messages: 18
Registered: July 2009
Junior Member
Dear Laurent,

I managed to find a walkaround. It is not perfect, but at leats I may serve for the simplest cases.

I managed to access the values through the StereotypeApplication object and eCrossReferences() method. However, by using this mechanism I lost reference to the actual properties. In my case I can easily go over that issue through casting.

I hope this helps!

Best,

Adrian
Re: Using getValue(Stereotype, String) with Collections. Possible bug? [message #541112 is a reply to message #541072] Fri, 18 June 2010 11:58 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Adrian

There is now a patch for MDT/OCL 3.0.0 or CVS HEAD at
https://bugs.eclipse.org/bugs/show_bug.cgi?id=287052

This may allow you to do

self.getValue(self.getAppliedStereotype('Qualified::Name'),
'property')->flatten()->size() = 1

Let us know how you get on.

Regards

Ed Willink

On 18/06/2010 09:53, Adrián Noguero wrote:
>
> Many thanks Laurent, sadly I have to use plain OCL in my project. I'll
> try to figure out some other walkaround and if I find it I will post it
> here.
>
> Thanks again and best regards!
>
> Adrian
Re: Using getValue(Stereotype, String) with Collections. Possible bug? [message #543467 is a reply to message #540251] Tue, 29 June 2010 14:11 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 1
Registered: June 2010
Junior Member
Hi,

I have the same problem.

Laurent :
" However, if you're using OCL through Acceleo templates, you can delegate
the call to the UML EOperation by using a Java service which explicitely
returns a Collection.
"


Laurent could you describe how i can "solve" it with java service?

thanks

gaetan
Re: Using getValue(Stereotype, String) with Collections. Possible bug? [message #543728 is a reply to message #543467] Wed, 30 June 2010 12:28 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090600020101000605000800
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Gaetan,

This would be better asked on the m2t newsgroup :). The thing is :
Acceleo allows you to call for Java methods in addition to plain OCL.
OCL has the symptom of discarding any additional value from these
collections, Java doesn't. Do note that this only applies if you're
using Acceleo (generating code), not if you're using plain OCL (to write
constraints on your models for example).

In short, create a Java class (say "fr.sopragroup.UMLService") with method :

public List<Object> getTaggedValue(Element element, Stereotype
stereotype, String property) {
List<Object> result = new ArrayList<Object>();
Object value = element.getValue(stereotype, property);
if (value instanceof Collection) {
result.addAll((Collection)value);
else
result.add(value);
return result;
}

create an Acceleo query that will delegate to this method :

[query public getTaggedValue(Element element, Stereotype stereotype,
String property) : Sequence(OclAny) = invoke('fr.sopragroup.UMLService',
'getTaggedValue(org.eclipse.uml2.uml.Element,
org.eclipse.uml2.uml.Stereotype, java.lang.String)', Sequence{element,
stereotype, property})/]

(yes, pretty verbose. We have facilities to create these queries, look
at the included documentation for more information).

Then you can use "getTaggedValue(element, stereotype, property)" from
any Acceleo template or query to get the list of tagged values.

Laurent Goubet
Obeo

gruault@sopragroup.com wrote:
> Hi,
>
> I have the same problem.
>
> Laurent :
> " However, if you're using OCL through Acceleo templates, you can
> delegate the call to the UML EOperation by using a Java service which
> explicitely returns a Collection.
> "
>
> Laurent could you describe how i can "solve" it with java service?
>
> thanks
>
> gaetan


--------------090600020101000605000800
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=
--------------090600020101000605000800--
Re: Using getValue(Stereotype, String) with Collections. Possible bug? [message #1708674 is a reply to message #541110] Fri, 18 September 2015 14:39 Go to previous messageGo to next message
Salim CHEHIDA is currently offline Salim CHEHIDAFriend
Messages: 1
Registered: September 2015
Junior Member
Hi Adrian,
I have the same problem.
how you are used eCrossReferences() to formulate the OCL constraint?
are you have other solutions?
thanks
salim
Re: Using getValue(Stereotype, String) with Collections. Possible bug? [message #1708689 is a reply to message #1708674] Fri, 18 September 2015 18:15 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You are piggybacking on a five year old thread that reported a bug fix.
It is very unlikely that you have the same problem unless you are using
a five year old release; upgrade.

Your question has a typo in that makes it unintelligible.

The new PIvot-based OCL supports typesafe stereotype navigation without
using the tape-unsafe Java API.

Regards

Ed Willink


On 18/09/2015 16:49, Salim CHEHIDA wrote:
> Hi Adrian,
> I have the same problem.
> how you are used eCrossReferences() to formulate the OCL constraint?
> are you have other solutions?
> thanks
> salim
Previous Topic:OCLInECore standalone, Mars
Next Topic:Migrating code to OCL 3.5 (Eclipse 4.5)
Goto Forum:
  


Current Time: Wed Apr 24 23:50:31 GMT 2024

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

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

Back to the top