Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [JET] Implicit objects 'context' and 'out'
[JET] Implicit objects 'context' and 'out' [message #520333] Thu, 11 March 2010 23:08 Go to next message
Michael Wahler is currently offline Michael WahlerFriend
Messages: 14
Registered: July 2009
Junior Member
Hi everyone,

I am currently getting started with JET and I have been able to do some
cool things so far! However, when I started to use Java declarations in
my templates, my JET skills came to an end :)

Here's what I am trying to do: I use a template in which I successfully
produce some output using tags such as <c:iterate> or <c:get>. I have
also defined some Java functions within <%! %> tags. My problem is the
interface between the template processor and the Java functions.

First, I need a reference to the top model element, which is of type
'Application', in the Java code. I have tried the statement
Application app = (Application) context.getSource();
because context is supposed to be an "implicit" (whatever that means)
object. The compiler complains that context cannot be resolved.

After I have invoked my functions, I want to print the result into the
output file. Again, I am using an implicit object:
out.write (s);
where s is of type String. However, this causes the following errors:
- Syntax error on token "s", VariableDeclaratorId expected after this token
- Syntax error on token(s), misplaced construct(s)

It seems that the "implicit" objects aren't so implicit afterall. Could
somebody please hint me to a solution?

Thanks and best regards

Re: [JET] Implicit objects 'context' and 'out' [message #522346 is a reply to message #520333] Mon, 22 March 2010 13:06 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member

The 'context' and 'out' objects are implicit only to scriptlets <% ...
%> and expressions <%= ... %>. Implementation-wise, the JET template
gets turned into a Java class:

public class YourTemplate implements JET2Template {

// Your <%! ... %> functions. E.g
// <%!
// String hello(String name)
// return "Hello " + name;
// } %>
String hello(String name) {
return "Hello " + name;

// implement JET2Template#generate(JET2Context,JET2Writer)
public void generate(JET2Context context, JET2Writer out) {

// expressions, e.g. <%= foo %> become
// scriptlets, e.g. <% int x = 3; %> become
int x = 3;

So, if you want your functions to have access to context and out, you
can either pass them to the functions as explicit arguments, or you can
initialize instance variables:

JET2Context context;
JET2Writer out;

this.context = context;
this.out = out;

Previous Topic:how to link xpand in workflow file
Next Topic:Additional Xpath Functions
Goto Forum:

Current Time: Mon May 21 07:20:35 GMT 2018

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

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

Back to the top