cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sea...@apache.org
Subject svn commit: r732411 - in /cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser: Form.java Option.java OptionGroup.java
Date Wed, 07 Jan 2009 18:01:31 GMT
Author: seanoc
Date: Wed Jan  7 10:01:31 2009
New Revision: 732411

URL: http://svn.apache.org/viewvc?rev=732411&view=rev
Log:
More NodeList refactoring

Modified:
    cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/Form.java
    cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/Option.java
    cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/OptionGroup.java

Modified: cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/Form.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/Form.java?rev=732411&r1=732410&r2=732411&view=diff
==============================================================================
--- cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/Form.java
(original)
+++ cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/Form.java
Wed Jan  7 10:01:31 2009
@@ -26,9 +26,9 @@
 
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.tools.common.toolspec.Tool;
 
 
@@ -43,15 +43,24 @@
 
     public Form(Element el) {
         this.element = el;
-        NodeList list = element.getElementsByTagNameNS(Tool.TOOL_SPEC_PUBLIC_ID, "optionGroup");
-
-        for (int i = 0; i < list.getLength(); i++) {
-            optionGroups.add(new OptionGroup((Element)list.item(i)));
-        }
-        list = element.getElementsByTagNameNS(Tool.TOOL_SPEC_PUBLIC_ID, "argument");
-        for (int i = 0; i < list.getLength(); i++) {
-            arguments.add(new Argument((Element)list.item(i)));
+        
+        List<Element> elemList = 
+            DOMUtils.findAllElementsByTagNameNS(element, 
+                                                Tool.TOOL_SPEC_PUBLIC_ID, 
+                                                "optionGroup");
+        
+        for (Element elem : elemList) {
+            optionGroups.add(new OptionGroup(elem));
         }
+        
+        elemList = 
+            DOMUtils.findAllElementsByTagNameNS(element, 
+                                                Tool.TOOL_SPEC_PUBLIC_ID, 
+                                                "argument");
+        for (Element elem : elemList) {
+            arguments.add(new Argument(elem));
+        }     
+        
         getOptions(element);
     }
 

Modified: cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/Option.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/Option.java?rev=732411&r1=732410&r2=732411&view=diff
==============================================================================
--- cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/Option.java
(original)
+++ cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/Option.java
Wed Jan  7 10:01:31 2009
@@ -19,14 +19,15 @@
 
 package org.apache.cxf.tools.common.toolspec.parser;
 
+import java.util.List;
 import java.util.StringTokenizer;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.tools.common.toolspec.Tool;
 
 public class Option implements TokenConsumer {
@@ -42,22 +43,27 @@
 
     public Option(Element el) {
         this.element = el;
-
-        NodeList list = element.getElementsByTagNameNS(Tool.TOOL_SPEC_PUBLIC_ID, "associatedArgument");
-
-        if (list != null && list.getLength() > 0) {
-            argument = (Element)list.item(0);
-        }
-
-        list = element.getElementsByTagNameNS(Tool.TOOL_SPEC_PUBLIC_ID, "annotation");
-        if (list != null && list.getLength() > 0) {
-            annotation = (Element)list.item(0);
+        
+        
+        List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(element, 
+                                                                     Tool.TOOL_SPEC_PUBLIC_ID,

+                                                                     "associatedArgument");
+        if (elemList != null && elemList.size() > 0) {            
+            argument = (Element)elemList.get(0);
+        }
+        
+        elemList = DOMUtils.findAllElementsByTagNameNS(element, 
+                                                       Tool.TOOL_SPEC_PUBLIC_ID, 
+                                                       "annotation");
+        if (elemList != null && elemList.size() > 0) {            
+            annotation = (Element)elemList.get(0);
         }
 
         if (annotation == null && argument != null) {
-            list = argument.getElementsByTagNameNS(Tool.TOOL_SPEC_PUBLIC_ID, "annotation");
-            if (list != null && list.getLength() > 0) {
-                annotation = (Element)list.item(0);
+            elemList =  DOMUtils.findAllElementsByTagNameNS(argument, Tool.TOOL_SPEC_PUBLIC_ID,
"annotation");
+
+            if (elemList != null && elemList.size() > 0) {
+                annotation = (Element)elemList.get(0);
             }
         }
     }
@@ -85,13 +91,14 @@
         }
 
         // go through each switch to see if we can match one to the arg.
-        NodeList switches = element.getElementsByTagNameNS(Tool.TOOL_SPEC_PUBLIC_ID, "switch");
+        List<Element> switches = 
+            DOMUtils.findAllElementsByTagNameNS(element, Tool.TOOL_SPEC_PUBLIC_ID, "switch");
 
         boolean accepted = false;
 
-        for (int i = 0; i < switches.getLength(); i++) {
+        for (Element switchElem : switches) {
 
-            String switchArg = "-" + switches.item(i).getFirstChild().getNodeValue();
+            String switchArg = "-" + switchElem.getFirstChild().getNodeValue();
             if (LOG.isLoggable(Level.FINE)) {
                 LOG.fine("switchArg is " + switchArg);
             }
@@ -152,11 +159,14 @@
     }
 
     private boolean hasInvalidCharacter(String argValue) {
-        NodeList list = argument.getElementsByTagNameNS(Tool.TOOL_SPEC_PUBLIC_ID, "valuetype");
+        
+        List<Element> list = 
+            DOMUtils.findAllElementsByTagNameNS(argument, Tool.TOOL_SPEC_PUBLIC_ID, "valuetype");
+        //NodeList list = argument.getElementsByTagNameNS(Tool.TOOL_SPEC_PUBLIC_ID, "valuetype");
         String valuetypeStr = null;
 
-        if (list != null && list.getLength() > 0) {
-            valueType = (Element)list.item(0);
+        if (list != null && list.size() > 0) {
+            valueType = (Element)list.get(0);
             valuetypeStr = valueType.getFirstChild().getNodeValue();
 
             if ("IdentifyString".equals(valuetypeStr)) {
@@ -176,10 +186,14 @@
     
     private boolean isInEnumArgumentValue(String argValue) {
         boolean result = true;
-        NodeList list = argument.getElementsByTagNameNS(Tool.TOOL_SPEC_PUBLIC_ID, "valueenum");
-        if (list != null && list.getLength() == 1) {
+        List<Element> list = 
+            DOMUtils.findAllElementsByTagNameNS(argument, Tool.TOOL_SPEC_PUBLIC_ID, "valueenum");
+        
+        
+        //NodeList list = argument.getElementsByTagNameNS(Tool.TOOL_SPEC_PUBLIC_ID, "valueenum");
+        if (list != null && list.size() == 1) {
             result = false;
-            String enumValue = list.item(0).getTextContent();
+            String enumValue = list.get(0).getTextContent();
             StringTokenizer stk = new StringTokenizer(enumValue, VALUE_ENUM_SEPARATOR);
             if (stk.countTokens() <= 0) {
                 return result;
@@ -274,11 +288,14 @@
     }
 
     public String getPrimarySwitch() {
-        NodeList switches = element.getElementsByTagNameNS(Tool.TOOL_SPEC_PUBLIC_ID, "switch");
+        //NodeList switches = element.getElementsByTagNameNS(Tool.TOOL_SPEC_PUBLIC_ID, "switch");
+        
+        List<Element> switches = 
+            DOMUtils.findAllElementsByTagNameNS(element, Tool.TOOL_SPEC_PUBLIC_ID, "switch");
 
         // options must have atleast one switch, as enforced by schema, so no
         // need for defensive coding.
-        return switches.item(0).getFirstChild().getNodeValue();
+        return switches.get(0).getFirstChild().getNodeValue();
     }
 
     public String toString() {

Modified: cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/OptionGroup.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/OptionGroup.java?rev=732411&r1=732410&r2=732411&view=diff
==============================================================================
--- cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/OptionGroup.java
(original)
+++ cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/OptionGroup.java
Wed Jan  7 10:01:31 2009
@@ -26,9 +26,9 @@
 import java.util.logging.Logger;
 
 import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.tools.common.toolspec.Tool;
 
 public class OptionGroup implements TokenConsumer {
@@ -40,10 +40,13 @@
 
     public OptionGroup(Element el) {
         this.element = el;
-        NodeList optionEls = element.getElementsByTagNameNS(Tool.TOOL_SPEC_PUBLIC_ID, "option");
-
-        for (int i = 0; i < optionEls.getLength(); i++) {
-            options.add(new Option((Element)optionEls.item(i)));
+        
+        List<Element> optionEls = 
+            DOMUtils.findAllElementsByTagNameNS(element, 
+                                                Tool.TOOL_SPEC_PUBLIC_ID, 
+                                                "option");        
+        for (Element elem : optionEls) {
+            options.add(new Option(elem));
         }
     }
 



Mime
View raw message