Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Any JET2 sample with Java object input ?
Any JET2 sample with Java object input ? [message #41381] Wed, 06 February 2008 13:56 Go to next message
Eclipse User
Originally posted by: aah.yahoo.com

Hi,
I am looking for a JET2 sample, where the input is a live Java object --
which was described in JET1 tutorials published. I see that most of the
JET2 samples talk about a sample xml input and the template operates on
it using XPath.

Can someone please share some sample where input is a Java object?
Thanks in advance.
-Anand
Re: Any JET2 sample with Java object input ? [message #41544 is a reply to message #41381] Thu, 07 February 2008 16:35 Go to previous messageGo to next message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
Anand:

If you are looking to manipulate Java objects directly, here are a few
suggestions.

1) To lauch a JET transformation, use
JET2Platform.runTransformationOnObject(), passing the object you want.

2) With-in a JET2 template, to access that object, use:

context.getSource().

(BTW, you can use Java scriptlets <% ...java statements ...%> and Java
expressions <%= expression %> within the template).

3) To write text from a scriptlet, use the 'out' variable.

If you can tell us a bit more about the context in which you want to use
JET, I can give you more hints.

Thanks,

Paul

"Anand" <aah@yahoo.com> wrote in message
news:foceb8$bg$1@build.eclipse.org...
> Hi,
> I am looking for a JET2 sample, where the input is a live Java object --
> which was described in JET1 tutorials published. I see that most of the
> JET2 samples talk about a sample xml input and the template operates on it
> using XPath.
>
> Can someone please share some sample where input is a Java object?
> Thanks in advance.
> -Anand
Re: Any JET2 sample with Java object input ? [message #41604 is a reply to message #41544] Fri, 08 February 2008 04:00 Go to previous messageGo to next message
Eclipse User
Originally posted by: anand.hatwalne.gmail.com

Paul, thanks for your reply.

I writing out some C++ code, by walking (parts of) the CDT AST.
So the input to my template would be a IASTTranslationUnit or
IASTCompositeTypeSpecifier object.

Using JET1, I figured out that it was as simple as passing the argument
to the template, and then play with that in the template.
I wasn't exactly sure how to achieve the same using JET2.


Here's a snippet from JET1 that I have put together. An analogy/example
with JET2 to achieve the same, would be really nice.

<%@jet package="com.mypackage"
imports="org.eclipse.cdt.core.dom.ast.* java.util.*"
class="MyGenerator"
%>


<% IASTTranslationUnit translationUnit = (IASTTranslationUnit) argument; %>


<%= Do Something here from the TU passed %>


thanks again,
Anand

Paul Elder wrote the following on 2/7/2008 10:05 PM:
> Anand:
>
> If you are looking to manipulate Java objects directly, here are a few
> suggestions.
>
> 1) To lauch a JET transformation, use
> JET2Platform.runTransformationOnObject(), passing the object you want.
>
> 2) With-in a JET2 template, to access that object, use:
>
> context.getSource().
>
> (BTW, you can use Java scriptlets <% ...java statements ...%> and Java
> expressions <%= expression %> within the template).
>
> 3) To write text from a scriptlet, use the 'out' variable.
>
> If you can tell us a bit more about the context in which you want to use
> JET, I can give you more hints.
>
> Thanks,
>
> Paul
>
> "Anand" <aah@yahoo.com> wrote in message
> news:foceb8$bg$1@build.eclipse.org...
>> Hi,
>> I am looking for a JET2 sample, where the input is a live Java object --
>> which was described in JET1 tutorials published. I see that most of the
>> JET2 samples talk about a sample xml input and the template operates on it
>> using XPath.
>>
>> Can someone please share some sample where input is a Java object?
>> Thanks in advance.
>> -Anand
>
>
Re: Any JET2 sample with Java object input ? [message #41758 is a reply to message #41604] Wed, 13 February 2008 15:44 Go to previous message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
Anand:

Apart form context.getSource(), you can also set JET2 context variables:

context.setVariable("someName", someValue);

You can then get these inside your templates:

<%
IASTTranslationUnit translationUnit = (IASTTranslationUnit)
context.getVariable("someName");
%>

Paul

"Anand Hatwalne" <anand.hatwalne@gmail.com> wrote in message
news:fogk59$apb$1@build.eclipse.org...
> Paul, thanks for your reply.
>
> I writing out some C++ code, by walking (parts of) the CDT AST.
> So the input to my template would be a IASTTranslationUnit or
> IASTCompositeTypeSpecifier object.
>
> Using JET1, I figured out that it was as simple as passing the argument to
> the template, and then play with that in the template.
> I wasn't exactly sure how to achieve the same using JET2.
>
>
> Here's a snippet from JET1 that I have put together. An analogy/example
> with JET2 to achieve the same, would be really nice.
>
> <%@jet package="com.mypackage"
> imports="org.eclipse.cdt.core.dom.ast.* java.util.*"
> class="MyGenerator"
> %>
>
>
> <% IASTTranslationUnit translationUnit = (IASTTranslationUnit) argument;
> %>
>
>
> <%= Do Something here from the TU passed %>
>
>
> thanks again,
> Anand
>
> Paul Elder wrote the following on 2/7/2008 10:05 PM:
>> Anand:
>>
>> If you are looking to manipulate Java objects directly, here are a few
>> suggestions.
>>
>> 1) To lauch a JET transformation, use
>> JET2Platform.runTransformationOnObject(), passing the object you want.
>>
>> 2) With-in a JET2 template, to access that object, use:
>>
>> context.getSource().
>>
>> (BTW, you can use Java scriptlets <% ...java statements ...%> and Java
>> expressions <%= expression %> within the template).
>>
>> 3) To write text from a scriptlet, use the 'out' variable.
>>
>> If you can tell us a bit more about the context in which you want to use
>> JET, I can give you more hints.
>>
>> Thanks,
>>
>> Paul
>>
>> "Anand" <aah@yahoo.com> wrote in message
>> news:foceb8$bg$1@build.eclipse.org...
>>> Hi,
>>> I am looking for a JET2 sample, where the input is a live Java object --
>>> which was described in JET1 tutorials published. I see that most of the
>>> JET2 samples talk about a sample xml input and the template operates on
>>> it using XPath.
>>>
>>> Can someone please share some sample where input is a Java object?
>>> Thanks in advance.
>>> -Anand
>>
Previous Topic:debugging one's custom tags
Next Topic:Debugging the JET in the Eclipse
Goto Forum:
  


Current Time: Thu Oct 23 15:54:16 GMT 2014

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

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