Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] How modular is the acceleo architecture?
[Acceleo] How modular is the acceleo architecture? [message #764432] Mon, 12 December 2011 06:59 Go to next message
Timothy Marc is currently offline Timothy MarcFriend
Messages: 547
Registered: July 2009
Senior Member
Hello all,

I'm quite familiar with Acceleo's capabilities of generating code from
models, so this question is rather dedicated to the architecture of Acceleo
itself, in particular to the customization capabilities of an Acceleo
module.

What I want to achieve is the following:

I have a main module that is devided into four templates:

1. Generate StartUp code
2. Generate configuration code
3. Generate application code
4. Generate TearDown code

Now, I want to provide extension points which are called during the
execution of those four templates by invoking an external function. The
extension point ID will be passed into the module as parameter (a user
wizard will be programmed that allows the user to select the respective
extension).

Executing a template would be similar to this pseudo-code:

[template xyz(extId : String)]
[access extension registry and load external module]
[start external module and pass current context object]
[/template]

The main question is: Is it possible to initialize deployed modules via the
extension point mechanism at runtime, and if not, is it possible to
implement kind of a template method pattern with Acceleo, where the concrete
and user-defined implementation of the template will be determined during
runtime (by pre-configuration in a previous wizard).

Hope, I made myself clear??

Thanks for any hint on this.

Timothy
Re: [Acceleo] How modular is the acceleo architecture? [message #765222 is a reply to message #764432] Tue, 13 December 2011 16:50 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4188
Registered: July 2009
Senior Member
Hi

Since the Acceleo guys aren't answering, my take is:

You are asking the wrong question.

How extensible is Java? well once you layer Eclipse extension points, it
is very extensible.

Acceleo is Turing complete, so you can layer any additional flexibility
that you like on top.

Regards

Ed Willink

On 11/12/2011 22:59, Timothy Marc wrote:
> Hello all,
>
> I'm quite familiar with Acceleo's capabilities of generating code from
> models, so this question is rather dedicated to the architecture of
> Acceleo itself, in particular to the customization capabilities of an
> Acceleo module.
>
> What I want to achieve is the following:
>
> I have a main module that is devided into four templates:
>
> 1. Generate StartUp code
> 2. Generate configuration code
> 3. Generate application code
> 4. Generate TearDown code
>
> Now, I want to provide extension points which are called during the
> execution of those four templates by invoking an external function.
> The extension point ID will be passed into the module as parameter (a
> user wizard will be programmed that allows the user to select the
> respective extension).
>
> Executing a template would be similar to this pseudo-code:
>
> [template xyz(extId : String)]
> [access extension registry and load external module]
> [start external module and pass current context object]
> [/template]
>
> The main question is: Is it possible to initialize deployed modules
> via the extension point mechanism at runtime, and if not, is it
> possible to implement kind of a template method pattern with Acceleo,
> where the concrete and user-defined implementation of the template
> will be determined during runtime (by pre-configuration in a previous
> wizard).
>
> Hope, I made myself clear??
>
> Thanks for any hint on this.
>
> Timothy
>
>
>
Re: [Acceleo] How modular is the acceleo architecture? [message #765657 is a reply to message #764432] Wed, 14 December 2011 13:23 Go to previous message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 413
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

First, I'll get back to your main concern:
Quote:
is it possible [...] with Acceleo, where the concrete and user-defined implementation of the template will be determined during runtime.


So what you want is to define a template but to have its concrete implementation determined during the runtime? Well, you can do it in Acceleo "out of the box" with the dynamic modules. you can create an Acceleo module (defined as dynamic thanks to the dedicated extension point) that contains templates that override other template that will be always used instead of the overridden template. Here is an example:

You have an Acceleo module "m1"

[module main(..)]
[import m1/]
[template mainTemplate(...)][t1(...)/][t2(...)/][/template]

[module m1 (...)]
[template t1(...)][/template]
[template t2(...)][/template]


You can create another Acceleo generator that depends on the first one (the first one doesn't know about this new generator) and in this new generator you extend the first module:

[module m2(...) extends m1]
[template t1(...) overrides t1][/template]


With this, the template m2::t1 will always be called instead of m1::t1, if you run main::mainTemplate again, m2::t1 will be used (since it's a dynamic template) even if the first module doesn't know about this other generator.

With this mechanism in Acceleo, you can build, for example, three other generators (with one dynamic module each in my case) like this:

[module m3 (...) extends m1]
[template t2(...) overrides t1 ? (getProperty('strategy') = 'first')][/template]


[module m4 (...) extends m1]
[template t2(...) overrides t1 ? (getProperty('strategy') = 'second')][/template]


[module m5 (...) extends m1]
[template t2(...) overrides t1 ? (getProperty('strategy') = 'third')][/template]


Then, you can use properties files to let the user choose the value associated with the key "strategy". If he uses "first", then among the dynamic templates, only m3::t2 can be called since only its guard will return true. If he uses "second", then only m4::t2 can be used and if he uses another value than "first" / "second" / "third" then there are no dynamic templates that can be executed since their guards will return false and in that case m1::t2 will be used. You could also use a value from the model in the guard instead of a property but with this mechanism, you can add new generators and thanks to the dynamic module extension point, you can give new generation options to your end user who will only have to manipulate (in this case) a properties file. This mechanism is used in the generators of the EEF project.

In order to do this, you may want to have a look at the documentation for dynamic modules (with a video) and the documentation for properties files to let your users use properties files to influence the generation.

Regards,

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau & @acceleo
Google+: stephane.begaudeau & acceleo
Blog: http://stephanebegaudeau.tumblr.com
Acceleo Documentation: http://docs.obeonetwork.com/acceleo





Previous Topic:[Acceleo] Start a module with a SET parameter
Next Topic:[Acceleo] Bug when accessing abstract UML metaclasses
Goto Forum:
  


Current Time: Sun Dec 21 10:47:55 GMT 2014

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

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