[jdom-interest] XPathExpression question

jdom jdom at tuis.net
Fri Jun 7 11:48:47 PDT 2013


Hi Wayne.

You are asking in the right place.... :)

Other people may provide an answer sooner, but, I suspect that I will 
have to study your question in detail (and reproduce some things to 
check).

I will do that this evening (EST) and get back to you (I am at a 
conference now).

Rolf

On 2013-06-07 14:35, Keeney, Wayne wrote:
> 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
> XPathExpression are not thread safe. We were using clone as a
> (hopefully) more efficient method of getting our "own" instance of a
> pre compiled XPathExpression 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 XPathExpression, but it works if I set the variable
> before cloning. The problem with 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 using precompiled static instances):
>
>  XPathExpression<Element> xPath = _pathMap_.get(method);
>
>  xPath.setVariable("variable", _namespace_, "fString");
>
>  List<Element> elems = xPath.clone().evaluate(model.asDocument());
>
> But this doesn't work, it doesn't seem to recognize the variable
> replacement:
>
>  XPathExpression<Element> xPath = _pathMap_.get(method).clone();
>
>  xPath.setVariable("variable", _namespace_, "fString");
>
>  List<Element> elems = xPath.evaluate(model.asDocument());
>
> pathmap is just a map of precompiled XPathExpressions.
>
> Thanks,
>
> Wayne Keeney
>
> SAT Services



More information about the jdom-interest mailing list