Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo 3] Calling MTL queries from java code
[Acceleo 3] Calling MTL queries from java code [message #558740] Tue, 14 September 2010 09:28 Go to next message
Cédric Vidal is currently offline Cédric VidalFriend
Messages: 101
Registered: July 2009
Senior Member
Hi Guys,

Is there some kind of helper similar to Xtend's XtendFacade which would
allow executing MTL queries defined in a MTL template file from Java
code ? Both standalone and under Eclipse.

Kind regards,

Cédric Vidal
Re: [Acceleo 3] Calling MTL queries from java code [message #558749 is a reply to message #558740] Tue, 14 September 2010 09:56 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.
--------------040509090200040502050303
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Hi C
Re: [Acceleo 3] Calling MTL queries from java code [message #558827 is a reply to message #558740] Tue, 14 September 2010 14:25 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.
--------------000702050506080706060504
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Hi Cedric,

copy/pasting the previous message as it seems the forum (
http://www.eclipse.org/forums/index.php?t=msg&th=175371& amp;start=0&S=65d6c539a6d9a8d86083c7deb9a9abb1
) doesn't support UTF-8 :p.


-----
The planned API only allows for clients to call Acceleo Templates, not
Queries; though I believe you should be able to mimic it in order to
call queries as well. Take a look at AcceleoService#doGenerate to see
how it's done ... don't hesitate to raise enhancement requests on the
bugzilla is the API isn't opened enough for you to call queries instead
of Templates :) .
-----


Laurent Goubet
Obeo

Cedric Vidal wrote:
> Hi Guys,
>
> Is there some kind of helper similar to Xtend's XtendFacade which would
> allow executing MTL queries defined in a MTL template file from Java
> code ? Both standalone and under Eclipse.
>
> Kind regards,
>
> C
Re: [Acceleo 3] Calling MTL queries from java code [message #559058 is a reply to message #558827] Wed, 15 September 2010 13:12 Go to previous messageGo to next message
Cédric Vidal is currently offline Cédric VidalFriend
Messages: 101
Registered: July 2009
Senior Member
Hi Laurent,

Thanx for your quick answer :)

I've had a look at AcceleoService and thanx to your explanation, I've
managed to execute a MTL query programmatically. Actually, it was pretty
easy as the syntax of MTL queries is actually directly parsed into OCL
Expressions and directly accessible in the MTL Ecore Metamodel.

So all I had to do was to mimic the doEvaluate method of AcceleoEngine
and transform the Query's OCL expression into an OCL Query and evaluate it.

But I had to fork AcceleoService and AcceleoEngine. The original code is
pretty dependent on the fact that files are being generated which is not
relevant when executing queries (and AcceleoService is a final class ;) ).

What's more, I have an issue with the cleaning up after execution. I
stopped there as I didn't have the time to investigate that problem.

Regarding the API, it would indead be great if Acceleo 3 supported that
use case. According to me, it's very important to be able to leverage
the set of MTL queries you've written into Java code. It allows creating
libraries of queries that you can reuse both in MTL templates and Java code.

Regarding how the API could look like, I guess the following additional
methods in AcceleoService could do the job (mine look alike):

public Object doQuery(Module module, String queryName, EObject model,
Monitor monitor);
public Object doQuery(Query query, EObject model, Monitor monitor);

Best regards,

Cédric Vidal

Le 14/09/2010 16:25, Laurent Goubet a écrit :
> Hi Cedric,
>
> copy/pasting the previous message as it seems the forum (
> http://www.eclipse.org/forums/index.php?t=msg&th=175371& amp;start=0&S=65d6c539a6d9a8d86083c7deb9a9abb1
> ) doesn't support UTF-8 :p.
>
>
> -----
> The planned API only allows for clients to call Acceleo Templates, not
> Queries; though I believe you should be able to mimic it in order to
> call queries as well. Take a look at AcceleoService#doGenerate to see
> how it's done ... don't hesitate to raise enhancement requests on the
> bugzilla is the API isn't opened enough for you to call queries instead
> of Templates :) .
> -----
>
>
> Laurent Goubet
> Obeo
>
> Cedric Vidal wrote:
>> Hi Guys,
>>
>> Is there some kind of helper similar to Xtend's XtendFacade which
>> would allow executing MTL queries defined in a MTL template file from
>> Java code ? Both standalone and under Eclipse.
>>
>> Kind regards,
>>
>> Cédric Vidal
>
Re: [Acceleo 3] Calling MTL queries from java code [message #559059 is a reply to message #559058] Wed, 15 September 2010 13:17 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.
--------------080203090906060309050204
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Hi Cedric,

Thanks for the follow-up, could you raise an enhancement request on the
bugzilla with the code you wrote (as a patch or directly in the
comments) regarding these "doQuery" methods? That'll allow me to know
exactly the needed use case and quickly get the grasp of what changes
are needed :).

Laurent Goubet
Obeo

C
Re: [Acceleo 3] Calling MTL queries from java code [message #559078 is a reply to message #559059] Wed, 15 September 2010 14:04 Go to previous message
Cédric Vidal is currently offline Cédric VidalFriend
Messages: 101
Registered: July 2009
Senior Member
You're welcome. I'll submit a patch as soon as I get a chance. Probably
by friday. I'll keep you posted.

Le 15/09/2010 15:17, Laurent Goubet a écrit :
> Hi Cedric,
>
> Thanks for the follow-up, could you raise an enhancement request on the
> bugzilla with the code you wrote (as a patch or directly in the
> comments) regarding these "doQuery" methods? That'll allow me to know
> exactly the needed use case and quickly get the grasp of what changes
> are needed :).
>
> Laurent Goubet
> Obeo
>
> Cédric Vidal wrote:
>> Hi Laurent,
>>
>> Thanx for your quick answer :)
>>
>> I've had a look at AcceleoService and thanx to your explanation, I've
>> managed to execute a MTL query programmatically. Actually, it was
>> pretty easy as the syntax of MTL queries is actually directly parsed
>> into OCL Expressions and directly accessible in the MTL Ecore Metamodel.
>>
>> So all I had to do was to mimic the doEvaluate method of AcceleoEngine
>> and transform the Query's OCL expression into an OCL Query and
>> evaluate it.
>>
>> But I had to fork AcceleoService and AcceleoEngine. The original code
>> is pretty dependent on the fact that files are being generated which
>> is not relevant when executing queries (and AcceleoService is a final
>> class ;) ).
>>
>> What's more, I have an issue with the cleaning up after execution. I
>> stopped there as I didn't have the time to investigate that problem.
>>
>> Regarding the API, it would indead be great if Acceleo 3 supported
>> that use case. According to me, it's very important to be able to
>> leverage the set of MTL queries you've written into Java code. It
>> allows creating libraries of queries that you can reuse both in MTL
>> templates and Java code.
>>
>> Regarding how the API could look like, I guess the following
>> additional methods in AcceleoService could do the job (mine look alike):
>>
>> public Object doQuery(Module module, String queryName, EObject model,
>> Monitor monitor);
>> public Object doQuery(Query query, EObject model, Monitor monitor);
>>
>> Best regards,
>>
>> Cédric Vidal
>>
>> Le 14/09/2010 16:25, Laurent Goubet a écrit :
>>> Hi Cedric,
>>>
>>> copy/pasting the previous message as it seems the forum (
>>> http://www.eclipse.org/forums/index.php?t=msg&th=175371& amp;start=0&S=65d6c539a6d9a8d86083c7deb9a9abb1
>>>
>>> ) doesn't support UTF-8 :p.
>>>
>>>
>>> -----
>>> The planned API only allows for clients to call Acceleo Templates, not
>>> Queries; though I believe you should be able to mimic it in order to
>>> call queries as well. Take a look at AcceleoService#doGenerate to see
>>> how it's done ... don't hesitate to raise enhancement requests on the
>>> bugzilla is the API isn't opened enough for you to call queries instead
>>> of Templates :) .
>>> -----
>>>
>>>
>>> Laurent Goubet
>>> Obeo
>>>
>>> Cedric Vidal wrote:
>>>> Hi Guys,
>>>>
>>>> Is there some kind of helper similar to Xtend's XtendFacade which
>>>> would allow executing MTL queries defined in a MTL template file from
>>>> Java code ? Both standalone and under Eclipse.
>>>>
>>>> Kind regards,
>>>>
>>>> Cédric Vidal
>>>
>>
>
Previous Topic:Toolchain for source code generation from UML?
Next Topic:[xpand] problem calling xpand from Java
Goto Forum:
  


Current Time: Tue Mar 19 09:05:12 GMT 2024

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

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

Back to the top