Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [acceleo] best way to pass extra data from Java to template ?
[acceleo] best way to pass extra data from Java to template ? [message #805035] Thu, 23 February 2012 09:09 Go to next message
Marc Missing name is currently offline Marc Missing nameFriend
Messages: 38
Registered: March 2011

I have a compiler that uses acceleo for its backend part. Currently, all data given to the templates from the java code are parameters of templates. Problem is that when I want to drive a nested template from my java code, I need to change all intermediate templates to have the needed extra parameter. This is ok for q&d prototype, but clearly not a good idea for the longterm Smile

What would be the best choice ?

Using properties is an option, but AFAIK, acceleo has support for loading properties from a file. I would need first to write my properties to a file and then load it from acceleo... Or I could extend property handling in acceleo.

I could also use a "java service" to query global properties.

Are there any other option ? What would you recommend ?

Re: [acceleo] best way to pass extra data from Java to template ? [message #805202 is a reply to message #805035] Thu, 23 February 2012 13:32 Go to previous message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member


I'm not sure I understood your need perfectly but the Acceleo properties files APIs let you load properties directly thanks to a "java.util.Properties". For that, have a look at the method "getPropertiesLoaderService(...)" in the generated Java launcher and look at "alternatePropertiesLoading(String)". This operation will receive the "id" of the properties files that you have registered in the getProperties(...) operation in the generated Java launcher and with this "id" it will look for the ".properties" file and load its content in a java.util.Properties object. You can plug your code here to load programmatically a java.util.Properties object without having any ".properties" file on your file system.


Stephane Begaudeau, Obeo

Twitter: @sbegaudeau & @acceleo
Google+: stephane.begaudeau & acceleo
Acceleo Documentation:
Previous Topic:JET presentations not accesible?
Next Topic:[XPand2] setting local variables
Goto Forum:

Current Time: Wed Dec 06 05:26:56 GMT 2023

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

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

Back to the top