cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1428398 - /cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java
Date Thu, 03 Jan 2013 15:23:09 GMT
Author: dkulp
Date: Thu Jan  3 15:23:09 2013
New Revision: 1428398

URL: http://svn.apache.org/viewvc?rev=1428398&view=rev
Log:
Bunch of optimizations for the Aegis XMLTypeCreator to delay creating the XPathUtils and to
cache which documents could NOT be found instead of trying to repeatedly find it.

Modified:
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java?rev=1428398&r1=1428397&r2=1428398&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java
Thu Jan  3 15:23:09 2013
@@ -135,7 +135,13 @@ public class XMLTypeCreator extends Abst
         }
     }
     
-    private XPathUtils xpathUtils = new XPathUtils();
+    private volatile XPathUtils xpathUtils;
+    private synchronized XPathUtils getXPathUtils() {
+        if (xpathUtils == null) {
+            xpathUtils = new XPathUtils();
+        }
+        return xpathUtils;
+    }
 
     private Document readAegisFile(InputStream is, final String path) throws IOException
{
         DocumentBuilder documentBuilder;
@@ -195,23 +201,24 @@ public class XMLTypeCreator extends Abst
         if (clazz == null) {
             return null;
         }
-        Document doc = documents.get(clazz.getName());
-        if (doc != null) {
-            return doc;
+        if (documents.containsKey(clazz.getName())) {
+            return documents.get(clazz.getName());
         }
         String path = '/' + clazz.getName().replace('.', '/') + ".aegis.xml";
         InputStream is = clazz.getResourceAsStream(path);
         if (is == null) {
+            documents.put(clazz.getName(), null);
             LOG.finest("Mapping file : " + path + " not found.");
             return null;
         }
         LOG.finest("Found mapping file : " + path);
         try {
-            doc = readAegisFile(is, path);
+            Document doc = readAegisFile(is, path);
             documents.put(clazz.getName(), doc);
             return doc;
         } catch (IOException e) {
             LOG.log(Level.SEVERE, "Error loading file " + path, e);
+            documents.put(clazz.getName(), null);
             return null;
         }
     }
@@ -714,11 +721,11 @@ public class XMLTypeCreator extends Abst
     }
 
     private Element getMatch(Node doc, String xpath) {
-        return (Element)xpathUtils.getValue(xpath, doc, XPathConstants.NODE);
+        return (Element)getXPathUtils().getValue(xpath, doc, XPathConstants.NODE);
     }
 
     private List<Element> getMatches(Node doc, String xpath) {
-        NodeList nl = (NodeList)xpathUtils.getValue(xpath, doc, XPathConstants.NODESET);
+        NodeList nl = (NodeList)getXPathUtils().getValue(xpath, doc, XPathConstants.NODESET);
         List<Element> r = new ArrayList<Element>();
         for (int x = 0; x < nl.getLength(); x++) {
             r.add((Element)nl.item(x));



Mime
View raw message