Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » error on context.getVariable
error on context.getVariable [message #64137] Fri, 10 July 2009 08:10 Go to next message
aart matsinger is currently offline aart matsingerFriend
Messages: 12
Registered: July 2009
Junior Member
The following construct in a JET transformation template gives an error:
...
<c:setVariable var="x0" select="$c/@name" />
<%
String x1 = (String) context.getVariable("x0");
String x2 = x1 + "_1.xml";
out.write(x2);
%>
The error message is:
Error executing tag handler: java.lang.ClassCastException:
org.eclipse.jet.internal.xpath.NodeSetImpl cannot be cast to
java.lang.String

What could be the cause of this error, and how could I solve it ?

Some background:
The JET template 'work.jet' gets as input an profile that specifies the
names of a set of (other) XML files that it loads inside a loop, and deals
with their content.
In 'main.jet' I have included a dump statement for the profile.
However I want to dump each of the XML files that are specified in the
profile.
For that reason I want (inside 'work.jet') to construct specific names for
these dump files.
Any help is very much appreciated.
Kind regards,
Aart Matsinger
Re: error on context.getVariable [message #64182 is a reply to message #64137] Fri, 10 July 2009 13:16 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Aart wrote:
> The following construct in a JET transformation template gives an error:
> ...
> <c:setVariable var="x0" select="$c/@name" />
> <%
> String x1 = (String) context.getVariable("x0");
> String x2 = x1 + "_1.xml";
> out.write(x2);
> %>
> The error message is:
> Error executing tag handler: java.lang.ClassCastException:
> org.eclipse.jet.internal.xpath.NodeSetImpl cannot be cast to
> java.lang.String

Two suggestions:

1) The result of $c/@name is an XPath nodeset, not a string. You can
convert it to a string in one of two ways:

<c:setVariable var="x0" select="string($c/@name)"/>

or, in you Java code...

<%
String x1 =
org.eclipse.jet.xpath.XPathUtil.xpathString(context.getVaria ble( "x0"));
...
%>

2) You don't need to drop into Java at all to do what you want! Simply
putting this expression into your template yields the same result:

${$c/@name)_1.xml

Or, if you are using a release earlier than 1.0, the slightly longer form
below is equivalent:

<c:get select="$c/@name"/>_1.xml

Paul
Re: error on context.getVariable [message #64211 is a reply to message #64182] Fri, 10 July 2009 14:03 Go to previous message
aart matsinger is currently offline aart matsingerFriend
Messages: 12
Registered: July 2009
Junior Member
Paul,

Thanks for your help: I tried all alternatives and they are working fine,
except for the one that requires a version a version 1.
I found that I have for JET version 0.9.3 and for JET Core version 1.1.1,
so I assume that seems consistent with your statement.
I am struggling with the basics, so I am learning a lot in this way.

kind regards,
Aart
Previous Topic:XPand workflow problem
Next Topic:Using 'dump.jet' for sub-files
Goto Forum:
  


Current Time: Tue Mar 19 06:41:49 GMT 2024

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

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

Back to the top