Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » exchange data between java and jet template
exchange data between java and jet template [message #63238] Mon, 29 June 2009 08:57 Go to next message
aart matsinger is currently offline aart matsinger
Messages: 12
Registered: July 2009
Junior Member
How can I assign a variable retrieved from a model into script-code and
vice versa, e.g. my model contains the following:
<appendix value1="11" value2="22" value3=""/>
In the JET template I retrieve 'value1' and 'value2' into 'x1' and 'x2'
The following script calculates the maximum:
<%
int a;
int b;
int c = java.lang.Math.max(a, b);
%>
How can I assign 'x1' to 'a', 'x2' to 'b' and (after the script) 'c' to
'x3'

regards,
Aart
Re: exchange data between java and jet template [message #63263 is a reply to message #63238] Mon, 29 June 2009 09:38 Go to previous messageGo to next message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
aart matsinger wrote:
> How can I assign a variable retrieved from a model into script-code and
> vice versa, e.g. my model contains the following:
> <appendix value1="11" value2="22" value3=""/>
> In the JET template I retrieve 'value1' and 'value2' into 'x1' and 'x2'
> The following script calculates the maximum:
> <%
> int a;
> int b;
> int c = java.lang.Math.max(a, b);
> %> How can I assign 'x1' to 'a', 'x2' to 'b' and (after the script) 'c'
> to 'x3'
>
> regards,
> Aart
>

Aart:

I'm am guessing you are doing something like:

<c:setVariable name="x1" select="/appendix/@value1"/>

Even better would be:

<c:setVariable name="x1" select="number(/appendix/@value1)"/>

(so that x1 is a Number rather than an an XPath NodeSet)

Assuming you use the 'number' function in setting the variable,
Your Java code should look like:

<%
int a = ((Number)context.getVariable("x1")).intValue();
int b = ((Number)context.getVariable("x2")).intValue();
int c = Math.max(a, b);
%>

Paul
Re: exchange data between java and jet template [message #63285 is a reply to message #63263] Mon, 29 June 2009 10:01 Go to previous message
aart matsinger is currently offline aart matsinger
Messages: 12
Registered: July 2009
Junior Member
Paul,

Thanks! This works fine.

regards,
Aart
Previous Topic:[Announce] M2T releases with Galileo!
Next Topic:Acceleo QVTO Interop
Goto Forum:
  


Current Time: Mon Sep 01 19:40:29 EDT 2014

Powered by FUDForum. Page generated in 0.01489 seconds