Defining package from workflow [message #522870] |
Wed, 24 March 2010 09:42 |
MaximeLecourt Messages: 108 Registered: February 2010 Location: France |
Senior Member |
|
|
I defined a Model, and now I'm trying to generate JAVA code from it.
I need to be able to define in the workflow which class goes in which package, and I can't define the package name in the model (my model needs to be free of any language consideration, as I will have to generate Python, C++, and maybe other languages).
Eclipse Xpand Documentation writes about a Template AOP example, which I havn't been able to find. The workflow documentation writes about join points or wildcards, but I can't find examples for either.
My template looks like this
«DEFINE main(String package) FOR Package»
where String package is the name of the package, and is a variable defined in the workflow.
<property name="package" value="mypackage"/>
Is there a way to make some kind of table, that would change the value of the property package, depending on the class name ? Or any other way to define what class goes in what package, when the user has only access to the workflow ?
One day I shall master M2T, but that day has yet to come...
|
|
|
|
Re: Defining package from workflow [message #522919 is a reply to message #522870] |
Wed, 24 March 2010 14:19 |
MaximeLecourt Messages: 108 Registered: February 2010 Location: France |
Senior Member |
|
|
Do you mean introducing a "Namespace" in my metamodel ?
If it's that, I can't, as it's language-related.
The point is to create a model that may be translated in any langage, so I can't use anything that is langage specific.
The package definition can't possibly be in the model.
One day I shall master M2T, but that day has yet to come...
[Updated on: Wed, 24 March 2010 14:20] Report message to a moderator
|
|
|
|
|
|
|
Re: Defining package from workflow [message #526203 is a reply to message #522870] |
Fri, 09 April 2010 08:45 |
MaximeLecourt Messages: 108 Registered: February 2010 Location: France |
Senior Member |
|
|
I'm thinking of two different ways to define the package name outside the metamodel.
First would be using properties.
<property name="package">
<class='Company' value='company'>
<class='Site' value='company'>
<class='User' value='group'>
<class='Group' value='group'>
</property>
Then i'd invoke the workflow with
<expand
value="template::Template::main('${package}') FOR something" />
But in my Xpand template,
«EXPAND javaObject::javaClass(package) FOREACH classes()»
How do I match my classes() instance name with package.class ?
Is there a way to export an xml file from Xtend ?
That way I could define a javapackage() function, that would match a parameter (the class name in model) with class from xml file, and return the value ?
Another way would be invoke the workflow from JAVA, and having the properties as a parameter from run method.
String file = "./workflow/company.mwe";
Map<String, String> properties = new HashMap<String, String>();
Map<String, ?> slotContents = new HashMap();
properties.put("Company", "company");
properties.put("Site", "company");
properties.put("User", "user");
properties.put("Group", "user");
new WorkflowRunner().run(file, new NullProgressMonitor(),properties,slotContents);
But this time, how can use all the properties as parameter to my workflow ? So that way whenever the Xpand template is called for a Type whose name is in my properties, I can get the property value.
One day I shall master M2T, but that day has yet to come...
|
|
|
|
|
Re: Defining package from workflow [message #526658 is a reply to message #522870] |
Mon, 12 April 2010 14:15 |
MaximeLecourt Messages: 108 Registered: February 2010 Location: France |
Senior Member |
|
|
Now I do.
The help only states
Quote: | FILE
The FILE statement redirects the output generated from its body statements to the specified target.
«FILE expression [outletName]»
a sequence of statements
«ENDFILE»
The target is a file in the file system whose name is specified by the expression (relative to the specified target directory for that generator run). The expression for the target specification can be a concatenation (using the + operator). Additionally, you can specify an identifier (a legal Java identifier) for the name of the outlet. (See the configuration section for a description of outlets).
The body of a FILE statement can contain any other statements. Example:
«FILE InterfaceName + ".java"»
package «InterfacePackageName»;
/* generated class! Do not modify! */
public interface «InterfaceName» {
«EXPAND Operation::InterfaceImplementation FOREACH Operation»
}
«ENDFILE»
«FILE ImplName + ".java" MY_OUTLET»
package «ImplPackageName»;
public class «ImplName» extends «ImplBaseName»
implements «InterfaceName» {
//TODO: implement it
}
«ENDFILE»
|
Thank you (again)
Maxime
One day I shall master M2T, but that day has yet to come...
|
|
|
Powered by
FUDForum. Page generated in 0.02350 seconds