How to use Java Emitter Template (JET) to generate Java code from a a .xmi file created based on an EMF model

StackOverflow https://stackoverflow.com/questions/4479359

Pergunta

So, here is my problem, I have an Eclipse EMF project, and i have built a model, generated the corresponding code, and also programmed some framework classes by hand, that correspond to the model.

I have used the eclipse wizard to adapt the project to a Java Emitter Template (JET) Transformation project (and noticed that this did not generate the same configurations in the MANIFEST, that a JET Project created from scratch, does...)

I have created a JET file that creates a Java class to generate the code for the main class of the application, based on the input that goes into "argument".

Then I have created a Dynamic instance, and populated the created .xmi file with some nodes according to the model.

Now what I did was to create a JET Transformation running configuration, and i am trying to pass as input the .xmi file, and use onee of the only two things available in the Transformation ID combo box...

If I select Transformation ID to be jet2, I get this output in console:

templates/main.jet(8,1):  <c:setVariable var='org.eclipse.jet.taglib.control.iterateSetsContext' select='true()'>
    Trace: completed action. 
templates/main.jet(29,1):  <c:if test='isVariableDefined(''org.eclipse.jet.resource.project.name'')'>
    Trace: processing body
templates/dump.jet(2,1):  <c:dump select='/*' format='true' entities='true'>
    Trace: completed action. 
templates/main.jet(30,5):  <ws:file template='templates/dump.jet' path='{$org.eclipse.jet.resource.project.name}/dump.xml'>
    Trace: completed action. 
Successful Execution

And if instead, I select Transformation ID to be org.eclipse.jet.transforms.taglib.doc (the only available other option), I get:

templates/control.jet(8,1):  <c:setVariable var='jetPluginNS' select='''org.eclipse.jet'''>
    Trace: completed action. 
templates/control.jet(9,1):  <c:setVariable var='tagLibrariesXP' select='concat($jetPluginNS, ''.tagLibraries'')'>
    Trace: completed action. 
templates/control.jet(15,1):  <c:setVariable var='pluginNS' select='$org.eclipse.jet.resource.project.name'>
    Trace: completed action. 
templates/control.jet(16,1):  <c:setVariable var='docPlugin' select='concat($org.eclipse.jet.resource.project.name, ''.doc'')'>
    Trace: completed action. 
templates/control.jet(21,5):  <c:iterate select='/plugin/extension[@point = $tagLibrariesXP]' var='extension'>
    Trace: loop initialized
templates/control.jet(21,5):  <c:iterate select='/plugin/extension[@point = $tagLibrariesXP]' var='extension'>
    Trace: finished loop
templates/control.jet(69,5):  <c:iterate select='/plugin/extension[@point = $tagLibrariesXP]' var='extension'>
    Trace: loop initialized
templates/control.jet(69,5):  <c:iterate select='/plugin/extension[@point = $tagLibrariesXP]' var='extension'>
    Trace: finished loop
Successful Execution

In either case, I dont get any generated Java class out of the generate method, and yet both say they are successful... also, by the console messages in first case, I see that a dump.xml file is generated with a kind of xmi to xml translation of that file, but without any association to Java or any of the methods i defined to be created in the JET generation class...

Also, if after generating the dump.xml file mentioned, i try to use it as input, it tells me that my Application object is not found or is abstract. In fact the one from the generated package is indeed an interface, but even if i try to use the Impl one i get the same error, and i dont even know if it is acting correctly because of all this procedure i took to get to this dump.xml file.

What am I doing wrong? can anyone please help me?

Thanks in advance!

Foi útil?

Solução

Since you only had two choices for transformation id I'm going to say that you did not create a JET transform project. If you had then its transform id would have shown up in the drop down list in the configurations dialog.

I would start by using the new project wizard to create a new JET transform project. The default behavior of a new transform is to dump the input model into a file named dump.xml in the root directory of the same project that contains the input model file. When this JET project has been created then use the run configuration dialog to run the transform against your XML file. When you look at the dump.xml file that gets created you'll see the actual model that JET uses. EMF models can be cyclical but JET will adapt an EMF model into a subset that is hierarchical in nature.

Once you see the effective model (the one in the dump.xml file) then you can build or modify your templates to use that model and generate whatever files you need.

Also, the way your question is worded you seem to have built a single JET template for your class, but JET also needs a template, usually called main.jet, that acts as a controller in the MVC sense and which is responsible for applying other JET templates in the JET project to the model and specifying the resultant file names for the generated content.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top