cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1090633 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
Date Sat, 09 Apr 2011 17:19:56 GMT
Author: dkulp
Date: Sat Apr  9 17:19:56 2011
New Revision: 1090633

URL: http://svn.apache.org/viewvc?rev=1090633&view=rev
Log:
When calling xpath.evaluate, the classloader MUST be the exact
classloader used to load the xpath expression.   Otherwise,
strange ClassCastExceptions occur
Don't hold onto the Factory as it can lock the classloader.  If this
causes a performance issue, we may need to relook at it.

Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java
    cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java?rev=1090633&r1=1090632&r2=1090633&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java Sat Apr 
9 17:19:56 2011
@@ -31,11 +31,10 @@ import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 public class XPathUtils {
-    private static final XPathFactory FACTORY = XPathFactory.newInstance();
     private XPath xpath;
 
     public XPathUtils() {
-        xpath = FACTORY.newXPath();
+        xpath = XPathFactory.newInstance().newXPath();
     }
 
     public XPathUtils(final Map<String, String> ns) {
@@ -52,10 +51,14 @@ public class XPathUtils {
     }
 
     public Object getValue(String xpathExpression, Node node, QName type) {
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
         try {
+            Thread.currentThread().setContextClassLoader(xpath.getClass().getClassLoader());
             return xpath.evaluate(xpathExpression, node, type);
         } catch (Exception e) {
             return null;
+        } finally {
+            Thread.currentThread().setContextClassLoader(loader);
         }
     }
     public NodeList getValueList(String xpathExpression, Node node) {
@@ -72,7 +75,4 @@ public class XPathUtils {
         return getValue(xpathExpression, node, type) != null;
     }
 
-    public static XPathFactory getFactory() {
-        return FACTORY;
-    }
 }

Modified: cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java?rev=1090633&r1=1090632&r2=1090633&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
(original)
+++ cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
Sat Apr  9 17:19:56 2011
@@ -50,6 +50,7 @@ import javax.xml.validation.SchemaFactor
 import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathFactory;
 
 
 import org.w3c.dom.Attr;
@@ -100,7 +101,6 @@ import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.FileUtils;
 import org.apache.cxf.helpers.XMLUtils;
-import org.apache.cxf.helpers.XPathUtils;
 import org.apache.cxf.resource.URIResolver;
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.service.model.ServiceInfo;
@@ -474,7 +474,7 @@ public class JAXBDataBinding implements 
                 String s = r.getAttributeValue(null, "schemaLocation");
                 if (StringUtils.isEmpty(s)) {
                     Document d = StaxUtils.read(r);
-                    XPath p = XPathUtils.getFactory().newXPath();
+                    XPath p = XPathFactory.newInstance().newXPath();
                     p.setNamespaceContext(new W3CNamespaceContext(d.getDocumentElement()));
                     XPathExpression xpe = p.compile(d.getDocumentElement().getAttribute("node"));
                     for (XmlSchema schema : schemas.getXmlSchemas()) {



Mime
View raw message