[jboss-svn-commits] JBL Code SVN: r38410 - labs/jbossesb/branches/JBESB_4_11_CP2/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Sep 6 16:42:21 EDT 2013


Author: tcunning
Date: 2013-09-06 16:42:21 -0400 (Fri, 06 Sep 2013)
New Revision: 38410

Modified:
   labs/jbossesb/branches/JBESB_4_11_CP2/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java
Log:
JBESB-3950
Add a config option for omitting empty objects for optional fields.


Modified: labs/jbossesb/branches/JBESB_4_11_CP2/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP2/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java	2013-09-03 15:58:50 UTC (rev 38409)
+++ labs/jbossesb/branches/JBESB_4_11_CP2/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java	2013-09-06 20:42:21 UTC (rev 38410)
@@ -111,6 +111,7 @@
     private static Logger logger = Logger.getLogger(SoapUIClientService.class);
     private final WsdlCache wsdlCache;
     private final SmooksCache smooksCache;
+    private boolean omitNullMappedElements;
     private static final String SOAPUI_OPTIONAL_COMMENT = "Optional:";
     private static final String REMOVE_POSTFIX = " to be removed";
     private static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
@@ -151,6 +152,9 @@
         smooksCache = new SmooksCache(smooksLRUCacheSize);
         final int wsdlLRUCacheSize = properties.getIntProperty("wsdl.lru.cache.size", 30);
         wsdlCache = new WsdlCache(wsdlLRUCacheSize);
+        
+        String nullMappedElements = properties.getProperty("omit.null.mapped.elements", "false");
+        omitNullMappedElements = Boolean.parseBoolean(nullMappedElements);
     }
 
     protected void startService() throws Exception {
@@ -989,6 +993,39 @@
                                 //If it is required generate empty element
                                 //Remove the soapUI's '?' text
                                 element.removeChild(node);
+                                
+                                if (omitNullMappedElements) {
+                                    if ((params.containsKey(element.getNodeName()) && (params.get(element.getNodeName()) == null))) {
+                                        parent.removeChild(element);                
+                                        
+                                        Node myEl = parent;
+                                        boolean stillOptional = true;
+                                        
+                                        // Run through parent tree and make sure we delete any parents that also are null
+                                        // and that are optional
+                                        while ((myEl != null) && (stillOptional)) {
+                                            Comment myComment = YADOMUtil.getCommentBefore((Element)myEl);
+                                            if(myComment != null && myComment.getTextContent().endsWith(SOAPUI_OPTIONAL_COMMENT)) {
+                                                //If it is optional do not generate the element
+        
+                                                if (    (params.containsKey(myEl.getNodeName())) &&
+                                                        (params.get(myEl.getNodeName()) == null) && 
+                                                        (myEl.getAttributes().getLength() == 0) ) {
+                                                    Node childToRemove = myEl;
+                                                    
+                                                    // Remove both the element and the comment
+                                                    myEl = myEl.getParentNode();                    
+                                                    myEl.removeChild(childToRemove);
+                                                    myEl.removeChild(myComment);
+                                                } else {
+                                                    stillOptional = false;
+                                                }
+                                            } else {
+                                                stillOptional = false;
+                                            }
+                                        }
+                                    }
+                                }
                             }
                         }
                     } else {



More information about the jboss-svn-commits mailing list