ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1298603 - in /webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom: ChildNode.java ElementImpl.java NodeImpl.java
Date Thu, 08 Mar 2012 21:48:20 GMT
Author: veithen
Date: Thu Mar  8 21:48:19 2012
New Revision: 1298603

URL: http://svn.apache.org/viewvc?rev=1298603&view=rev
Log:
AXIOM-412: Implemented rule (6) for non attribute nodes.

Modified:
    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/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=1298603&r1=1298602&r2=1298603&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 21:48:19 2012
@@ -43,9 +43,11 @@ public abstract class ChildNode extends 
 
     protected ChildNode nextSibling;
 
-    private DocumentImpl ownerNode;
-
-    private ParentNode parentNode;
+    /**
+     * The parent or the owner document of the node. The meaning of this attribute depends
on the
+     * {@link NodeImpl#HAS_PARENT} flag.
+     */
+    private ParentNode ownerNode;
 
     /** @param ownerDocument  */
     protected ChildNode(DocumentImpl ownerDocument, OMFactory factory) {
@@ -58,7 +60,15 @@ public abstract class ChildNode extends 
     }
 
     DocumentImpl ownerDocument() {
-        return ownerNode;
+        if (ownerNode == null) {
+            return null;
+        } else if (ownerNode instanceof DocumentImpl) {
+            // Note: the value of the HAS_PARENT flag doesn't matter here. If the ownerNode
is of
+            // type Document, it must be the owner document.
+            return (DocumentImpl)ownerNode;
+        } else {
+            return ownerNode.ownerDocument();
+        }
     }
     
     /**
@@ -67,6 +77,9 @@ public abstract class ChildNode extends 
      * @param document
      */
     void setOwnerDocument(DocumentImpl document) {
+        if (ownerNode != null) {
+            throw new IllegalStateException();
+        }
         this.ownerNode = document;
     }
 
@@ -75,7 +88,7 @@ public abstract class ChildNode extends 
     }
 
     ParentNode parentNode() {
-        return parentNode;
+        return hasParent() ? ownerNode : null;
     }
 
     public OMNode getNextOMSibling() throws OMException {
@@ -138,8 +151,12 @@ public abstract class ChildNode extends 
     }
 
     public void setParent(OMContainer element) {
-        if (element == null || element instanceof ParentNode) {
-            this.parentNode = (ParentNode) element;
+        if (element == null) {
+            ownerNode = ownerDocument();
+            hasParent(false);
+        } else if (element instanceof ParentNode) {
+            ownerNode = (ParentNode) element;
+            hasParent(true);
         } else {
             throw new OMException("The given parent is not of the type "
                     + ParentNode.class);
@@ -256,8 +273,8 @@ public abstract class ChildNode extends 
         newnode.previousSibling = null;
         newnode.nextSibling = null;
         newnode.isFirstChild(false);
-        newnode.setOwnerDocument(ownerDocument());
-        newnode.parentNode = null;
+        newnode.ownerNode = ownerDocument();
+        newnode.hasParent(false);
 
         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=1298603&r1=1298602&r2=1298603&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 21:48:19 2012
@@ -151,7 +151,6 @@ public class ElementImpl extends ParentN
                        OMXMLParserWrapper builder, OMFactory factory) {
         this(tagName, ns, builder, factory);
         if (parentNode != null) {
-            setOwnerDocument(parentNode.ownerDocument());
             parentNode.addChild(this);
         }
 

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=1298603&r1=1298602&r2=1298603&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 21:48:19 2012
@@ -47,6 +47,14 @@ public abstract class NodeImpl implement
 
     protected short flags;
 
+    /**
+     * Used by {@link ChildNode} to determine the meaning of the <code>ownerNode</code>
attribute.
+     * If the flag is set, then the attribute contains the reference to the parent node.
If the flag
+     * is not set, then the node has no parent and the attribute stores a reference to the
owner
+     * document (which may be <code>null</code> if the owner document has not
been created yet).
+     */
+    protected final static short HAS_PARENT = 0x1 << 1;
+    
     protected final static short FIRSTCHILD = 0x1 << 2;
 
     protected final static short READONLY = 0x1 << 3;
@@ -266,6 +274,14 @@ public abstract class NodeImpl implement
      * Flags setters and getters
      */
 
+    final boolean hasParent() {
+        return (flags & HAS_PARENT) != 0;
+    }
+
+    final void hasParent(boolean value) {
+        flags = (short) (value ? flags | HAS_PARENT : flags & ~HAS_PARENT);
+    }
+
     final boolean isFirstChild() {
         return (flags & FIRSTCHILD) != 0;
     }



Mime
View raw message