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 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 |
Paul Elder 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 |
Ed Merks Messages: 33140 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 |
Eclipse User |
|
|
|
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 |
Paul Elder 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
|
|
|
Goto Forum:
Current Time: Thu Apr 25 14:46:43 GMT 2024
Powered by FUDForum. Page generated in 0.04059 seconds
|