|Re: How to access information about the code generated? [message #507267 is a reply to message #507193]
||Tue, 12 January 2010 16:56
| Paul Elder
Registered: July 2009
Unfortunately, there is no public API for accessing the log information
that you see on the JET execution context.
But, if you're willing to take a risk on using internal classes, getting
at this information is pretty simple...
The class org.eclipse.jet.internal.runtime.RuntimeLoggerContextExtende r
is the logging intermediary between log messages issued by tags and any
listeners to this. Given a JET2Context object, you use the
getInstance(JET2Context) static method to obtain an instance.
Once you have a RuntimeLoggerContextExtender, you can use
addListener(RuntimeTagLogger) to add a listener to tag execution.
org.eclipse.jet.internal.runtime.RuntimeTagLogger is an interface with a
single log(String,TagInfo,String,int) method to implement. It is called
everytime a tag wants to log some message. The last argument (int level)
is one of the RuntimeLoggerContextExtender.XXX_LEVEL constants.
So, it should be possible for you to invoke a JET transformation from
API something like the following:
// load the source model, if necessary. Take a peek at the
// implementation of JET2Platform.runTransformOnString()
// or JET2Platform.runTransformOnResource() methods
// for inspiration
// construct a JET2Context
final JET2Context ctx = new JET2Context(inMemoryInputModelRoot);
// get and configure the RuntimeLoggerContextExtender
final RuntimeLoggerContextExtender logExt
// add a log listener...
logExt.addListener( new MyRuntimeTagLogger() );
// finally, run the transformation..
final IStatus status
= JET2Platform.runTransform(id, ctx, progressMonitor);
The only risk you take in doing this is the usage of internal API, so a
future JET version make move, modify or delete these classes/methods
If you'd like a stable API, consider filing an enhancement request. If
you'd really, really like a stable API, consider contributing an
Powered by FUDForum
. Page generated in 0.03076 seconds