Home » Modeling » M2T (model-to-text transformation) » [Acceleo 3 / MTL] Problems when wrapping java methods in MTL
[Acceleo 3 / MTL] Problems when wrapping java methods in MTL [message #633081] |
Fri, 15 October 2010 10:12 |
Emilio Salazar Messages: 9 Registered: October 2009 |
Junior Member |
|
|
Dear all,
I want to call a java method from my MTL code. Therefore, I've used the Acceleo 3 wizard to generate the MTL's wrapper. Nevertheless, the generated MTL wrapper doesn't compiles.
The java method specification which I need to call is:
public static Object getNestedValue (Element self, List<String> NameValues)
and the MTL wrapper generated by the wizard is:
[query public getNestedValue(arg0 : Element, arg1 : Sequence(OclAny)) : OclAny
= invoke('Reflexion.Debug', 'getNestedValue(org.eclipse.uml2.uml.Element, java.util.List)', Sequence{arg0, arg1}) /]
As it's said before, the problem is that this wrapper doesn't compiles. I get the next error:
Type mismatch. No common supertype: (Element), (Sequence(OclAny)) debug.mtl /org.eclipse.acceleo.module.sample/src/org/eclipse/acceleo/m odule/sample/files line 7 Acceleo Problem
I think that the problem is that "java.util.List" doesn't match with the MTL's Sequence (in this case, of strings) type. But I were not able to discover which java type matches with Sequence type.
So, I'm a bit confusing. Any help will be welcome.
Thank you in advance.
Regards,
Emilio.
|
|
|
Re: [Acceleo 3 / MTL] Problems when wrapping java methods in MTL [message #633098 is a reply to message #633081] |
Fri, 15 October 2010 11:04 |
|
This is a multi-part message in MIME format.
--------------040104050507070604010009
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Hi Emilio,
The problem you have is that OCL doesn't allow for a Sequence containing
an element and a list, Sequence{'a', 'z', 'e'} is valid, but
Sequence{'a', Sequence{'z', 'e'}} is not.
As such, it is currently impossible to call, from Acceleo, Java services
which take a collection as parameter. This is a known limitation which
we have little options to try and circumvent. Do you really need a list
as parameter, or can you workaround this limitation by calling the
service multiple times (one for each of your list's content)?
Laurent Goubet
Obeo
Emilio Salazar wrote:
> Dear all,
>
> I want to call a java method from my MTL code. Therefore, I've used the
> Acceleo 3 wizard to generate the MTL's wrapper. Nevertheless, the
> generated MTL wrapper doesn't compiles.
>
> The java method specification which I need to call is:
>
> public static Object getNestedValue (Element self, List<String> NameValues)
>
> and the MTL wrapper generated by the wizard is:
>
> [query public getNestedValue(arg0 : Element, arg1 : Sequence(OclAny)) :
> OclAny
> = invoke('Reflexion.Debug',
> 'getNestedValue(org.eclipse.uml2.uml.Element, java.util.List)',
> Sequence{arg0, arg1}) /]
>
> As it's said before, the problem is that this wrapper doesn't compiles.
> I get the next error:
>
> Type mismatch. No common supertype: (Element), (Sequence(OclAny))
> debug.mtl
> /org.eclipse.acceleo.module.sample/src/org/eclipse/acceleo/m
> odule/sample/files line 7 Acceleo Problem
>
> I think that the problem is that "java.util.List" doesn't match with
> the MTL's Sequence (in this case, of strings) type. But I were not able
> to discover which java type matches with Sequence type.
> So, I'm a bit confusing. Any help will be welcome.
>
> Thank you in advance.
>
> Regards,
> Emilio.
>
--------------040104050507070604010009
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=
--------------040104050507070604010009--
|
|
| |
Re: [Acceleo 3 / MTL] Problems when wrapping java methods in MTL [message #633142 is a reply to message #633098] |
Fri, 15 October 2010 13:48 |
Ed Willink Messages: 7671 Registered: July 2009 |
Senior Member |
|
|
Hi Emilio, Laurent
> The problem you have is that OCL doesn't allow for a Sequence
> containing an element and a list, Sequence{'a', 'z', 'e'} is valid,
> but Sequence{'a', Sequence{'z', 'e'}} is not.
This is true of OMG OCL 2.0 and MDT/OCL 3.0.
OCL 2.2 changed Collection to conform to OclAny, so the above is valid
in OCL 2.2, which hopefully will be supported by MDT/OCL 3.1.
Regards
Ed Willink
|
|
|
Re: [Acceleo 3 / MTL] Problems when wrapping java methods in MTL [message #639840 is a reply to message #633142] |
Thu, 18 November 2010 04:54 |
Sergio Messages: 21 Registered: August 2010 Location: Cardedeu |
Junior Member |
|
|
thank you very much for your help!!!
I was trying to do some workaround, and at the end I saw what was making me noise all the time.
In fact, this is what I can't understand:
[for (a : Association | class.getAssociations() )]
[numberOfRelations(a, class.name)/]
[if (numberOfRelations(a, class.name)>0)]
inside
[/if]
[/for]
where:
[query public numberOfRelations(a : Association, sourceClass : String) : Integer = a.ownedElement->asSequence().oclAsType(Property)->select(type.name.equalsIgnoreCase(sourceClass))->upper.oclAsType(Integer) /]
and this is the output:
So, I have to believe that my query "numberOfRelations" is returning some integer (1,1,2) but if I what to use the result as a number... I can't!, so this operation fails: if (numberOfRelations(a, class.name)>0)]
And If I try:
[query public numberOfRelations(a : Association, sourceClass : String) : Integer = 2 /]
then this is the output:
2
inside
2
inside
2
inside
so, Why this can't be treated as an Integer?:
[query public [B]numberOfRelations[/B](a : Association, sourceClass : String) : Integer = a.ownedElement->asSequence().oclAsType(Property)->select(type.name.equalsIgnoreCase(sourceClass))->upper/]
Thank you!!!
Sergio Sacristán
http://s2o-bcn.blogspot.com/
|
|
|
Re: [Acceleo 3 / MTL] Problems when wrapping java methods in MTL [message #639859 is a reply to message #633081] |
Thu, 18 November 2010 07:54 |
|
Hi Sergio,
The problem is that your first query does not return an integer but a collection of one integer. We have a bug about queries, we don't check the type of the returned value and the type of the query, so even if you could expect this query to return an integer, it won't.
"a.ownedElement" is a collection
"a.ownedElement->asSequence()" still a collection
"a.ownedElement->asSequence().oclAsType(Property)" again, still a collection
"a.ownedElement->asSequence().oclAsType(Property)->select(type.name.equalsIgnoreCase(sourceClass)) " always a collection
"a.ownedElement->asSequence().oclAsType(Property)->select(type.name.equalsIgnoreCase(sourceClass))- >upper.oclAsType(Integer)" and finally a collection
You can add a "->first()" to get the value since there seems to be only one integer in this collection.
Stephane Begaudeau, Obeo
[Updated on: Thu, 18 November 2010 07:54] Report message to a moderator
|
|
| | |
Goto Forum:
Current Time: Thu Sep 26 12:38:01 GMT 2024
Powered by FUDForum. Page generated in 0.04124 seconds
|