You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2010/01/14 22:47:01 UTC

svn commit: r899428 - in /cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal: WSDLRefValidator.java model/XNode.java

Author: dkulp
Date: Thu Jan 14 21:47:00 2010
New Revision: 899428

URL: http://svn.apache.org/viewvc?rev=899428&view=rev
Log:
Using full XPaths for wsdl validation when they are very simple is
apparently VERY expensive.   Do a much quicker basic search.   A very
complex wsdl I have (500+ operations, 3000+ classes generated) now
does a wsdl2java in 30 secs compared to over 2 minutes.

Modified:
    cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDLRefValidator.java
    cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XNode.java

Modified: cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDLRefValidator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDLRefValidator.java?rev=899428&r1=899427&r2=899428&view=diff
==============================================================================
--- cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDLRefValidator.java (original)
+++ cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDLRefValidator.java Thu Jan 14 21:47:00 2010
@@ -201,10 +201,8 @@
     }
 
     private boolean isExist(List<Document> docs, XNode vNode) {
-        XPathUtils xpather = new XPathUtils(vNode.getNSMap());
-        String expression = vNode.toString();
         for (Document doc : docs) {
-            if (xpather.isExist(expression, doc, XPathConstants.NODE)) {
+            if (vNode.matches(doc)) {
                 return true;
             }
         }
@@ -239,8 +237,8 @@
 
             List<Document> wsdlDocs = getWSDLDocuments();
             for (XNode vNode : vNodes) {
-
                 if (!isExist(wsdlDocs, vNode)) {
+                    //System.out.println("Fail: " + vNode.getXPath());
                     FailureLocation loc = getFailureLocation(wsdlDocs, vNode.getFailurePoint());
 
                     vResults.addError(new Message("FAILED_AT_POINT",

Modified: cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XNode.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XNode.java?rev=899428&r1=899427&r2=899428&view=diff
==============================================================================
--- cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XNode.java (original)
+++ cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/model/XNode.java Thu Jan 14 21:47:00 2010
@@ -24,6 +24,10 @@
 import java.util.Stack;
 import javax.xml.namespace.QName;
 
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
 import org.apache.cxf.common.util.StringUtils;
 
 public class XNode {
@@ -165,4 +169,53 @@
         nsMap.put(prefix, name.getNamespaceURI());
         return sb.toString();
     }
+
+    
+    private boolean matches(Element el) { 
+        if (el.getLocalName().equals(name.getLocalPart())
+            && el.getNamespaceURI().equals(name.getNamespaceURI())) {
+            if (!StringUtils.isEmpty(attributeName) && !StringUtils.isEmpty(attributeValue)) {
+                String v = el.getAttribute(attributeName);
+                if (attributeValue.equals(v) || (StringUtils.isEmpty(v) && isDefaultAttributeValue)) {
+                    return true;
+                }
+            } else {
+                return true;
+            }
+        }
+        return false;
+    }
+    private boolean matches(Element el, Stack<XNode> stack) {
+        if (matches(el)) {
+            if (stack.isEmpty()) {
+                return true;
+            }
+            XNode next = stack.pop();
+            Node nd = el.getFirstChild();
+            while (nd != null) {
+                if (nd instanceof Element) {
+                    el = (Element)nd;
+                    if (next.matches(el, stack)) {
+                        return true;
+                    }
+                }
+                nd = nd.getNextSibling();
+            }
+            stack.push(next);
+        }
+        return false;
+    }
+    
+    public boolean matches(Document doc) {
+        Stack<XNode> nodes = new Stack<XNode>();
+        nodes.push(this);
+        XNode pNode = getParentNode();
+        while (pNode != null) {
+            nodes.push(pNode);
+            pNode = pNode.getParentNode();
+        }
+        pNode = nodes.pop();
+        return pNode.matches(doc.getDocumentElement(), nodes);
+        
+    }
 }