Java Mailing List Archive

http://www.junlu.com/

Home » JDOM Projects »

[jdom-interest] XPathExpression question

Keeney, Wayne

2013-06-07

Replies: Find Java Web Hosting

Author LoginPost Reply

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

 

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.