Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » Run generate method for a single JET2 template
Run generate method for a single JET2 template [message #40791] Tue, 22 January 2008 17:21 Go to next message
Eclipse UserFriend
Is there a way to run a single template's generate method?

I'm trying:

public void testJETTrans() throws Exception
{
JET2Context jetcontext = new JET2Context(null, Collections.EMPTY_MAP);
JET2Writer jetwriter = new BodyContentWriter();
_jet_main test = new _jet_main();
test.generate(jetcontext, jetwriter);
}

But I get a java.lang.NullPointerException for the TagFactory of context.
Looking at the API for TagFactory, I'm not sure how to create and set it
to my context. Is what I'm trying to do possible? I'm creating the unit
test and want to run templates one at a time and be able to compare my
expected result to the in memory result of the template.
Re: Run generate method for a single JET2 template [message #40824 is a reply to message #40791] Tue, 22 January 2008 17:45 Go to previous messageGo to next message
Eclipse UserFriend
I was able to get it to work by using the TagFactoryImpl class.

JET2Context jetcontext = new JET2Context(null, initializeTransformVars());
jetcontext.setTagFactory(new TagFactoryImpl(jetcontext));
JET2Writer jetwriter = new BodyContentWriter();
_jet_AttachEventxml test = new _jet_AttachEventxml();
test.generate(jetcontext, jetwriter);
jetwriter.toString();

I'm not quite sure how the tag libraries are being picked up, because I do
also have a custom tag library and it'll be interesting to find out if
this works on a template that uses custom tags as well.
Re: Run generate method for a single JET2 template [message #40886 is a reply to message #40824] Wed, 23 January 2008 13:01 Go to previous message
Eclipse UserFriend
Originally posted by: pankaj.surti.accenture.com

Hi Roshan,

I use the following way to get what you need, this is based on the post
http://dev.eclipse.org/newslists/news.eclipse.modeling.m2t/m sg00364.html

Can someone confirm which method is better?


String[] jetTransformsToSearch = { "com.x1.t1.transform" }; // plug-in name
final String templatePath = "src/main/templates/MyTemplate.jet"; //
template name
final JET2Context context1 = new JET2Context( null ); // create a context
context1.setTagFactory(new TagFactoryImpl(context1)); // attach the
tagfactory
context1.setVariables(); // set all the varibles required by the template
final BufferedJET2Writer out1 = new BodyContentWriter(); // create a writer
// tricky code below, watch out, but works...
JET2TemplateManager.run
(
jetTransformsToSearch,
new JET2TemplateManager.ITemplateOperation() {
public void run(JET2TemplateManager.ITemplateRunner templateRunner)
{
templateRunner.generate( templatePath, context1, out1 );
}
}
);
// do something with the result
String testOutputXML = out1.getContent();

Thanks,
- Pankaj.
Previous Topic:why : "java:package" just being skipped when regenerating
Next Topic:Re: JUnit Test on JET Transform
Goto Forum:
  


Current Time: Thu Jul 17 09:20:37 EDT 2025

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

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

Back to the top