Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Launching java services from a .mtl file
[Acceleo] Launching java services from a .mtl file [message #537355] Wed, 02 June 2010 07:38 Go to next message
Daniel  is currently offline Daniel Friend
Messages: 44
Registered: June 2010
Member
Hi all and thank you for your help.

This doubt may seem very simple but I would like you to help me.
In Acceleo 2.7 when you wanted to use a java service you only had to import it:

import org.acceleo.module.pim.uml21.gen.java.services.Common

That way you could use the Common.java services.

How do I do this in Acceleo 3 using .mtls?

Thank you very much.
Re: [Acceleo] Launching java services from a .mtl file [message #537361 is a reply to message #537355] Wed, 02 June 2010 08:13 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.
--------------080405000705050608080103
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Daniel,

Acceleo 3.0 is a little more permissive as to the services that can be
called, though the tooling isn't as polished as it was in Acceleo 2.x.

For example, to use the method "EcoreUtil#getRootContainer(EObject)" as
a Java service in Acceleo 3, you need to use :

[invoke('org.eclipse.emf.ecore.util.EcoreUtil',
'getRootContainer(org.eclipse.emf.ecore.EObject)', Sequence{eObject})/]

Take a look at the integrated help for the service wrappers and other
tooling we provide for the Java services. This particular point of the
documentation is located in the Acceleo User Guide, in the section
"Wrapping Java Services". All documentation is accessible through the
menu Help=>Help Contents, in the "Acceleo Model To Text" section.

Laurent Goubet
Obeo

Daniel wrote:
> Hi all and thank you for your help.
>
> This doubt may seem very simple but I would like you to help me.
> In Acceleo 2.7 when you wanted to use a java service you only had to
> import it:
>
> import org.acceleo.module.pim.uml21.gen.java.services.Common
>
> That way you could use the Common.java services.
>
> How do I do this in Acceleo 3 using .mtls?
>
> Thank you very much.


--------------080405000705050608080103
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=
--------------080405000705050608080103--
Re: [Acceleo] Launching java services from a .mtl file [message #537386 is a reply to message #537361] Wed, 02 June 2010 09:34 Go to previous messageGo to next message
Daniel  is currently offline Daniel Friend
Messages: 44
Registered: June 2010
Member
Thank you very much, I'm going to try it.
Re: [Acceleo] Launching java services from a .mtl file [message #537465 is a reply to message #537386] Wed, 02 June 2010 14:30 Go to previous messageGo to next message
Daniel  is currently offline Daniel Friend
Messages: 44
Registered: June 2010
Member
Hi again, I am trying but I am having some trouble.

1.

I am using the wizard to create templates with querys to my java modules but I get errors and I dont know exactly how invoke goes. I mean I have a Java file with:

public class Common {

public String addQuote(String value) {......

It creates me:
[query public addQuote(arg0 : String) : String
= invoke('org.acceleo.module.pim.uml21.gen.java.services.Commo n', 'addQuote(java.lang.String)', Sequence{arg0}) /]

Ok so the invoke goes like this:
invoke('path to file', 'method(parameters)', ??? )

What is the third parameter? I mean suppos I want to use this service in a class.name, how would I do that?
I think if I do it with the query it would be :
[addQuote(class.name)]

but I dont know if the way to do it would be:
[class.name.addQuote()]

Ok, and also if I dont want to use the query and I want to use invoke directly how would it be?
invoke('org.acceleo.module.pim.uml21.gen.java.services.Commo n', 'addQuote(java.lang.String)', Sequence{class.name}) /]

?????

2.
Thats one problem, the other problems are that some of the generated querys are incorrect, for example in Acceleo 2.7 I used:

import org.eclipse.uml2.uml.Classifier;

public class Service {
public Classifier[] hasName(Classifier cl){ .....

And the generated query is:
[query public hasName(arg0 : Classifier) : Classifier;
= invoke('org.acceleo.module.pim.uml21.gen.java.services.Servi ce', 'hasName(org.eclipse.uml2.uml.Classifier)', Sequence{arg0}) /]
But there is an error:

"Invalid Type: Classifier"

How do I fix this?

3.

Finally my other problem is that I used a java services file which used this packages:
import fr.obeo.acceleo.gen.template.eval.ENode;
import fr.obeo.acceleo.tools.AcceleoToolsPlugin;

Which are from Acceleo 2.7, and now, having installed the 3.0.0 version it produces errors. What should I do? Import the packages from Acceleo 2.7 or is there any equivalent in 3.0.0?

Thank you very much.

Re: [Acceleo] Launching java services from a .mtl file [message #537486 is a reply to message #537465] Wed, 02 June 2010 15:21 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.
--------------080500060407040406050103
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Daniel,

See my comments inlined below.

Laurent Goubet
Obeo

Daniel wrote:
> Hi again, I am trying but I am having some trouble.
>
> 1.
>
> I am using the wizard to create templates with querys to my java modules
> but I get errors and I dont know exactly how invoke goes. I mean I have
> a Java file with:
>
> public class Common {
>
> public String addQuote(String value) {......
>
> It creates me:
> [query public addQuote(arg0 : String) : String
> = invoke('org.acceleo.module.pim.uml21.gen.java.services.Commo n',
> 'addQuote(java.lang.String)', Sequence{arg0}) /]

Yup, the query is good.

>
> Ok so the invoke goes like this:
> invoke('path to file', 'method(parameters)', ??? )

The third parameter of the "invoke" service is a Sequence containing all
of the arguments of your own service. If your service is "test(String,
String)" you pass a Sequence containing two Strings to the invoke service.

>
> What is the third parameter? I mean suppos I want to use this service in
> a class.name, how would I do that?
> I think if I do it with the query it would be :
> [addQuote(class.name)]
> but I dont know if the way to do it would be:
> [class.name.addQuote()]

Both are okay. addQuote(class.name) is MTL's way, class.name.addQuote()
is more of an Acceleo way. We decided to allow both of these in our
implementation as the MTL specification doesn't forbid the second, and
we think it is easier.

>
> Ok, and also if I dont want to use the query and I want to use invoke
> directly how would it be?
> invoke('org.acceleo.module.pim.uml21.gen.java.services.Commo n',
> 'addQuote(java.lang.String)', Sequence{class.name}) /]
>
> ?????

Yep, that's it. The wrapper query only makes it easier to isolate calls
to a given Java service, and makes reading the template easier.

I for one would rather read
[class.name.addQuote().replace('test', 'thing')/]
instead of
[invoke('org.acceleo.module.pim.uml21.gen.java.services.Comm on'
'addQuote(java.lang.String)', Sequence{class.name}).replace('test',
'thing')/]

>
> 2.
> Thats one problem, the other problems are that some of the generated
> querys are incorrect, for example in Acceleo 2.7 I used:
>
> import org.eclipse.uml2.uml.Classifier;
>
> public class Service {
> public Classifier[] hasName(Classifier cl){ .....
>
> And the generated query is:
> [query public hasName(arg0 : Classifier) : Classifier;
> = invoke('org.acceleo.module.pim.uml21.gen.java.services.Servi ce',
> 'hasName(org.eclipse.uml2.uml.Classifier)', Sequence{arg0}) /]
> But there is an error:
>
> "Invalid Type: Classifier"
> How do I fix this?

This would mean you haven't imported the UML model in the module header
of that query : [module test('<UML metamodel URI>')].

You do know you can now call EOperations directly from the generation
module instead of using Java services for each call? For example you can
use [classifier.hasValue(stereotype, 'value')/] directly... don't know
if this help in this particular case.

>
> 3.
>
> Finally my other problem is that I used a java services file which used
> this packages:
> import fr.obeo.acceleo.gen.template.eval.ENode;
> import fr.obeo.acceleo.tools.AcceleoToolsPlugin;
>
> Which are from Acceleo 2.7, and now, having installed the 3.0.0 version
> it produces errors. What should I do? Import the packages from Acceleo
> 2.7 or is there any equivalent in 3.0.0?

I don't know why you used both of these classes in your Java service,
but they no longer exist in Acceleo 3.0. You could import the package
from Acceleo 2... but that would serve no purpose since you'll never get
elements of type "ENode" in Acceleo 3.

You should look at the java method making use of these classes and see
if they are useful. You'll most likely end up removing the references
altogether, but don't hesitate to come back to us if you can't find a
way to work around these imports.

>
> Thank you very much.
>
>


--------------080500060407040406050103
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=
--------------080500060407040406050103--
Re: [Acceleo] Launching java services from a .mtl file [message #538190 is a reply to message #537486] Sun, 06 June 2010 09:21 Go to previous messageGo to next message
Daniel  is currently offline Daniel Friend
Messages: 44
Registered: June 2010
Member
Hi again and thank you for your help, you have solved me a lot of problems Very Happy

Nevertheless I still have doubts about point 2:

2-

I generated this module:

[module service('http://www.eclipse.org/uml2/2.1.0/UML')/]

[query public hasName(arg0 : Classifier) : Classifier;
= invoke('org.acceleo.module.pim.uml21.gen.java.services.Servi ce', 'hasName(org.eclipse.uml2.uml.Classifier)', Sequence{arg0}) /]

So I am importing the metamodel but it stills tells me:

"Invalid type: Classifier"

This is the beginning of the Java class:

package org.acceleo.module.pim.uml21.gen.java.services;

import org.eclipse.uml2.uml.Operation;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Interface;
import org.eclipse.uml2.uml.Classifier;


public class Service {
public Classifier[] hasName(Classifier cl){....


I thought that using the org.eclipse.uml2.uml it would be enough importing 'http://www.eclipse.org/uml2/2.1.0/UML' in the module.

Also when I use the method "hasName" it doesnt really do anything about "hasName", its only a bad name. The service does things that I cant solve using EOperations.

3-

I was trying to migrate an Acceleo 2 module that used a service which imported:

> import fr.obeo.acceleo.gen.template.eval.ENode;
> import fr.obeo.acceleo.tools.AcceleoToolsPlugin;

Thats why I used them, so I would try to figure out how can I migrate it without using them.

Thank you very much again!
Re: [Acceleo] Launching java services from a .mtl file [message #538297 is a reply to message #538190] Mon, 07 June 2010 08:18 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.
--------------040405080606030200000007
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Daniel,

2- Is the ';' behind "Classifier" a generated character? There shouldn't
be anything between the return type of the query and the "=" character.
This should be :

[query public hasName(arg0 : Classifier) : Classifier =
invoke('org.acceleo.module.pim.uml21.gen.java.services.Servi ce',
'hasName(org.eclipse.uml2.uml.Classifier)', Sequence{arg0}) /]

If that doesn't do the trick, does qualifying the types help? (Replacing
"Classifier" with "uml::Classifier".)

3- I know some of the Acceleo 2 services used those ... but they were
internal of the tool and thus have no equivalent in Acceleo 3. Please
let us know if you don't manage to port equivalent services.

Laurent Goubet
Obeo

Daniel wrote:
> Hi again and thank you for your help, you have solved me a lot of
> problems :d
>
> Nevertheless I still have doubts about point 2:
>
> 2-
>
> I generated this module:
>
> [module service('http://www.eclipse.org/uml2/2.1.0/UML')/]
>
> [query public hasName(arg0 : Classifier) : Classifier;
> = invoke('org.acceleo.module.pim.uml21.gen.java.services.Servi ce',
> 'hasName(org.eclipse.uml2.uml.Classifier)', Sequence{arg0}) /]
>
> So I am importing the metamodel but it stills tells me:
>
> "Invalid type: Classifier"
>
> This is the beginning of the Java class:
>
> package org.acceleo.module.pim.uml21.gen.java.services;
>
> import org.eclipse.uml2.uml.Operation;
> import org.eclipse.uml2.uml.Class;
> import org.eclipse.uml2.uml.Interface;
> import org.eclipse.uml2.uml.Classifier;
>
>
> public class Service {
> public Classifier[] hasName(Classifier cl){....
>
>
> I thought that using the org.eclipse.uml2.uml it would be enough
> importing 'http://www.eclipse.org/uml2/2.1.0/UML' in the module.
>
> Also when I use the method "hasName" it doesnt really do anything about
> "hasName", its only a bad name. The service does things that I cant
> solve using EOperations.
>
> 3-
>
> I was trying to migrate an Acceleo 2 module that used a service which
> imported:
>
>> import fr.obeo.acceleo.gen.template.eval.ENode;
>> import fr.obeo.acceleo.tools.AcceleoToolsPlugin;
>
> Thats why I used them, so I would try to figure out how can I migrate it
> without using them.
>
> Thank you very much again!


--------------040405080606030200000007
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=
--------------040405080606030200000007--
Re: [Acceleo] Launching java services from a .mtl file [message #538745 is a reply to message #538297] Tue, 08 June 2010 14:22 Go to previous messageGo to next message
Daniel  is currently offline Daniel Friend
Messages: 44
Registered: June 2010
Member
Hi!

Thank you very much, removing the ; worked.

Also I dont know why but I checked it and the ";" in Classifier; was indeed automatically generated.

Thank your!
Re: [Acceleo] Launching java services from a .mtl file [message #538781 is a reply to message #538745] Tue, 08 June 2010 15:30 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.
--------------000807060101030909090008
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Then it's a bug with the generated file :'(. Could you raise a bugzilla
against m2t/Acceleo with this?

Thanks

Laurent Goubet
Obeo

Daniel wrote:
> Hi!
>
> Thank you very much, removing the ; worked.
>
> Also I dont know why but I checked it and the ";" in Classifier; was
> indeed automatically generated.
>
> Thank your!


--------------000807060101030909090008
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=
--------------000807060101030909090008--
Re: [Acceleo] Launching java services from a .mtl file [message #538853 is a reply to message #538781] Tue, 08 June 2010 19:32 Go to previous messageGo to next message
Daniel  is currently offline Daniel Friend
Messages: 44
Registered: June 2010
Member
I'm sorry but I hadnt use bugzilla before, how can I do it?
Re: [Acceleo] Launching java services from a .mtl file [message #538949 is a reply to message #538853] Wed, 09 June 2010 07:26 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.
--------------030409060307020008090106
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Daniel,

The eclipse bugzilla can be found on https://bugs.eclipse.org/bugs/

1) you need to create a bugzilla account if you don't have one
(https://bugs.eclipse.org/bugs/createaccount.cgi)
2) navigate to file a new bug => modeling => M2T => select 'Acceleo' as
the component (alternative : just click
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=M2T& component=Acceleo
:p)
3) fill in the summary and description of your bug

Laurent Goubet
Obeo

Daniel wrote:
> I'm sorry but I hadnt use bugzilla before, how can I do it?


--------------030409060307020008090106
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=
--------------030409060307020008090106--
Re: [Acceleo] Launching java services from a .mtl file [message #539196 is a reply to message #538949] Wed, 09 June 2010 21:59 Go to previous message
Daniel  is currently offline Daniel Friend
Messages: 44
Registered: June 2010
Member
Done, thank you for the help with bugzilla!
Previous Topic:[Acceleo] Main
Next Topic:[Announce] Share the Worldcup 2010 experience with the Eclipse Modeling Community !
Goto Forum:
  


Current Time: Tue Dec 23 00:51:29 GMT 2014

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

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