running jet2 transformation from java [message #60134] |
Thu, 30 April 2009 09:54 |
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03228 seconds