Author: scheu
Date: Wed Oct 10 12:32:15 2007
New Revision: 583588

URL: http://svn.apache.org/viewvc?rev=583588&view=rev
Log:
WSCOMMONS-256
Contributor:Rich Scheuerle
Added iterators for getting child elements that match a certain local name or 
namespace.
Added deprecated iterator for the old qname equality code.  This is not used in 
Axiom, but we have some customers that had a dependency on the old algorithm.

kudos to Mike and Glen

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenLegacyQNameIterator.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenLocalNameIterator.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenNamespaceIterator.java
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenQNameIterator.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java?rev=583588&r1=583587&r2=583588&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
 Wed Oct 10 12:32:15 2007
@@ -45,6 +45,25 @@
      * @return Returns an iterator of [EMAIL PROTECTED] OMElement} items that 
match the given QName
      */
     Iterator getChildrenWithName(QName elementQName);
+    
+    /**
+     * Returns an iterator for child nodes matching the local name.
+     * <p/>
+     *
+     * @param localName 
+     * @return Returns an iterator of [EMAIL PROTECTED] OMElement} items that 
match the given localName
+     */
+    Iterator getChildrenWithLocalName(String localName);
+    
+    /**
+     * Returns an iterator for child nodes matching the namespace uri.
+     * <p/>
+     *
+     * @param uri 
+     * @return Returns an iterator of [EMAIL PROTECTED] OMElement} items that 
match the given uri
+     */
+    Iterator getChildrenWithNamespaceURI(String uri);
+    
 
     /**
      * Returns the first child in document order that matches the given QName

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java?rev=583588&r1=583587&r2=583588&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
 Wed Oct 10 12:32:15 2007
@@ -40,7 +40,7 @@
      * @see #getChildrenWithName(javax.xml.namespace.QName)
      */
     Iterator getChildElements();
-
+    
     /**
      * Creates a namespace in the current element scope.
      *

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenLegacyQNameIterator.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenLegacyQNameIterator.java?rev=583588&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenLegacyQNameIterator.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenLegacyQNameIterator.java
 Wed Oct 10 12:32:15 2007
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.om.impl.traverse;
+
+import org.apache.axiom.om.OMNode;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Iterate over elements with the QName that uses the 
+ * legacy algorithm.  This iterator is only retained for migrating
+ * some existing customers that have a dependency on the old algorithm
+ * @deprecated
+ */
+public class OMChildrenLegacyQNameIterator extends OMChildrenQNameIterator {
+
+    public OMChildrenLegacyQNameIterator(OMNode currentChild, QName qName) {
+        super(currentChild, qName);
+    }
+
+    /**
+     * This version of equals returns true if the local parts match.
+     * 
+     * @param searchQName
+     * @param currentQName
+     * @return true if equals
+     */
+    public boolean isEquals(QName searchQName, QName currentQName) {
+        // if the given localname is null, whatever value this.qname has, its 
a match. 
+        // But can one give a QName without a localName ??
+        String localPart = searchQName.getLocalPart();
+        boolean localNameMatch =(localPart == null) || (localPart.equals("")) 
||
+            ((currentQName != null) && 
currentQName.getLocalPart().equals(localPart));
+        
+        String namespaceURI = searchQName.getNamespaceURI();
+        boolean namespaceURIMatch = (namespaceURI == null) || 
(namespaceURI.equals(""))||
+            ((currentQName != null) && 
currentQName.getNamespaceURI().equals(namespaceURI));
+        return localNameMatch && namespaceURIMatch;
+    }
+}

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenLocalNameIterator.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenLocalNameIterator.java?rev=583588&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenLocalNameIterator.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenLocalNameIterator.java
 Wed Oct 10 12:32:15 2007
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.om.impl.traverse;
+
+import org.apache.axiom.om.OMNode;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Iterate over elements with the same LocalName
+ *
+ */
+public class OMChildrenLocalNameIterator extends OMChildrenQNameIterator {
+
+    public OMChildrenLocalNameIterator(OMNode currentChild, String localName) {
+        super(currentChild, new QName("", localName));
+    }
+
+    /**
+     * This version of equals returns true if the local parts match.
+     * 
+     * @param searchQName
+     * @param currentQName
+     * @return true if equals
+     */
+    public boolean isEquals(QName searchQName, QName currentQName) {
+        return searchQName.getLocalPart().equals(searchQName.getLocalPart());
+    }
+}

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenNamespaceIterator.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenNamespaceIterator.java?rev=583588&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenNamespaceIterator.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenNamespaceIterator.java
 Wed Oct 10 12:32:15 2007
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.om.impl.traverse;
+
+import org.apache.axiom.om.OMNode;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Iterate over elements with the same namespace uri
+ *
+ */
+public class OMChildrenNamespaceIterator extends OMChildrenQNameIterator {
+
+    public OMChildrenNamespaceIterator(OMNode currentChild, String uri) {
+        super(currentChild, new QName(uri, "dummyName"));
+    }
+
+    /**
+     * This version of equals returns true if the local parts match.
+     * 
+     * @param searchQName
+     * @param currentQName
+     * @return true if equals
+     */
+    public boolean isEquals(QName searchQName, QName currentQName) {
+        return 
searchQName.getNamespaceURI().equals(searchQName.getNamespaceURI());
+    }
+}

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenQNameIterator.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenQNameIterator.java?rev=583588&r1=583587&r2=583588&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenQNameIterator.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMChildrenQNameIterator.java
 Wed Oct 10 12:32:15 2007
@@ -24,10 +24,16 @@
 
 import javax.xml.namespace.QName;
 
-/** Class OMChildrenQNameIterator */
+/** 
+ * Class OMChildrenQNameIterator
+ * 
+ * This iterator returns the elements that have a matching QName.
+ * This class can be extended to customize the QName equality.
+ *
+ */
 public class OMChildrenQNameIterator extends OMChildrenIterator {
     /** Field givenQName */
-    private QName givenQName;
+    private final QName givenQName;
 
     /** Field needToMoveForward */
     private boolean needToMoveForward = true;
@@ -45,6 +51,18 @@
         super(currentChild);
         this.givenQName = givenQName;
     }
+    
+    /**
+     * Returns true if the qnames are equal.
+     * The default algorithm is to use the QName equality (which examines the 
namespace and localPart).
+     * You can extend this class to provide your own equality algorithm.
+     * @param searchQName
+     * @param currentQName
+     * @return true if qnames are equal.
+     */
+    public boolean isEqual(QName searchQName, QName currentQName) {
+        return searchQName.equals(currentQName);
+    }
 
     /**
      * Returns <tt>true</tt> if the iteration has more elements. (In other 
words, returns
@@ -58,7 +76,8 @@
                 // check the current node for the criteria
                 if (currentChild instanceof OMElement) {
                     QName thisQName = ((OMElement)currentChild).getQName();
-                    if (givenQName == null || thisQName.equals(givenQName)) {
+                    // A null givenName is an indicator to return all elements
+                    if (givenQName == null || isEqual(givenQName, thisQName)) {
                         isMatchingNodeFound = true;
                         needToMoveForward = false;
                         break;
@@ -93,4 +112,29 @@
         currentChild = currentChild.getNextOMSibling();
         return lastChild;
     }
+    
+    /**
+     * Prior versions of the OMChildrenQNameIterator used the following
+     * logic to check equality.  This algorithm is incorrect; however some 
customers
+     * have dependency on this behavior.  This method is retained (but 
deprecated) to allow
+     * them an opportunity to use the old algorithm.
+     * 
+     * @param searchQName
+     * @param currentQName
+     * @return true using legacy equality match
+     * @deprecated
+     */
+    public static boolean isEquals_Legacy(QName searchQName, QName 
currentQName) {
+        
+        // if the given localname is null, whatever value this.qname has, its 
a match. But can one give a QName without a localName ??
+        String localPart = searchQName.getLocalPart();
+        boolean localNameMatch =(localPart == null) || (localPart.equals("")) 
||
+            ((currentQName != null) && 
currentQName.getLocalPart().equals(localPart));
+        String namespaceURI = searchQName.getNamespaceURI();
+        boolean namespaceURIMatch = (namespaceURI == null) || 
(namespaceURI.equals(""))||
+            ((currentQName != null) && 
currentQName.getNamespaceURI().equals(namespaceURI));
+        return localNameMatch && namespaceURIMatch;
+    }
+    
+    
 }

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java?rev=583588&r1=583587&r2=583588&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
 Wed Oct 10 12:32:15 2007
@@ -31,6 +31,8 @@
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.impl.dom.factory.OMDOMFactory;
 import org.apache.axiom.om.impl.traverse.OMChildrenIterator;
+import org.apache.axiom.om.impl.traverse.OMChildrenLocalNameIterator;
+import org.apache.axiom.om.impl.traverse.OMChildrenNamespaceIterator;
 import org.apache.axiom.om.impl.traverse.OMChildrenQNameIterator;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Document;
@@ -90,6 +92,17 @@
      */
     public Iterator getChildrenWithName(QName elementQName) throws OMException 
{
         return new OMChildrenQNameIterator(getFirstOMChild(), elementQName);
+    }
+    
+    public Iterator getChildrenWithLocalName(String localName) {
+        return new OMChildrenLocalNameIterator(getFirstOMChild(),
+                                               localName);
+    }
+
+
+    public Iterator getChildrenWithNamespaceURI(String uri) {
+        return new OMChildrenNamespaceIterator(getFirstOMChild(),
+                                               uri);
     }
 
     /**

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java?rev=583588&r1=583587&r2=583588&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
 Wed Oct 10 12:32:15 2007
@@ -30,6 +30,8 @@
 import org.apache.axiom.om.impl.OMContainerEx;
 import org.apache.axiom.om.impl.OMNodeEx;
 import org.apache.axiom.om.impl.traverse.OMChildrenIterator;
+import org.apache.axiom.om.impl.traverse.OMChildrenLocalNameIterator;
+import org.apache.axiom.om.impl.traverse.OMChildrenNamespaceIterator;
 import org.apache.axiom.om.impl.traverse.OMChildrenQNameIterator;
 
 import javax.xml.namespace.QName;
@@ -229,6 +231,16 @@
                                            elementQName);
     }
 
+    public Iterator getChildrenWithLocalName(String localName) {
+        return new OMChildrenLocalNameIterator(getFirstOMChild(),
+                                               localName);
+    }
+
+
+    public Iterator getChildrenWithNamespaceURI(String uri) {
+        return new OMChildrenNamespaceIterator(getFirstOMChild(),
+                                               uri);
+    }
     /**
      * Method getFirstOMChild.
      *

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=583588&r1=583587&r2=583588&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
 Wed Oct 10 12:32:15 2007
@@ -37,6 +37,9 @@
 import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory;
 import org.apache.axiom.om.impl.traverse.OMChildElementIterator;
 import org.apache.axiom.om.impl.traverse.OMChildrenIterator;
+import org.apache.axiom.om.impl.traverse.OMChildrenLegacyQNameIterator;
+import org.apache.axiom.om.impl.traverse.OMChildrenLocalNameIterator;
+import org.apache.axiom.om.impl.traverse.OMChildrenNamespaceIterator;
 import org.apache.axiom.om.impl.traverse.OMChildrenQNameIterator;
 import org.apache.axiom.om.impl.util.EmptyIterator;
 import org.apache.axiom.om.impl.util.OMSerializerUtil;
@@ -208,7 +211,27 @@
     public Iterator getChildrenWithName(QName elementQName) {
         return new OMChildrenQNameIterator(getFirstOMChild(),
                                            elementQName);
+        
+        // The semantics of this call was changed.
+        // The original sematics had a looser definition of QName equality.
+        // To get this original functionality use:
+        /*
+        return new OMChildrenLegacyQNameIterator(getFirstOMChild(), 
elementQName);
+        */
     }
+    
+
+    public Iterator getChildrenWithLocalName(String localName) {
+        return new OMChildrenLocalNameIterator(getFirstOMChild(),
+                                               localName);
+    }
+
+
+    public Iterator getChildrenWithNamespaceURI(String uri) {
+        return new OMChildrenNamespaceIterator(getFirstOMChild(),
+                                               uri);
+    }
+
 
     /**
      * Method getFirstChildWithName.

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=583588&r1=583587&r2=583588&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
 Wed Oct 10 12:32:15 2007
@@ -61,6 +61,7 @@
  * heavy overhead penalty, so should be avoided if possible.</p>
  */
 public class OMSourcedElementImpl extends OMElementImpl implements 
OMSourcedElement {
+    
     /** Data source for element data. */
     private OMDataSource dataSource;
 
@@ -768,6 +769,16 @@
     public Iterator getChildrenWithName(QName elementQName) {
         forceExpand();
         return super.getChildrenWithName(elementQName);
+    }
+    
+    public Iterator getChildrenWithLocalName(String localName) {
+        forceExpand();
+        return super.getChildrenWithLocalName(localName);
+    }
+
+    public Iterator getChildrenWithNamespaceURI(String uri) {
+        forceExpand();
+        return super.getChildrenWithNamespaceURI(uri);
     }
 
     /* (non-Javadoc)



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to