Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » invoke template from java with string return?
invoke template from java with string return? [message #87792] Sat, 30 June 2007 19:40 Go to next message
Eclipse UserFriend
Originally posted by: woodri.us.ibm.com

Hi,

I've looked at the runTransformOnX() methods (x=Object,String, ...) in
org.eclipse.jet.JET2Platform. Is there a JET2 class that does something
like org.eclipse.emf.codegen.jet.JETEmitter in EMF: take a list of
arguments, execute a template against them, and return a string?

Thanks,
Rick
Re: invoke template from java with string return? [message #87819 is a reply to message #87792] Sun, 01 July 2007 12:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Rick,

I'll redirect your question to the M2T newsgroup (on the "to" list of
the reply) where the JET2 questions are answered.


Rick Wood wrote:
> Hi,
>
> I've looked at the runTransformOnX() methods (x=Object,String, ...) in
> org.eclipse.jet.JET2Platform. Is there a JET2 class that does
> something like org.eclipse.emf.codegen.jet.JETEmitter in EMF: take a
> list of arguments, execute a template against them, and return a string?
>
> Thanks,
> Rick
Re: invoke template from java with string return? [message #87847 is a reply to message #87819] Mon, 02 July 2007 12:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: woodri.us.ibm.com

Thanks Ed - I looked for that group, but forgot to hit the "refresh"
button on the newsgroup subscription panel ... !

Ed Merks wrote:
> Rick,
>
> I'll redirect your question to the M2T newsgroup (on the "to" list of
> the reply) where the JET2 questions are answered.
>
>
> Rick Wood wrote:
>> Hi,
>>
>> I've looked at the runTransformOnX() methods (x=Object,String, ...) in
>> org.eclipse.jet.JET2Platform. Is there a JET2 class that does
>> something like org.eclipse.emf.codegen.jet.JETEmitter in EMF: take a
>> list of arguments, execute a template against them, and return a string?
>>
>> Thanks,
>> Rick
Re: invoke template from java with string return? [message #88177 is a reply to message #87792] Thu, 05 July 2007 13:26 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Rick:

Yes, JET 0.8.0 has org.eclipse.jet.JET2TemplateManager. You use it something
like this...

String[] jetTransformsToSearch = { "a.b.c", ... };

final String templatePath = "... project relative path of the template to
run.jet ...";
final JET2Context context = new JET2Context( ... source model or null ...);
// optionally set any context variables via
context.setVariable("name", ... value ...);
final BufferedJET2Writer out = new BodyContentWriter();
JET2TemplateManager.run( jetTransformsToSeach, new
JET2TemplateManager.ITemplateOperation() {
public run(JET2TemplateManager.ITemplateRunner templateRunner) {
String result = templateRunner.generate( templatePath, context,
out );
}
});
// do something with the result
String output = out.getContent();

The reason for passing the runnable-like class is that the manager may have
to dynamically load JET projects from the workspace. JET is very careful to
make sure such things get unloaded again - using the ITemplateOperation
helps identify that boundary. In real life, you would probably execute
multiple templates in a single ITemplateOperation.

Lastly, I noticed the Javadoc for ITemplateRunner.generate() says it
throughs IllegalAccessException. It does not. It throughs
IllegalArgumentException of templatePath does not map to a know template. I
have submitted bug 195523
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=195523).

Paul


"Rick Wood" <woodri@us.ibm.com> wrote in message
news:f66bjj$39i$1@build.eclipse.org...
> Hi,
>
> I've looked at the runTransformOnX() methods (x=Object,String, ...) in
> org.eclipse.jet.JET2Platform. Is there a JET2 class that does something
> like org.eclipse.emf.codegen.jet.JETEmitter in EMF: take a list of
> arguments, execute a template against them, and return a string?
>
> Thanks,
> Rick
Re: invoke template from java with string return? [message #608619 is a reply to message #87792] Sun, 01 July 2007 12:04 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 32454
Registered: July 2009
Senior Member
Rick,

I'll redirect your question to the M2T newsgroup (on the "to" list of
the reply) where the JET2 questions are answered.


Rick Wood wrote:
> Hi,
>
> I've looked at the runTransformOnX() methods (x=Object,String, ...) in
> org.eclipse.jet.JET2Platform. Is there a JET2 class that does
> something like org.eclipse.emf.codegen.jet.JETEmitter in EMF: take a
> list of arguments, execute a template against them, and return a string?
>
> Thanks,
> Rick


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: invoke template from java with string return? [message #608621 is a reply to message #87819] Mon, 02 July 2007 12:16 Go to previous message
Eclipse UserFriend
Originally posted by: woodri.us.ibm.com

Thanks Ed - I looked for that group, but forgot to hit the "refresh"
button on the newsgroup subscription panel ... !

Ed Merks wrote:
> Rick,
>
> I'll redirect your question to the M2T newsgroup (on the "to" list of
> the reply) where the JET2 questions are answered.
>
>
> Rick Wood wrote:
>> Hi,
>>
>> I've looked at the runTransformOnX() methods (x=Object,String, ...) in
>> org.eclipse.jet.JET2Platform. Is there a JET2 class that does
>> something like org.eclipse.emf.codegen.jet.JETEmitter in EMF: take a
>> list of arguments, execute a template against them, and return a string?
>>
>> Thanks,
>> Rick
Re: invoke template from java with string return? [message #608643 is a reply to message #87792] Thu, 05 July 2007 13:26 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Rick:

Yes, JET 0.8.0 has org.eclipse.jet.JET2TemplateManager. You use it something
like this...

String[] jetTransformsToSearch = { "a.b.c", ... };

final String templatePath = "... project relative path of the template to
run.jet ...";
final JET2Context context = new JET2Context( ... source model or null ...);
// optionally set any context variables via
context.setVariable("name", ... value ...);
final BufferedJET2Writer out = new BodyContentWriter();
JET2TemplateManager.run( jetTransformsToSeach, new
JET2TemplateManager.ITemplateOperation() {
public run(JET2TemplateManager.ITemplateRunner templateRunner) {
String result = templateRunner.generate( templatePath, context,
out );
}
});
// do something with the result
String output = out.getContent();

The reason for passing the runnable-like class is that the manager may have
to dynamically load JET projects from the workspace. JET is very careful to
make sure such things get unloaded again - using the ITemplateOperation
helps identify that boundary. In real life, you would probably execute
multiple templates in a single ITemplateOperation.

Lastly, I noticed the Javadoc for ITemplateRunner.generate() says it
throughs IllegalAccessException. It does not. It throughs
IllegalArgumentException of templatePath does not map to a know template. I
have submitted bug 195523
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=195523).

Paul


"Rick Wood" <woodri@us.ibm.com> wrote in message
news:f66bjj$39i$1@build.eclipse.org...
> Hi,
>
> I've looked at the runTransformOnX() methods (x=Object,String, ...) in
> org.eclipse.jet.JET2Platform. Is there a JET2 class that does something
> like org.eclipse.emf.codegen.jet.JETEmitter in EMF: take a list of
> arguments, execute a template against them, and return a string?
>
> Thanks,
> Rick
Previous Topic:[Teneo / JPOX] Reload content
Next Topic:[Teneo / JPOX] Spaces with type string
Goto Forum:
  


Current Time: Sat Aug 20 06:01:38 GMT 2022

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

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

Back to the top