XPathExpression question

"Keeney, Wayne" <[email protected]> Fri, 7 Jun 2013 12:35:45 -0600
Newsgroups gmane.comp.java.jdom.general
Message-ID <1C8985E6271A2E4AAD3D9F2C5BEE5E9031FEFFC0B5@RTL-MAIL01.Integ.Local>
--===============1980254971==
Content-Language: en-US
Content-Type: multipart/alternative;
	boundary="_000_1C8985E6271A2E4AAD3D9F2C5BEE5E9031FEFFC0B5RTLMAIL01Inte_"

--_000_1C8985E6271A2E4AAD3D9F2C5BEE5E9031FEFFC0B5RTLMAIL01Inte_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Here's hoping this question gets to the right place.

We are using JDOM2 (2.0.3) and it's my understanding that instances of XPat=
hExpression are not thread safe.  We were using clone as a (hopefully) more=
 efficient method of getting our "own" instance of a pre compiled XPathExpr=
ession safe from other thread access.  This is not my main question, but is=
 it more efficient?

My main question has to do with setting variables on the XPathExpression.  =
I could not get the variable setting to work on a cloned copy of an XPathEx=
pression, but it works if I set the variable before cloning.  The problem w=
ith this, is of course, thread safety.

Is this a known bug, maybe fixed?

This works (but opens an opportunity for threading problems since we're usi=
ng precompiled static instances):
                        XPathExpression<Element> xPath =3D pathMap.get(meth=
od);
                        xPath.setVariable("variable", namespace, "fString")=
;
                        List<Element> elems =3D xPath.clone().evaluate(mode=
l.asDocument());

But this doesn't work, it doesn't seem to recognize the variable replacemen=
t:
                        XPathExpression<Element> xPath =3D pathMap.get(meth=
od).clone();
                        xPath.setVariable("variable", namespace, "fString")=
;
                        List<Element> elems =3D xPath.evaluate(model.asDocu=
ment());

pathmap is just a map of precompiled XPathExpressions.

Thanks,

Wayne Keeney
SAT Services


--_000_1C8985E6271A2E4AAD3D9F2C5BEE5E9031FEFFC0B5RTLMAIL01Inte_
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40"><head><meta http-equiv=3DContent-Type content=
=3D"text/html; charset=3Dus-ascii"><meta name=3DGenerator content=3D"Micros=
oft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Consolas;
	panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal-compose;
	font-family:"Calibri","sans-serif";
	color:windowtext;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]--></head><body lang=3DEN-US link=3Dblue vli=
nk=3Dpurple><div class=3DWordSection1><p class=3DMsoNormal>Here&#8217;s hop=
ing this question gets to the right place.&nbsp; <o:p></o:p></p><p class=3D=
MsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>We are using JDOM2 (2.0=
.3) and it&#8217;s my understanding that instances of XPathExpression are n=
ot thread safe.&nbsp; We were using clone as a (hopefully) more efficient m=
ethod of getting our &#8220;own&#8221; instance of a pre compiled XPathExpr=
ession safe from other thread access.&nbsp; This is not my main question, b=
ut is it more efficient?<o:p></o:p></p><p class=3DMsoNormal><o:p>&nbsp;</o:=
p></p><p class=3DMsoNormal>My main question has to do with setting variable=
s on the XPathExpression.&nbsp; I could not get the variable setting to wor=
k on a cloned copy of an XPathExpression, but it works if I set the variabl=
e before cloning.&nbsp; The problem with this, is of course, thread safety.=
<o:p></o:p></p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNorm=
al>Is this a known bug, maybe fixed?&nbsp; <o:p></o:p></p><p class=3DMsoNor=
mal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>This works (but opens an oppo=
rtunity for threading problems since we&#8217;re using precompiled static i=
nstances):<o:p></o:p></p><p class=3DMsoNormal style=3D'text-autospace:none'=
><span style=3D'font-size:10.0pt;font-family:Consolas;color:black'>&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XPathExpression&lt;=
Element&gt; xPath =3D </span><i><span style=3D'font-size:10.0pt;font-family=
:Consolas;color:#0000C0'>pathMap</span></i><span style=3D'font-size:10.0pt;=
font-family:Consolas;color:black'>.get(method);</span><span style=3D'font-s=
ize:10.0pt;font-family:Consolas'><o:p></o:p></span></p><p class=3DMsoNormal=
 style=3D'text-autospace:none'><span style=3D'font-size:10.0pt;font-family:=
Consolas;color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp; xPath.setVariable(</span><span style=3D'font-size:10.0pt;font-fa=
mily:Consolas;color:#2A00FF'>&quot;variable&quot;</span><span style=3D'font=
-size:10.0pt;font-family:Consolas;color:black'>, </span><i><span style=3D'f=
ont-size:10.0pt;font-family:Consolas;color:#0000C0'>namespace</span></i><sp=
an style=3D'font-size:10.0pt;font-family:Consolas;color:black'>, </span><sp=
an style=3D'font-size:10.0pt;font-family:Consolas;color:#2A00FF'>&quot;fStr=
ing&quot;</span><span style=3D'font-size:10.0pt;font-family:Consolas;color:=
black'>);</span><span style=3D'font-size:10.0pt;font-family:Consolas'><o:p>=
</o:p></span></p><p class=3DMsoNormal><span style=3D'font-size:10.0pt;font-=
family:Consolas;color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp; List&lt;Element&gt; elems =3D xPath.clone().evaluate(mode=
l.asDocument());<o:p></o:p></span></p><p class=3DMsoNormal><span style=3D'f=
ont-size:10.0pt;font-family:Consolas;color:black'><o:p>&nbsp;</o:p></span><=
/p><p class=3DMsoNormal><span style=3D'font-size:10.0pt;font-family:Consola=
s;color:black'>But this doesn&#8217;t work, it doesn&#8217;t seem to recogn=
ize the variable replacement:<o:p></o:p></span></p><p class=3DMsoNormal sty=
le=3D'text-autospace:none'><span style=3D'font-size:10.0pt;font-family:Cons=
olas;color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp; XPathExpression&lt;Element&gt; xPath =3D </span><i><span style=3D'fo=
nt-size:10.0pt;font-family:Consolas;color:#0000C0'>pathMap</span></i><span =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>.get(method).cl=
one();</span><span style=3D'font-size:10.0pt;font-family:Consolas'><o:p></o=
:p></span></p><p class=3DMsoNormal style=3D'text-autospace:none'><span styl=
e=3D'font-size:10.0pt;font-family:Consolas;color:black'>&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xPath.setVariable(</span><span=
 style=3D'font-size:10.0pt;font-family:Consolas;color:#2A00FF'>&quot;variab=
le&quot;</span><span style=3D'font-size:10.0pt;font-family:Consolas;color:b=
lack'>, </span><i><span style=3D'font-size:10.0pt;font-family:Consolas;colo=
r:#0000C0'>namespace</span></i><span style=3D'font-size:10.0pt;font-family:=
Consolas;color:black'>, </span><span style=3D'font-size:10.0pt;font-family:=
Consolas;color:#2A00FF'>&quot;fString&quot;</span><span style=3D'font-size:=
10.0pt;font-family:Consolas;color:black'>);</span><span style=3D'font-size:=
10.0pt;font-family:Consolas'><o:p></o:p></span></p><p class=3DMsoNormal><sp=
an style=3D'font-size:10.0pt;font-family:Consolas;color:black'>&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;Element&gt; ele=
ms =3D xPath.evaluate(model.asDocument());<o:p></o:p></span></p><p class=3D=
MsoNormal><span style=3D'font-size:10.0pt;font-family:Consolas;color:black'=
><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span style=3D'font-size:=
10.0pt;font-family:Consolas;color:black'>pathmap is just a map of precompil=
ed XPathExpressions.<o:p></o:p></span></p><p class=3DMsoNormal><span style=
=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p>&nbsp;</o:p></s=
pan></p><p class=3DMsoNormal><span style=3D'font-size:10.0pt;font-family:Co=
nsolas;color:black'>Thanks,<o:p></o:p></span></p><p class=3DMsoNormal><span=
 style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p>&nbsp;</o=
:p></span></p><p class=3DMsoNormal><span style=3D'font-size:10.0pt;font-fam=
ily:Consolas;color:black'>Wayne Keeney<o:p></o:p></span></p><p class=3DMsoN=
ormal><span style=3D'font-size:10.0pt;font-family:Consolas;color:black'>SAT=
 Services</span><o:p></o:p></p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p></=
div></body></html>=

--_000_1C8985E6271A2E4AAD3D9F2C5BEE5E9031FEFFC0B5RTLMAIL01Inte_--

--===============1980254971==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/[email protected]
--===============1980254971==--