Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Defining package from workflow(generating JAVA)
Defining package from workflow [message #522870] Wed, 24 March 2010 09:42 Go to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
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 #522874 is a reply to message #522870] Wed, 24 March 2010 09:57 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
What do you think of introducing the concept of a 'Namespace'. This namespace can be translated into different target languages (e.g. Java -> Packages) and every class is placed into a namespace.
Inside the workflow you would define a property targetLanguage.
The fully qualified name consists of the translated namespace and the name.
Re: Defining package from workflow [message #522919 is a reply to message #522870] Wed, 24 March 2010 14:19 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
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 #522968 is a reply to message #522919] Wed, 24 March 2010 16:18 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
Hello Maxime

Maxime Lecourt wrote on Wed, 24 March 2010 15:19
Do you mean introducing a "Namespace" in my metamodel ?


Yes.
Quote:

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.

I think of namespaces as abstract concept.
Every language defines namespaces. If your metamodell knows the concept 'class' it should also know the concept 'namespace'.
Isn't the concept of a namespace o more general concept as class?

Another possibility is to transform the PIM into a PSM adding an annotation model defining the Java=package or C++=namespace or Phython=namespace information. But then you have to check, if an annotation for every class exists.
I would implement it as extension name(). The extension calls a Java method. Inside Java you can use a HashMap (the table you wanted?).
AOP can be used to change the implementation of the name() extension for different target languages.

Regards
Darius
Re: Defining package from workflow [message #523139 is a reply to message #522870] Thu, 25 March 2010 09:50 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
Do you know where I could fins some documentation on what you call an "annotation model" ? I couldn't find what it is, either in Eclipse documentation or on internet.

By extension, you mean Xtend extension ? (Eclipse Doc : An EXTENSION import points to the Xtend file containing the required extensions)

It's what I'm searching, but I'd like to use it through the workflow.

The only thing my users should be able to modify is the workflow. So they are not to use Xtend or Xpand.
Is it possible, and how ?


One day I shall master M2T, but that day has yet to come...
Re: Defining package from workflow [message #523162 is a reply to message #523139] Thu, 25 March 2010 12:11 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
Maxime Lecourt wrote on Thu, 25 March 2010 10:50

Do you know where I could fins some documentation on what you call an "annotation model" ? I couldn't find what it is, either in Eclipse documentation or on internet.


I mean something like a MDA marked model.
See MDA Guide: http://www.omg.org/cgi-bin/doc?omg/03-06-01
Chapter 3.10.1 Marking.

Quote:

By extension, you mean Xtend extension ?


Oh sorry. Yes I mean an Xtend extension. I allways speak of an extension because it is shorter Smile

Quote:

It's what I'm searching, but I'd like to use it through the workflow.
The only thing my users should be able to modify is the workflow. So they are not to use Xtend or Xpand.
Is it possible, and how ?


You mean the Java approach using a HashMap?
In this case you are free to implement any strategy to parse a model.
A model could be a simple property [key=value] file, to fill the HashMap.

Regards
Darius

[Updated on: Thu, 25 March 2010 12:13]

Report message to a moderator

Re: Defining package from workflow [message #523449 is a reply to message #522870] Fri, 26 March 2010 14:07 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
I'm thinking about another approach for some of thoses specific points.

I'm thinking about using two metamodels.
One would be my "generic" metamodel, and another would be a langage-specific metamodel, which I would use only to add the points that are present in one language and not in the others.

From what I've read on the forum, it's possible, as long as my templates are in separate files.

Regards,

maxime


One day I shall master M2T, but that day has yet to come...
Re: Defining package from workflow [message #526203 is a reply to message #522870] Fri, 09 April 2010 08:45 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
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 #526629 is a reply to message #522874] Mon, 12 April 2010 13:19 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
Darius Jockel wrote on Wed, 24 March 2010 10:57
What do you think of introducing the concept of a 'Namespace'. This namespace can be translated into different target languages (e.g. Java -> Packages) and every class is placed into a namespace.
Inside the workflow you would define a property targetLanguage.
The fully qualified name consists of the translated namespace and the name.



Instead of using a namespace, I called a JAVA method.
But as the workflow is already running, the outlet writing path is already defined. So I can define my package name perfectly in my .java file, but I can't create the file system.

I thought about using
«FILE ImplName + ".java" MY_OUTLET»
but I can only change the outlet, not it's value.
What should I do ?


One day I shall master M2T, but that day has yet to come...
Re: Defining package from workflow [message #526633 is a reply to message #526629] Mon, 12 April 2010 13:29 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
Hello,

you know that you can generate files relative to the outlet path?
«FILE package/path/ImplName + ".java" MY_OUTLET»



Regards
Darius
Re: Defining package from workflow [message #526658 is a reply to message #522870] Mon, 12 April 2010 14:15 Go to previous message
MaximeLecourt  is currently offline MaximeLecourt Friend
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...
Previous Topic:Java Extension
Next Topic:[Acceleo] variables
Goto Forum:
  


Current Time: Fri Apr 19 12:41:57 GMT 2024

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

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

Back to the top