ws-commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ruchi...@apache.org
Subject svn commit: r627957 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-api/src/main/java/org/apache/axiom/om/ds/ axiom-api/src/main/java/org/apache/axiom/om/xpath/ axiom-dom/src/main/java/org/apach...
Date Fri, 15 Feb 2008 06:22:49 GMT
Author: ruchithf
Date: Thu Feb 14 22:22:45 2008
New Revision: 627957

URL: http://svn.apache.org/viewvc?rev=627957&view=rev
Log:
Applied Saliya's patch to WSCOMMONS-230

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMAttribute.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/InputStreamDataSource.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/DocumentNavigator.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMAttribute.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMAttribute.java?rev=627957&r1=627956&r2=627957&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMAttribute.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMAttribute.java
Thu Feb 14 22:22:45 2008
@@ -46,4 +46,10 @@
 
     /** Returns the OMFactory that created this object */
     OMFactory getOMFactory();
+
+    /**
+     * Returns the owner element of this attribute
+     * @return OMElement - The owner element
+     */
+    OMElement getOwner();
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/InputStreamDataSource.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/InputStreamDataSource.java?rev=627957&r1=627956&r2=627957&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/InputStreamDataSource.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/InputStreamDataSource.java
Thu Feb 14 22:22:45 2008
@@ -131,7 +131,7 @@
         try {
             serialize(baos, format);
         } catch (XMLStreamException e) {
-            new OMException(e);
+            throw new OMException(e);
         }
         return baos.toByteArray();
     }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/DocumentNavigator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/DocumentNavigator.java?rev=627957&r1=627956&r2=627957&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/DocumentNavigator.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/DocumentNavigator.java
Thu Feb 14 22:22:45 2008
@@ -762,6 +762,18 @@
         public OMFactory getOMFactory() {
             return this.factory;
         }
+
+        /**
+         * Returns the owner element of this attribute
+         * 
+         * @return OMElement If the parent <code>OMContainer</code> is an
+         * instanceof <code>OMElement</code> we return that element else
+         * we return null. To get the <code>OMContainer</code> itself use
+         * the <code>getParent()</code> method.
+         */
+        public OMElement getOwner() {
+            return (parent instanceof OMElement) ? (OMElement)parent : null;
+        }
     }
 }
 

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java?rev=627957&r1=627956&r2=627957&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
Thu Feb 14 22:22:45 2008
@@ -18,13 +18,8 @@
  */
 package org.apache.axiom.om.impl.dom;
 
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMConstants;
-import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.*;
+import org.apache.axiom.om.xpath.DocumentNavigator;
 import org.w3c.dom.Attr;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Element;
@@ -398,6 +393,77 @@
         return (this.namespace == null) ? this.attrName : this.namespace
                 .getPrefix()
                 + ":" + this.attrName;
+    }
+
+    /**
+     * Returns the owner element of this attribute
+     * @return OMElement - if the parent OMContainer is an instanceof OMElement
+     * we return that OMElement else return null. To get the OMContainer itself use
+     * getParent() method.
+     */
+    public OMElement getOwner() {
+        return (parent instanceof OMElement) ? (OMElement)parent : null;
+    }
+
+    /**
+     * An instance of <code>AttrImpl</code> can act as an <code>OMAttribute</code>
and as well as an
+     * <code>org.w3c.dom.Attr</code>. So we first check if the object to compare
with (<code>obj</code>)
+     * is of type <code>OMAttribute</code> (this includes instances of <code>OMAttributeImpl</code>
or
+     * <code>AttrImpl</code> (instances of this class)). If so we check for the
equality
+     * of namespaces first (note that if the namespace of this instance is null then for
the <code>obj</code>
+     * to be equal its namespace must also be null). This condition solely doesn't determine
the equality.
+     * So we check for the equality of names and values (note that the value can also be
null in which case
+     * the same argument holds as that for the namespace) of the two instances. If all three
conditions are
+     * met then we say the two instances are equal.
+     *
+     * <p>If <code>obj</code> is of type <code>org.w3c.dom.Attr</code>
then we perform the same equality check
+     * as before. Note that, however, the implementation of the test for equality in this
case is little different
+     * than before.
+     *
+     * <p>If <code>obj</code> is neither of type <code>OMAttribute</code>
nor of type <code>org.w3c.dom.Attr</code>
+     * then we return false.
+     *
+     * @param obj The object to compare with this instance
+     * @return True if the two objects are equal or else false. The equality is checked as
explained above.
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof OMAttribute) { // Checks equality of an OMAttributeImpl or an
AttrImpl with this instance
+            OMAttribute other = (OMAttribute) obj;
+            return (namespace == null ? other.getNamespace() == null :
+                    namespace.equals(other.getNamespace()) &&
+                    attrName.equals(other.getLocalName()) &&
+                    (attrValue == null ? other.getAttributeValue() == null :
+                            attrValue.toString().equals(other.getAttributeValue())));
+        } else if (obj instanceof Attr) {// Checks equality of an org.w3c.dom.Attr with this
instance
+            Attr other = (Attr)obj;
+            String otherNs = other.getNamespaceURI();
+            if (namespace == null) { // I don't have a namespace
+                if (otherNs != null) {
+                    return false; // I don't have a namespace and the other has. So return
false
+                } else {
+                    // Both of us don't have namespaces. So check for name and value equality
only
+                    return (attrName.equals(other.getLocalName()) &&
+                            (attrValue == null ? other.getValue() == null :
+                                    attrValue.toString().equals(other.getValue())));
+                }
+            } else { // Ok, now I've a namespace
+                String ns = namespace.getNamespaceURI();
+                String prefix = namespace.getPrefix();
+                String otherPrefix = other.getPrefix();
+                // First check for namespaceURI equality. Then check for prefix equality.
+                // Then check for name and value equality
+                return (ns.equals(otherNs) && (prefix == null ? otherPrefix == null
: prefix.equals(otherPrefix)) &&
+                        (attrName.equals(other.getLocalName())) &&
+                        (attrValue == null ? other.getValue() == null :
+                                attrValue.toString().equals(other.getValue())));
+            }
+        }
+        return false;
+    }
+
+    public int hashCode() {
+        return attrName.hashCode() ^ (attrValue != null ? attrValue.toString().hashCode()
: 0) ^
+                (namespace != null ? namespace.hashCode() : 0);
     }
 
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java?rev=627957&r1=627956&r2=627957&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
Thu Feb 14 22:22:45 2008
@@ -22,6 +22,7 @@
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMElement;
 
 import javax.xml.namespace.QName;
 
@@ -39,6 +40,9 @@
     /** <code>OMFactory</code> that created this <code>OMAttribute</code>
*/
     private OMFactory factory;
 
+    // Keep track of the owner of the attribute
+    protected OMElement owner;
+
     /**
      * Constructor OMAttributeImpl.
      *
@@ -131,6 +135,49 @@
 
     public OMFactory getOMFactory() {
         return this.factory;
+    }
+
+    /**
+     * Returns the owner element of this attribute
+     * @return OMElement - the owner element
+     */
+    public OMElement getOwner() {
+        return owner;
+    }
+
+    /**
+     * Checks for the equality of two <code>OMAttribute</code> instances. Thus
the object to compare
+     * this with may be an instance of <code>OMAttributeImpl</code> (an instance
of this class) or
+     * an instance of <code>AttrImpl</code>. The method returns false for any
object of type other
+     * than <code>OMAttribute</code>.
+     *
+     * <p>We check for the equality of namespaces first (note that if the namespace
of this instance is null
+     * then for the <code>obj</code> to be equal its namespace must also be null).
This condition solely
+     * doesn't determine the equality. So we check for the equality of names and values (note
that the value
+     * can also be null in which case the same argument holds as that for the namespace)
of the two instances.
+     * If all three conditions are met then we say the two instances are equal.
+     *
+     * Note: We ignore the owner when checking for the equality. This is simply because the
owner is
+     * introduced just to keep things simple for the programmer and not as part of an attribute
itself.
+     *
+     * @param obj The object to compare with this instance.
+     * @return True if obj is equal to this or else false.
+     */
+    public boolean equals(Object obj) {
+        if (! (obj instanceof OMAttribute)) return false;
+        OMAttribute other = (OMAttribute)obj;
+        //first check namespace then localName then value to improve performance
+        return (namespace == null ? other.getNamespace() == null :
+                namespace.equals(other.getNamespace()) &&
+                localName.equals(other.getLocalName()) &&
+                (value == null ? other.getAttributeValue() == null :
+                        value.equals(other.getAttributeValue())));
+
+    }
+
+    public int hashCode() {
+        return localName.hashCode() ^ (value != null ? value.hashCode() : 0) ^
+                (namespace != null ? namespace.hashCode() : 0);
     }
 
 }

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=627957&r1=627956&r2=627957&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
Thu Feb 14 22:22:45 2008
@@ -518,9 +518,25 @@
      * Inserts an attribute to this element. Implementor can decide as to insert this in
the front
      * or at the end of set of attributes.
      *
-     * @return Returns attribute.
+     * <p>The owner of the attribute is set to be the particular <code>OMElement</code>.
+     * If the attribute already has an owner then the attribute is cloned (i.e. its name,
+     * value and namespace are copied to a new attribute) and the new attribute is added
+     * to the element. It's owner is then set to be the particular <code>OMElement</code>.
+     * 
+     * @return The attribute that was added to the element. Note: The added attribute
+     * may not be the same instance that was given to add. This can happen if the given
+     * attribute already has an owner. In such case the returned attribute and the given
+     * attribute are <i>equal</i> but not the same instance.
+     *
+     * @see OMAttributeImpl#equals(Object)
      */
-    public OMAttribute addAttribute(OMAttribute attr) {
+    public OMAttribute addAttribute(OMAttribute attr){
+        // If the attribute already has an owner element then clone the attribute
+        if (attr.getOwner() !=null){
+            attr = new OMAttributeImpl(
+                    attr.getLocalName(), attr.getNamespace(), attr.getAttributeValue(), attr.getOMFactory());
+        }
+
         if (attributes == null) {
             this.attributes = new LinkedHashMap(5);
         }
@@ -533,6 +549,8 @@
             this.declareNamespace(nsURI, nsPrefix);
         }
 
+        // Set the owner element of the attribute
+        ((OMAttributeImpl)attr).owner = this;
         attributes.put(attr.getQName(), attr);
         return attr;
     }
@@ -540,14 +558,33 @@
     /** Method removeAttribute. */
     public void removeAttribute(OMAttribute attr) {
         if (attributes != null) {
+            // Remove the owner from this attribute
+            ((OMAttributeImpl)attr).owner = null;
             attributes.remove(attr.getQName());
         }
     }
 
     /**
-     * Method addAttribute.
      *
-     * @return Returns OMAttribute.
+     * Creates an <code>OMAttributeImpl</code> instance out of the given arguments
and
+     * inserts that attribute to this element. Implementor can decide as to insert this
+     * in the front or at the end of set of attributes.
+     *
+     * <p>The owner of the attribute is set to be the particular <code>OMElement</code>.
+     * If the attribute already has an owner then the attribute is cloned (i.e. its name,
+     * value and namespace are copied to a new attribute) and the new attribute is added
+     * to the element. It's owner is then set to be the particular <code>OMElement</code>.
+     *
+     * @param attributeName The name of the attribute
+     * @param value The value of the attribute
+     * @param ns The namespace of the attribute
+     *
+     * @return The attribute that was added to the element. Note: The added attribute
+     * may not be the same instance that was given to add. This can happen if the given
+     * attribute already has an owner. In such case the returned attribute and the given
+     * attribute are <i>equal</i> but not the same instance.
+     *
+     * @see OMAttributeImpl#equals(Object)
      */
     public OMAttribute addAttribute(String attributeName, String value,
                                     OMNamespace ns) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org


Mime
View raw message