[jboss-svn-commits] JBL Code SVN: r34635 - in labs/jbossesb/branches/JBESB_4_7_CP/product: rosetta/src/org/jboss/soa/esb/dom and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Aug 11 06:32:54 EDT 2010


Author: kevin.conner at jboss.com
Date: 2010-08-11 06:32:54 -0400 (Wed, 11 Aug 2010)
New Revision: 34635

Modified:
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/soap/OGNLUtils.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/dom/YADOMUtil.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/soap/OGNLUtilsUnitTest.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/soap/ognl-test-01.xml
   labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java
Log:
Pulled across fix for OGNLUtils.assertIsCollection fails: JBESB-3453

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/soap/OGNLUtils.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/soap/OGNLUtils.java	2010-08-11 05:23:02 UTC (rev 34634)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/soap/OGNLUtils.java	2010-08-11 10:32:54 UTC (rev 34635)
@@ -22,6 +22,7 @@
     public static final String JBOSSESB_SOAP_NS_PREFIX = "jbossesb-soap:";
     public static final String OGNL_ATTRIB = "ognl";
     public static final String IS_COLLECTION_ATTRIB = "is-collection";
+    public static final String SOAPUI_CLONE_COMMENT = " repetitions:";
     
     private enum SOAPNameSpaces 
     { 
@@ -153,13 +154,19 @@
             return true;
         }
 
-        Comment firstComment = (Comment) YADOMUtil.getFirstChildByType(element, Node.COMMENT_NODE);
-
-        // TODO: Get Ole (soapUI) to add an attribute to the collection element - better than looking for this comment.
-        if(firstComment != null && firstComment.getTextContent().indexOf("1 or more repetitions") != -1) {
-            return true;
+        Comment comment = (Comment)YADOMUtil.getFirstChildByType(element, Node.COMMENT_NODE);
+        if (comment != null
+            && comment.getTextContent().endsWith(SOAPUI_CLONE_COMMENT)) {
+            //possible array
+            Element first = YADOMUtil.getFirstChildElement(element);
+            Element last = YADOMUtil.getLastChildElement(element);
+            if (first != null && last != null && first.getTagName().equals(last.getTagName())) {
+                //The children are of same tag so the parent is a collection holder (array)
+                return true;
+            }
         }
 
+
         return false;
     }
 

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/dom/YADOMUtil.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/dom/YADOMUtil.java	2010-08-11 05:23:02 UTC (rev 34634)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/dom/YADOMUtil.java	2010-08-11 10:32:54 UTC (rev 34635)
@@ -47,6 +47,7 @@
 import org.jboss.soa.esb.util.DOMUtil;
 import org.jboss.soa.esb.util.TransformerUtil;
 import org.w3c.dom.Attr;
+import org.w3c.dom.Comment;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
@@ -443,4 +444,68 @@
             target.appendChild((Node)nodeList.get(i));
         }
     }
+
+    /**
+     * Get the comment node before the supplied element.
+     *
+     * @param element The element.
+     * @return The Comment node.
+     */
+    public static Comment getCommentBefore(Element element) {
+        Node sibling = element.getPreviousSibling();
+
+        while(sibling != null) {
+            if(sibling.getNodeType() == Node.COMMENT_NODE) {
+                return (Comment) sibling;
+            } else if(sibling.getNodeType() == Node.TEXT_NODE) {
+                // continue...
+                sibling = sibling.getPreviousSibling();
+            } else {
+                // It's an Element, CData, PI etc
+                return null;
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Get the first child element for the supplied element.
+     *
+     * @param element The element.
+     * @return The child element.
+     */
+    public static Element getFirstChildElement(Element element) {
+        NodeList children = element.getChildNodes();
+        int childCount = children.getLength();
+
+        for(int i = 0; i < childCount; i++) {
+            Node child = children.item(i);
+            if(child.getNodeType() == Node.ELEMENT_NODE) {
+                return (Element) child;
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Get the last child element for the supplied element.
+     *
+     * @param element The element.
+     * @return The child element.
+     */
+    public static Element getLastChildElement(Element element) {
+        NodeList children = element.getChildNodes();
+        int childCount = children.getLength();
+
+        for(int i = (childCount-1); i >= 0; i--) {
+            Node child = children.item(i);
+            if(child.getNodeType() == Node.ELEMENT_NODE) {
+                return (Element) child;
+            }
+        }
+
+        return null;
+    }
 }

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/soap/OGNLUtilsUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/soap/OGNLUtilsUnitTest.java	2010-08-11 05:23:02 UTC (rev 34634)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/soap/OGNLUtilsUnitTest.java	2010-08-11 10:32:54 UTC (rev 34635)
@@ -65,6 +65,9 @@
         node = getNode("/soapenv:Envelope/soapenv:Body/cus:customerOrder/cus:items/cus:item[2]/cus:partNumber");
         final String nameSpace = "http://schemas.xmlsoap.org/soap/envelope/";
         assertEquals("customerOrder.items[1].partNumber", OGNLUtils.getOGNLExpression((Element) node, nameSpace));
+
+        node = getNode("/soapenv:Envelope/soapenv:Body/cus:customerOrder/cus:queryRequest/cus:username");
+        assertEquals("customerOrder.queryRequest.username", OGNLUtils.getOGNLExpression((Element) node));
     }
     
     public void test_checkParentNameSpace( )

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/soap/ognl-test-01.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/soap/ognl-test-01.xml	2010-08-11 05:23:02 UTC (rev 34634)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/soap/ognl-test-01.xml	2010-08-11 10:32:54 UTC (rev 34635)
@@ -22,6 +22,14 @@
                <cus:extensionAmount>?</cus:extensionAmount>
             </cus:item>
          </cus:items>
+         <cus:queryRequest>
+            <cus:username>?</cus:username>
+            <!--1 or more repetitions:-->
+            <cus:productIds>?</cus:productIds>
+            <cus:productIds>?</cus:productIds>
+            <cus:isLookup>?</cus:isLookup>
+            <cus:maxWaitTime>?</cus:maxWaitTime>
+        </cus:queryRequest>
       </cus:customerOrder>
    </soapenv:Body>
 </soapenv:Envelope>
\ No newline at end of file

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java	2010-08-11 05:23:02 UTC (rev 34634)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java	2010-08-11 10:32:54 UTC (rev 34635)
@@ -90,8 +90,6 @@
  */
 public class SoapUIClientService extends ServiceMBeanSupport implements SoapUIClientServiceMBean {
 
-    private static final String SOAPUI_CLONE_COMMENT = " repetitions:";
-
     private static final String IS_CLONE_ATTRIB = "is-clone";
     private static Logger logger = Logger.getLogger(SoapUIClientService.class);
     private Map<String, WsdlInterface[]> wsdls = new HashMap<String, WsdlInterface[]>();
@@ -634,17 +632,17 @@
         Comment comment;
 
         // Is it this element...
-        comment = getCommentBefore(element);
-        if(comment != null && comment.getTextContent().endsWith(SOAPUI_CLONE_COMMENT)) {
+        comment = YADOMUtil.getCommentBefore(element);
+        if(comment != null && comment.getTextContent().endsWith(OGNLUtils.SOAPUI_CLONE_COMMENT)) {
             comment.setTextContent(comment.getTextContent() + CLONED_POSTFIX);
             return element;
         }
 
         // Is it the first child element of this element...
-        Element firstChildElement = getFirstChildElement(element);
+        Element firstChildElement = YADOMUtil.getFirstChildElement(element);
         if(firstChildElement != null) {
-            comment = getCommentBefore(firstChildElement);
-            if(comment != null && comment.getTextContent().endsWith(SOAPUI_CLONE_COMMENT)) {
+            comment = YADOMUtil.getCommentBefore(firstChildElement);
+            if(comment != null && comment.getTextContent().endsWith(OGNLUtils.SOAPUI_CLONE_COMMENT)) {
                 comment.setTextContent(comment.getTextContent() + CLONED_POSTFIX);
                 return firstChildElement;
             }
@@ -654,7 +652,7 @@
     }
 
     private void resetClonePoint(Element clonePoint) {
-        Comment comment = getCommentBefore(clonePoint);
+        Comment comment = YADOMUtil.getCommentBefore(clonePoint);
 
         if(comment == null) {
             throw new IllegalStateException("Call to reset a 'clonePoint' that doesn't have a comment before it.");
@@ -668,38 +666,6 @@
         comment.setTextContent(commentText.substring(0, commentText.length() - CLONED_POSTFIX.length()));
     }
 
-    private Comment getCommentBefore(Element element) {
-        Node sibling = element.getPreviousSibling();
-
-        while(sibling != null) {
-            if(sibling.getNodeType() == Node.COMMENT_NODE) {
-                return (Comment) sibling;
-            } else if(sibling.getNodeType() == Node.TEXT_NODE) {
-                // continue...
-                sibling = sibling.getPreviousSibling();
-            } else {
-                // It's an Element, CData, PI etc
-                return null;
-            }
-        }
-
-        return null;
-    }
-
-    private Element getFirstChildElement(Element element) {
-        NodeList children = element.getChildNodes();
-        int childCount = children.getLength();
-
-        for(int i = 0; i < childCount; i++) {
-            Node child = children.item(i);
-            if(child.getNodeType() == Node.ELEMENT_NODE) {
-                return (Element) child;
-            }
-        }
-
-        return null;
-    }
-
     /**
      * Clone a collection node.
      * <p/>



More information about the jboss-svn-commits mailing list