You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2012/03/08 21:07:13 UTC

svn commit: r1298553 - in /webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom: AttrImpl.java AttributeMap.java ChildNode.java ElementImpl.java NodeImpl.java

Author: veithen
Date: Thu Mar  8 20:07:13 2012
New Revision: 1298553

URL: http://svn.apache.org/viewvc?rev=1298553&view=rev
Log:
AXIOM-412: Implemented rule (6) for attribute nodes and moved the ownerNode attribute down from NodeImpl to ChildNode.

Modified:
    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-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java

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=1298553&r1=1298552&r2=1298553&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 Mar  8 20:07:13 2012
@@ -27,6 +27,7 @@ import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
 import org.w3c.dom.Attr;
 import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.TypeInfo;
@@ -62,19 +63,23 @@ public class AttrImpl extends NodeImpl i
     /** Flag to indicate whether this attr is used or not */
     private boolean used;
 
-    /** Owner of this attribute */
-    protected ParentNode parent;
+    /**
+     * Owner of this attribute. This is either the owner element or the owner document (if the
+     * attribute doesn't have an owner element).
+     */
+    private ParentNode owner;
 
     /** Flag used to mark an attribute as per the DOM Level 3 specification */
     protected boolean isId;
 
     protected AttrImpl(DocumentImpl ownerDocument, OMFactory factory) {
-        super(ownerDocument, factory);
+        super(factory);
+        owner = ownerDocument;
     }
 
     public AttrImpl(DocumentImpl ownerDocument, String localName,
                     OMNamespace ns, String value, OMFactory factory) {
-        super(ownerDocument, factory);
+        this(ownerDocument, factory);
         if (ns != null && ns.getNamespaceURI().length() == 0) {
             if (ns.getPrefix().length() > 0) {
                 throw new IllegalArgumentException("Cannot create a prefixed attribute with an empty namespace name");
@@ -90,14 +95,14 @@ public class AttrImpl extends NodeImpl i
 
     public AttrImpl(DocumentImpl ownerDocument, String name, String value,
                     OMFactory factory) {
-        super(ownerDocument, factory);
+        this(ownerDocument, factory);
         this.attrName = name;
         this.attrValue = new TextImpl(ownerDocument, value, factory);
         this.attrType = OMConstants.XMLATTRTYPE_CDATA;
     }
 
     public AttrImpl(DocumentImpl ownerDocument, String name, OMFactory factory) {
-        super(ownerDocument, factory);
+        this(ownerDocument, factory);
         this.attrName = name;
         //If this is a default namespace attr
         if (OMConstants.XMLNS_NS_PREFIX.equals(name)) {
@@ -109,7 +114,7 @@ public class AttrImpl extends NodeImpl i
 
     public AttrImpl(DocumentImpl ownerDocument, String localName,
                     OMNamespace namespace, OMFactory factory) {
-        super(ownerDocument, factory);
+        this(ownerDocument, factory);
         this.attrName = localName;
         this.namespace = (OMNamespaceImpl) namespace;
         this.attrType = OMConstants.XMLATTRTYPE_CDATA;
@@ -180,11 +185,19 @@ public class AttrImpl extends NodeImpl i
      * @see org.w3c.dom.Attr#getOwnerElement()
      */
     public Element getOwnerElement() {
-        // Owned is set to an element instance when the attribute is added to an
-        // element
-        return (Element) (isOwned() ? parent : null);
+        return owner instanceof ElementImpl ? (Element)owner : null;
     }
 
+    void setOwnerElement(ElementImpl element) {
+        if (element == null) {
+            if (owner instanceof ElementImpl) {
+                owner = ((ElementImpl)owner).ownerDocument();
+            }
+        } else {
+            owner = element;
+        }
+    }
+    
     public boolean getSpecified() {
         // Since we don't support DTD or schema, we always return true
         return true;
@@ -352,7 +365,7 @@ public class AttrImpl extends NodeImpl i
             }
         }
         clone.isSpecified(true);
-        clone.parent = null;
+        clone.owner = (DocumentImpl)getOwnerDocument();
         clone.setUsed(false);
         return clone;
     }
@@ -375,6 +388,10 @@ public class AttrImpl extends NodeImpl i
                 + ":" + this.attrName;
     }
 
+    public Document getOwnerDocument() {
+        return owner instanceof ElementImpl ? ((ElementImpl)owner).getOwnerDocument() : (DocumentImpl)owner;
+    }
+
     /**
      * Returns the owner element of this attribute
      * @return OMElement - if the parent OMContainer is an instanceof OMElement
@@ -382,7 +399,7 @@ public class AttrImpl extends NodeImpl i
      * getParent() method.
      */
     public OMElement getOwner() {
-        return (parent instanceof OMElement) ? (OMElement)parent : null;
+        return owner instanceof ElementImpl ? (OMElement)owner : null;
     }
 
     /**

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java?rev=1298553&r1=1298552&r2=1298553&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java Thu Mar  8 20:07:13 2012
@@ -67,7 +67,7 @@ public class AttributeMap extends NamedN
         }
 
         AttrImpl attr = (AttrImpl) attribute;
-        if (attr.isOwned()) { // If the attribute is owned then:
+        if (attr.getOwnerElement() != null) { // If the attribute is owned then:
             if (attr.getOwnerElement() != this.ownerNode) // the owner must be
                 // the owner of this
                 // list
@@ -80,8 +80,7 @@ public class AttributeMap extends NamedN
             // same element
         }
 
-        attr.parent = this.ownerNode; // Set the owner node
-        attr.isOwned(true); // To indicate that this attr belong to an element
+        attr.setOwnerElement((ElementImpl)this.ownerNode); // Set the owner node
         attr.setUsed(true); // Setting used to true
 
         int i = findNamePoint(attr.getNodeName(), 0);
@@ -90,8 +89,7 @@ public class AttributeMap extends NamedN
         if (i >= 0) { // There's an attribute already with this attr's name
             previous = (AttrImpl) nodes.elementAt(i);
             nodes.setElementAt(attr, i);
-            previous.parent = null;
-            previous.isOwned(false);
+            previous.setOwnerElement(null);
 
             // make sure it won't be mistaken with defaults in case it's reused
             previous.isSpecified(true);
@@ -133,7 +131,7 @@ public class AttributeMap extends NamedN
         }
 
         AttrImpl attr = (AttrImpl) attribute;
-        if (attr.isOwned()) { // If the attribute is owned then:
+        if (attr.getOwnerElement() != null) { // If the attribute is owned then:
             //the owner must be the owner of this list
             if (attr.getOwnerElement() != this.ownerNode)
                 throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
@@ -145,9 +143,7 @@ public class AttributeMap extends NamedN
             // same element
         }
         //Set the owner node
-        attr.setOwnerDocument(ownerNode.ownerDocument());
-        attr.parent = this.ownerNode;
-        attr.isOwned(true); // To indicate that this attr belong to an element
+        attr.setOwnerElement((ElementImpl)this.ownerNode);
 
         int i = findNamePoint(attr.getNamespaceURI(), attr.getLocalName());
         AttrImpl previous = null;
@@ -155,9 +151,7 @@ public class AttributeMap extends NamedN
         if (i >= 0) {
             previous = (AttrImpl) nodes.elementAt(i);
             nodes.setElementAt(attr, i);
-            previous.setOwnerDocument(ownerNode.ownerDocument());
-            previous.parent = null;
-            previous.isOwned(false);
+            previous.setOwnerElement(null);
             // make sure it won't be mistaken with defaults in case it's reused
             previous.isSpecified(true);
         } else {
@@ -206,7 +200,6 @@ public class AttributeMap extends NamedN
                     NodeImpl clone = (NodeImpl) n.cloneNode(true);
                     clone.isSpecified(n.isSpecified());
                     nodes.setElementAt(clone, i);
-                    clone.setOwnerDocument(ownerNode.ownerDocument());
                 }
             }
         }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java?rev=1298553&r1=1298552&r2=1298553&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java Thu Mar  8 20:07:13 2012
@@ -34,6 +34,7 @@ import org.apache.axiom.om.impl.MTOMXMLS
 import org.apache.axiom.om.impl.OMNodeEx;
 import org.apache.axiom.om.impl.builder.StAXBuilder;
 import org.apache.axiom.om.util.StAXUtils;
+import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
 public abstract class ChildNode extends NodeImpl {
@@ -42,17 +43,37 @@ public abstract class ChildNode extends 
 
     protected ChildNode nextSibling;
 
+    private DocumentImpl ownerNode;
+
     private ParentNode parentNode;
 
     /** @param ownerDocument  */
     protected ChildNode(DocumentImpl ownerDocument, OMFactory factory) {
-        super(ownerDocument, factory);
+        super(factory);
+        setOwnerDocument(ownerDocument);
     }
 
     protected ChildNode(OMFactory factory) {
         super(factory);
     }
 
+    DocumentImpl ownerDocument() {
+        return ownerNode;
+    }
+    
+    /**
+     * Sets the owner document.
+     *
+     * @param document
+     */
+    void setOwnerDocument(DocumentImpl document) {
+        this.ownerNode = document;
+    }
+
+    public Document getOwnerDocument() {
+        return ownerDocument();
+    }
+
     ParentNode parentNode() {
         return parentNode;
     }
@@ -235,6 +256,7 @@ public abstract class ChildNode extends 
         newnode.previousSibling = null;
         newnode.nextSibling = null;
         newnode.isFirstChild(false);
+        newnode.setOwnerDocument(ownerDocument());
         newnode.parentNode = null;
 
         return newnode;

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1298553&r1=1298552&r2=1298553&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java Thu Mar  8 20:07:13 2012
@@ -439,7 +439,7 @@ public class ElementImpl extends ParentN
     public Attr setAttributeNode(Attr attr) throws DOMException {
         AttrImpl attrImpl = (AttrImpl) attr;
 
-        if (attrImpl.isOwned()) {// check for ownership
+        if (attrImpl.getOwnerElement() != null) {// check for ownership
             if (!this.getOwnerDocument().equals(attr.getOwnerDocument())) {
                 String msg = DOMMessageFormatter.formatMessage(
                         DOMMessageFormatter.DOM_DOMAIN, DOMException.WRONG_DOCUMENT_ERR,
@@ -526,7 +526,7 @@ public class ElementImpl extends ParentN
         } else {
             AttrImpl attrImpl = (AttrImpl) attr;
 
-            if (attrImpl.isOwned()) {// check for ownership
+            if (attrImpl.getOwnerElement() != null) {// check for ownership
                 if (!this.getOwnerDocument().equals(attr.getOwnerDocument())) {
                     String msg = DOMMessageFormatter.formatMessage(
                             DOMMessageFormatter.DOM_DOMAIN,

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java?rev=1298553&r1=1298552&r2=1298553&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java Thu Mar  8 20:07:13 2012
@@ -22,7 +22,6 @@ package org.apache.axiom.om.impl.dom;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.w3c.dom.DOMException;
-import org.w3c.dom.Document;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -41,8 +40,6 @@ public abstract class NodeImpl implement
     /** Field done */
     protected boolean done = false;
 
-    private DocumentImpl ownerNode;
-
     /** Factory that created this node */
     protected final OMFactory factory;
 
@@ -50,8 +47,6 @@ public abstract class NodeImpl implement
 
     protected short flags;
 
-    protected final static short OWNED = 0x1 << 1;
-
     protected final static short FIRSTCHILD = 0x1 << 2;
 
     protected final static short READONLY = 0x1 << 3;
@@ -62,14 +57,6 @@ public abstract class NodeImpl implement
     // Constructors
     //
 
-    protected NodeImpl(DocumentImpl ownerDocument, OMFactory factory) {
-        //this(factory);
-        this.factory = factory;
-        setOwnerDocument(ownerDocument);
-        // this.isOwned(true);
-
-    }
-
     protected NodeImpl(OMFactory factory) {
         this.factory = factory;
     }
@@ -120,14 +107,6 @@ public abstract class NodeImpl implement
     }
 
     /**
-     * Finds the document that this Node belongs to (the document in whose context the Node was
-     * created). The Node may or may not
-     */
-    public Document getOwnerDocument() {
-        return ownerDocument();
-    }
-
-    /**
      * Returns the collection of attributes associated with this node, or null if none. At this
      * writing, Element is the only type of node which will ever have attributes.
      *
@@ -187,8 +166,6 @@ public abstract class NodeImpl implement
         } catch (CloneNotSupportedException e) {
             throw new RuntimeException("**Internal Error**" + e);
         }
-        newnode.setOwnerDocument(ownerDocument());
-        newnode.isOwned(false);
 
         newnode.isReadonly(false);
 
@@ -289,14 +266,6 @@ public abstract class NodeImpl implement
      * Flags setters and getters
      */
 
-    final boolean isOwned() {
-        return (flags & OWNED) != 0;
-    }
-
-    final void isOwned(boolean value) {
-        flags = (short) (value ? flags | OWNED : flags & ~OWNED);
-    }
-
     final boolean isFirstChild() {
         return (flags & FIRSTCHILD) != 0;
     }
@@ -321,19 +290,6 @@ public abstract class NodeImpl implement
         flags = (short) (value ? flags | SPECIFIED : flags & ~SPECIFIED);
     }
 
-    DocumentImpl ownerDocument() {
-        return ownerNode;
-    }
-    
-    /**
-     * Sets the owner document.
-     *
-     * @param document
-     */
-    void setOwnerDocument(DocumentImpl document) {
-        this.ownerNode = document;
-    }
-
     /*
      * DOM-Level 3 methods
      */