Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Emilio Salazar is currently offline Emilio SalazarFriend
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 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.
--------------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 #633102 is a reply to message #633098] Fri, 15 October 2010 11:48 Go to previous messageGo to next message
Emilio Salazar is currently offline Emilio SalazarFriend
Messages: 9
Registered: October 2009
Junior Member
Hi Laurent,

First, thank you for so fast answer.

OK, I didn't know this limitation of OCL.

Fortunately, I think that I can workaround this limitation by calling the java method multiple times.

Thank you again.

Regards,
Emilio.
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 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4188
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 Go to previous messageGo to next message
Sergio  is currently offline Sergio Friend
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:
	1
	1
	2


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 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 413
Registered: April 2010
Location: Nantes (France)
Senior Member

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 Smile

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

Re: [Acceleo 3 / MTL] Problems when wrapping java methods in MTL [message #640064 is a reply to message #639859] Thu, 18 November 2010 21:42 Go to previous messageGo to next message
Sergio  is currently offline Sergio Friend
Messages: 21
Registered: August 2010
Location: Cardedeu
Junior Member
great! thank you!!


Sergio Sacristán
http://s2o-bcn.blogspot.com/
Re: [Acceleo 3 / MTL] Problems when wrapping java methods in MTL [message #870736 is a reply to message #640064] Wed, 09 May 2012 13:42 Go to previous message
ibrahim kara is currently offline ibrahim karaFriend
Messages: 10
Registered: May 2012
Junior Member
Hi,

I am merging a plug-in written in Acceleo 2 to the new version Acceleo 3. In the old plug-in there are several calls to some java services with collection parameters. When I try to pass a collection to a Java service, I receive errors. I would like to know if it is possible to pass a collection from a template to a Java service as a parameter?

Thanks in advance.
Previous Topic:Trying to load UTP 1.1 (xmi from OMG)
Next Topic:[Acceleo] Determining whether a modeling element is extended by some stereotype in a hierarchy
Goto Forum:
  


Current Time: Sat Dec 20 21:45:03 GMT 2014

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

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