Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » running jet2 transformation from java
running jet2 transformation from java [message #60134] Thu, 30 April 2009 09:54 Go to next message
Eclipse User
Originally posted by: nickmari77.yahoo.com

Hi,

I know that this subject has already been discussed many times, but I
still can't run my transformation from java. Here's what I've done:

- a jet transformation project my.test.aplJetGen

- in the root of the project I have a sample.xml file that for me is
quite useless, but it is used to run the transform from the right
mouse button. This file contains:

<app/>

- still in the root of the project there are 3 model files:
File1.mod:

<?xml version="1.0" encoding="UTF-8"?>
<com class="Father">
<header name="Arthur" file="File1.mod"/>
<children>
<child link="File2.mod"/>
<child link="File3.mod"/>
</children>
</com>

File2.mod:

<?xml version="1.0" encoding="UTF-8"?>
<com class="Son">
<header name="Archibald" file="File2.mod"/>
<mood val="happy"/>
</com>

File3.mod:

<?xml version="1.0" encoding="UTF-8"?>
<com class="Son">
<header name="Ambrogio" file="File3.mod"/>
<mood val="sad"/>
</com>

- in the template folder there are:

main.jet:

<%@taglib prefix="ws" id="org.eclipse.jet.workspaceTags" %>
<c:if test="isVariableDefined('org.eclipse.jet.resource.project.name') ">
<ws:file template="templates/Family.mod"
path="{$org.eclipse.jet.resource.project.name}/generated.java "/>
</c:if>

family.jet:

Family Members:
<c:load url="cmp.test.aplJetGen/File1.mod" urlContext="workspace"
var="jetFather" type="syd"/>

Father: <c:get select="$jetFather/com/header/@name"/>
<c:iterate select="$jetFather/com/children/child" var="jetChild" >

<c:load url="cmp.test.aplModelGen/{$jetChild/@link}" urlContext="workspace" var="jetLinkChild"/>
Child: <c:get select="$jetLinkChild/com/header/@name"/>
Mood: Child: <c:get select="$jetLinkChild/com/mood/@val"/>
</c:iterate>

- in my java file, from which I run the transformation I have this code:

IStatus status = JET2Platform.runTransformOnString(ID, SOURCE,
new NullProgressMonitor());

here's a couple of questions:

- ID has to be the name of my project transformation? In my case
my.test.aplJetGen, right?

- SOURCE has to be my input model. In this case it should be File1.mod
in a string form? Or can I pass directly the filename?

The result of my java call is:

Exception in thread "main" java.lang.ExceptionInInitializerError
at Main.attempt(Main.java:127)

that refers to the JET2Platform.runTransformOnString call.

- is a second attempt I've followed a previous post/faq (ie: How do I
run an individual JET template and get a string back). Having a string
back is what I really want...

my code:

String[] jetTransformsToSearch = { "my.test.aplJetGen" };
String fileContents = "<com class=\"Father\">"
+ "<header name=\"Arthur\" file=\"File1.mod\"/>"
+ "<children> " + "<child link=\"File2.mod\"/>"
+ "<child link=\"File3.mod\"/>" + "</children> </com>";

final String templatePath = "templates";
final JET2Context context = new JET2Context(fileContents);
final BufferedJET2Writer out = new BodyContentWriter();
try {
JET2TemplateManager.run(jetTransformsToSearch,
new JET2TemplateManager.ITemplateOperation() {
public void run(
JET2TemplateManager.ITemplateRunner templateRunner) {
templateRunner.generate(templatePath, context, out);
}
});
} catch (BundleException e) {
e.printStackTrace();
}

String output = out.getContent();

The result is the same error on the method JET2TemplateManager.run:

Exception in thread "main" java.lang.ExceptionInInitializerError
at org.eclipse.jet.JET2TemplateManager.run(JET2TemplateManager. java:133)
at Main.attempt(Main.java:173)

Obviously there's something that I'm missing.
Hope someone can help :)

Thanks!

Nick
Re: running jet2 transformation from java [message #60158 is a reply to message #60134] Thu, 30 April 2009 12:07 Go to previous message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
Nick Mari wrote:

> Hi,

> I know that this subject has already been discussed many times, but I
> still can't run my transformation from java. Here's what I've done:

>>> Snip

> Obviously there's something that I'm missing.
> Hope someone can help :)

> Thanks!

> Nick

Nick: Sadly, the part that you are missing is that the JET runtime has
dependencies on Eclipse. You cannot run a JET transformation without
Eclipse.

This does not mean you must have the Eclipse UI active. You can run a JET
transformation 'headless' (that is, without a UI). What the transformation
does need, however, is a workspace (which contains your input, and will
contain your output).

The easiest way to run a jet transformation headless is to create an Ant
script that contains the jet.transform task. You then launch the ant
script using the Eclipse Ant runner application:

http://help.eclipse.org/ganymede/topic/org.eclipse.platform. doc.user/tasks/antRunner.htm

Paul
Previous Topic:Article on XPand Aspects
Next Topic:[Acceleo] Text to Model
Goto Forum:
  


Current Time: Fri Oct 31 17:20:49 GMT 2014

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

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