Home » Modeling » OCL » Using getValue(Stereotype, String) with Collections. Possible bug? (I can only manage to retrieve the first element of a collection)
|
Re: Using getValue(Stereotype, String) with Collections. Possible bug? [message #540321 is a reply to message #540251] |
Tue, 15 June 2010 15:40 |
|
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 #543728 is a reply to message #543467] |
Wed, 30 June 2010 12:28 |
|
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--
|
|
| | |
Goto Forum:
Current Time: Wed Apr 24 23:50:31 GMT 2024
Powered by FUDForum. Page generated in 0.03098 seconds
|