Author: veithen
Date: Sun Dec 14 13:54:20 2008
New Revision: 726547

URL: http://svn.apache.org/viewvc?rev=726547&view=rev
Log:
Refactored duplicate code into separate method.

Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeListImpl.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeListImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeListImpl.java?rev=726547&r1=726546&r2=726547&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeListImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeListImpl.java
 Sun Dec 14 13:54:20 2008
@@ -60,30 +60,33 @@
         }
     }
 
-    /**
-     * Returns the number of nodes.
-     *
-     * @see org.w3c.dom.NodeList#getLength()
-     */
-    public int getLength() {
-        Iterator children;
+    private Iterator getIterator() {
         if (this.tagName == null) {
-            children = ((OMContainerEx) rootNode).getChildren();
+            return ((OMContainerEx) rootNode).getChildren();
         } else if (!enableNS) {
-            children = ((OMContainerEx) rootNode)
+            return ((OMContainerEx) rootNode)
                     .getChildrenWithName(new QName(this.tagName));
         } else {
             if (DOMUtil.getPrefix(this.tagName) != null) {
-                children = ((OMContainerEx) rootNode)
+                return ((OMContainerEx) rootNode)
                         .getChildrenWithName(new QName(this.nsName, DOMUtil
                                 .getLocalName(this.tagName), DOMUtil
                                 .getPrefix(this.tagName)));
             } else {
-                children = ((OMContainerEx) rootNode)
+                return ((OMContainerEx) rootNode)
                         .getChildrenWithName(new QName(this.nsName, DOMUtil
                                 .getLocalName(this.tagName)));
             }
         }
+    }
+
+    /**
+     * Returns the number of nodes.
+     *
+     * @see org.w3c.dom.NodeList#getLength()
+     */
+    public int getLength() {
+        Iterator children = getIterator();
         int count = 0;
         while (children.hasNext()) {
             count++;
@@ -98,26 +101,7 @@
      * @see org.w3c.dom.NodeList#item(int)
      */
     public Node item(int index) {
-        Iterator children;
-
-        if (this.tagName == null) {
-            children = ((OMContainerEx) rootNode).getChildren();
-        } else if (!enableNS) {
-            children = ((OMContainerEx) rootNode)
-                    .getChildrenWithName(new QName(this.tagName));
-        } else {
-            if (DOMUtil.getPrefix(this.tagName) != null) {
-                children = ((OMContainerEx) rootNode)
-                        .getChildrenWithName(new QName(this.nsName, DOMUtil
-                                .getLocalName(this.tagName), DOMUtil
-                                .getPrefix(this.tagName)));
-            } else {
-                children = ((OMContainerEx) rootNode)
-                        .getChildrenWithName(new QName(this.nsName, DOMUtil
-                                .getLocalName(this.tagName)));
-            }
-        }
-
+        Iterator children = getIterator();
         int count = 0;
         while (children.hasNext()) {
             if (count == index) {


Reply via email to