Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [JET2] Run a JET transformation with a customed JET2Writer
[JET2] Run a JET transformation with a customed JET2Writer [message #21591] Thu, 07 June 2007 15:34 Go to next message
Eclipse UserFriend
Originally posted by: guillaume.riby.fr.ibm.com

Hi,
I'm currently working on a project where I have defined a FooBar structure
in an Ecore file, here are the different projects :
- "FooBar" : containing "foobar.ecore" and all generated implementation
files
- "FooBar.jetgenerator" : containing all JET templates

I can launch successfully this M2T transformation via the Eclipse
integrated launcher (Run > JET Transformation > ...). But this time I have
to launch it via another project "FooBar.jetlauncher" defining a customed
JET2Writer. The only way I have noticed to invoke JET transformation
specifying a new writer is to use "void generate(JET2Context context,
JET2Writer out)" method of JET2Template interface.

1/ Which is the good way to use this "generate" method ie where do we
precise PLUGIN_ID? and which class implements JET2Template interface? cause
I don't find it in the Javadoc of JET2Template.

2/ Here is source code of the launcher in a Java Project in the same
workspace, it doesn't work now :

Map<String, String> variables = new HashMap<String, String>();
variables.put("org.eclipse.jet.resource.project.name", PLUGIN_ID);
IStatus status = JET2Platform.runTransformOnObject(PLUGIN_ID, foobar,
variables, new NullProgressMonitor());
if(!status.isOK())
System.err.println("JET transformation has failed!");

Here PLUGIN_ID has been initialized to "FooBar.jetgenerator", the id of the
JET project, and "foobar" is the FooBar object (object corresponding to
implementation class generated from Ecore). The problem is that even if
"foobar" object is correctly loaded an exception is thrown during
JET2Platform.runTransformOnObject call, here it is :

Exception in thread "main" java.lang.ExceptionInInitializerError
at java.lang.J9VMInternals.initialize(J9VMInternals.java:205)
at Main.main(Main.java:37) <-------------------------------------
runTransformOnObject()
Caused by: java.lang.NullPointerException
at org.eclipse.jet.JET2Platform.<clinit>(JET2Platform.java:79)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:187)
... 2 more

I have used the same technics as described in different other posts of this
mailing list. Is that a problem if the launcher "FooBar.jetlauncher"
project is not in the runtime workspace? Three projects are in the
workspace. Is there a particular configuration for such a project
containing the JET transformation launcher?

Thank you.

Guillaume
Re: [JET2] Run a JET transformation with a customed JET2Writer [message #21943 is a reply to message #21591] Fri, 08 June 2007 17:09 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Guillaume:

First, I'm curious why you need a custom writer, maybe it illustrates a
weakness in the current implementation.

But, to user your own implementation of JET2Writer, you'll need to define a
your own version of c:include. Take a look at IncludeTag. The actual
template invocation is done for you by something called
TransformContextExtender. Your code would look something like this:

JET2Writer out = new MyCustomJETWriter(...);
TransformContextExtender.getInstance(context).execute(templa tePath,
/*useSuper*/false, out);

As for your second problem, I'd like to see a bit more of the stack trace.
ExceptionInInitializerError means some exception was thrown during class
initialization.

Looking at the line of code in question, the only way I can see that it
would fail is if you're trying to run outside of the Eclipse environment,
which is not supported. (But it does answer my first question as to why a
custom writer.)

Paul

"Guillaume Riby" <guillaume.riby@fr.ibm.com> wrote in message
news:abf98a999fd5a515bc9ca0356a8ddb52$1@www.eclipse.org...
> Hi,
> I'm currently working on a project where I have defined a FooBar structure
> in an Ecore file, here are the different projects :
> - "FooBar" : containing "foobar.ecore" and all generated implementation
> files
> - "FooBar.jetgenerator" : containing all JET templates
>
> I can launch successfully this M2T transformation via the Eclipse
> integrated launcher (Run > JET Transformation > ...). But this time I have
> to launch it via another project "FooBar.jetlauncher" defining a customed
> JET2Writer. The only way I have noticed to invoke JET transformation
> specifying a new writer is to use "void generate(JET2Context context,
> JET2Writer out)" method of JET2Template interface.
>
> 1/ Which is the good way to use this "generate" method ie where do we
> precise PLUGIN_ID? and which class implements JET2Template interface?
> cause
> I don't find it in the Javadoc of JET2Template.
>
> 2/ Here is source code of the launcher in a Java Project in the same
> workspace, it doesn't work now :
>
> Map<String, String> variables = new HashMap<String, String>();
> variables.put("org.eclipse.jet.resource.project.name", PLUGIN_ID);
> IStatus status = JET2Platform.runTransformOnObject(PLUGIN_ID, foobar,
> variables, new NullProgressMonitor());
> if(!status.isOK())
> System.err.println("JET transformation has failed!");
>
> Here PLUGIN_ID has been initialized to "FooBar.jetgenerator", the id of
> the
> JET project, and "foobar" is the FooBar object (object corresponding to
> implementation class generated from Ecore). The problem is that even if
> "foobar" object is correctly loaded an exception is thrown during
> JET2Platform.runTransformOnObject call, here it is :
>
> Exception in thread "main" java.lang.ExceptionInInitializerError
> at java.lang.J9VMInternals.initialize(J9VMInternals.java:205)
> at Main.main(Main.java:37) <-------------------------------------
> runTransformOnObject()
> Caused by: java.lang.NullPointerException
> at org.eclipse.jet.JET2Platform.<clinit>(JET2Platform.java:79)
> at java.lang.J9VMInternals.initializeImpl(Native Method)
> at java.lang.J9VMInternals.initialize(J9VMInternals.java:187)
> ... 2 more
>
> I have used the same technics as described in different other posts of
> this
> mailing list. Is that a problem if the launcher "FooBar.jetlauncher"
> project is not in the runtime workspace? Three projects are in the
> workspace. Is there a particular configuration for such a project
> containing the JET transformation launcher?
>
> Thank you.
>
> Guillaume
>
>
Previous Topic:[Jet2] Get CompilationUnit from newly generated file
Next Topic:Dump and Text Nodes
Goto Forum:
  


Current Time: Fri Apr 26 17:28:18 GMT 2024

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

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

Back to the top