Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Generation an XMI file to java file(How to generate XMi file to java file)
Generation an XMI file to java file [message #957531] Thu, 25 October 2012 05:41 Go to next message
Charbel Aoun is currently offline Charbel Aoun
Messages: 7
Registered: October 2012
Junior Member
Hello, I have created a meta-modele using the EMF and i got the file.Ecore then i generated to java files using acceleo 3.0 .
Everything is ok then i created a dynamic instance by right click on the ecore model and i filled data in the attribute and i got the XMI file.
Now i want to generate this XMi file to java file ( .java) as i did it for the ecore extension.
So is it possible to generate from .XMi to .java using acceleo and the mtl files i have????

Please i need this a solution as soon as possible if somebody can help.

Thank you in advance

Re: Generation an XMI file to java file [message #957597 is a reply to message #957531] Thu, 25 October 2012 06:44 Go to previous messageGo to next message
Charbel Aoun is currently offline Charbel Aoun
Messages: 7
Registered: October 2012
Junior Member
Charbel Aoun wrote on Thu, 25 October 2012 05:41
Hello, I have created a meta-modele using the EMF and i got the file.Ecore then i generated to java files using acceleo 3.0 .
Everything is ok then i created a dynamic instance by right click on the ecore model and i filled data in the attribute and i got the XMI file.
Now i want to generate this XMi file to java file ( .java) as i did it for the ecore extension.
So is it possible to generate from .XMi to .java using acceleo and the mtl files i have????

Please i need this a solution as soon as possible if somebody can help.

Thank you in advance


Re: Generation an XMI file to java file [message #957851 is a reply to message #957597] Thu, 25 October 2012 10:47 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
Charbel,

Acceleo operates on any EMF model, not only ".ecore" ones. Generating code from your xmi file is as easy as providing them to your launch config. However, your templates have been created to operated on ecore objects (EClass, EOperation, EAttribute...). The objects from your dynamic instance are not elements applying to the ecore metamodel, but elements applying to your own metamodel (as defined in "file.ecore").

For example, you may have created a class named "Library" in your model "file.ecore". When you launch acceleo with file.ecore, generating code from that object needs a template applying to (its first parameter) EClass. When you create a dynamic instance of your "Library" class, the template that applies to that dynamic instance must have its first parameter to be of type "Library".

In other words : yes, you can generate code from your dynamic instance through Acceleo, whatever the file extension; but no, you can't use the same generators for both the Ecore metamodel and your dynamic instance (that is in fact a model which metamodel is that 'file.ecore' from which you created it).

Laurent Goubet
Obeo
Re: Generation an XMI file to java file [message #958090 is a reply to message #957851] Thu, 25 October 2012 14:55 Go to previous messageGo to next message
Charbel Aoun is currently offline Charbel Aoun
Messages: 7
Registered: October 2012
Junior Member
Thank you for your reply, I have created another generator mtl file for the XMI and i wrote the following code inside (excuse me i'm so new in this language but i need a small demonstration for the moment):

[comment encoding = UTF-8 /]
[module generate('http://www.eclipse.org/emf/2003/XMLType')]


[template public generateElement(Library:XMLTypeDocumentRoot)]
[comment @main /]
[file (Library.generateElement().concat('.java'),false))]
[/file]
[/template]

only i need to see the file i have addressBook.XMi generated under the name addressBook.java

I already do it from ecore extension.

Could you help please by fixing the code if it's possible.

Thank you a lot

Re: Generation an XMI file to java file [message #958752 is a reply to message #958090] Fri, 26 October 2012 03:30 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
Charbel,

It seems like you are not new only to Acceleo but also to EMF. Using dynamic instances correctly is not that easy without knowledge of how the EMF framework works.

Please take a look at EMF tutorials to see how you can define your model and generate at editor for it (Lars Vogel has some pretty good ones, such as http://www.vogella.com/articles/EclipseEMF/article.html). This will allow you to use a "real" model instead of a dynamic one. It will also provide you with a true "metamodel URI" to act on instead of trying to use raw XML. This will allow you to replace
[module generate('http://www.eclipse.org/emf/2003/XMLType')]

with a more sensible
[module generate('http://www.eclipse.org/myMetamodelURI')]

one, and the too generic
[template public generateElement(Library : XMLTypeDocumentRoot)]

with the customized
[template public generateElement(Library : Library)]


In other words, you will be able to define your templates customized for your metamodel instead of trying to use generic, unknown types. This will not take you much longer, but it will obviously ease your task in the long run, especially if you plan on using more than Acceleo in terms of EMF-based tools.

Laurent Goubet
Obeo
Re: Generation an XMI file to java file [message #958775 is a reply to message #958752] Fri, 26 October 2012 03:51 Go to previous message
Charbel Aoun is currently offline Charbel Aoun
Messages: 7
Registered: October 2012
Junior Member
Yes i'm new in EMF two.
Thank you a lot i will look to the tutoriel then i will keep you posted.
Previous Topic:[Acceleo] JMerge tags with standalone generator
Next Topic:[Acceleo] Importing the Acceleo source code as a Maven project
Goto Forum:
  


Current Time: Tue Sep 02 05:19:50 EDT 2014

Powered by FUDForum. Page generated in 0.01925 seconds