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/06 21:40:39 UTC
svn commit: r1297699 - in
/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom:
om/impl/dom/ soap/impl/dom/soap11/
Author: veithen
Date: Tue Mar 6 20:40:38 2012
New Revision: 1297699
URL: http://svn.apache.org/viewvc?rev=1297699&view=rev
Log:
AXIOM-412: Restrict access to ChildNode#parentNode so that we can easily change the way the parent node is stored.
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/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
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-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultSubCodeImpl.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=1297699&r1=1297698&r2=1297699&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 Tue Mar 6 20:40:38 2012
@@ -366,6 +366,11 @@ public class AttrImpl extends NodeImpl i
return this.parent;
}
+ public Node getParentNode() {
+ // For DOM, the owner element is not the parent
+ return null;
+ }
+
/**
* Returns the attribute name.
*
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=1297699&r1=1297698&r2=1297699&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 Tue Mar 6 20:40:38 2012
@@ -42,7 +42,7 @@ public abstract class ChildNode extends
protected ChildNode nextSibling;
- protected ParentNode parentNode;
+ private ParentNode parentNode;
/** @param ownerDocument */
protected ChildNode(DocumentImpl ownerDocument, OMFactory factory) {
@@ -53,9 +53,14 @@ public abstract class ChildNode extends
super(factory);
}
+ ParentNode parentNode() {
+ return parentNode;
+ }
+
public OMNode getNextOMSibling() throws OMException {
- while (nextSibling == null && this.parentNode != null && !this.parentNode.done && parentNode.builder != null) {
- this.parentNode.buildNext();
+ ParentNode parentNode = parentNode();
+ while (nextSibling == null && parentNode != null && !parentNode.done && parentNode.builder != null) {
+ parentNode.buildNext();
}
return (OMNode)nextSibling;
}
@@ -104,11 +109,11 @@ public abstract class ChildNode extends
}
public OMContainer getParent() throws OMException {
- return this.parentNode;
+ return parentNode();
}
public Node getParentNode() {
- return this.parentNode;
+ return parentNode();
}
public void setParent(OMContainer element) {
@@ -122,7 +127,8 @@ public abstract class ChildNode extends
}
public OMNode detach() throws OMException {
- if (this.parentNode == null) {
+ ParentNode parentNode = parentNode();
+ if (parentNode == null) {
throw new OMException("Parent level elements cannot be detached");
} else {
if (!done) {
@@ -131,25 +137,25 @@ public abstract class ChildNode extends
getNextOMSibling(); // Make sure that nextSibling is set correctly
if (previousSibling == null) { // This is the first child
if (nextSibling != null) {
- this.parentNode.setFirstChild((OMNode)nextSibling);
+ parentNode.setFirstChild((OMNode)nextSibling);
} else {
- this.parentNode.firstChild = null;
- this.parentNode.lastChild = null;
+ parentNode.firstChild = null;
+ parentNode.lastChild = null;
}
} else {
this.previousSibling.setNextOMSibling((OMNode)nextSibling);
if (nextSibling == null) {
- this.previousSibling.parentNode.done = true;
+ this.previousSibling.parentNode().done = true;
}
}
if (this.nextSibling != null) {
this.nextSibling.setPreviousOMSibling((OMNode)this.previousSibling);
this.nextSibling = null;
}
- if (this.parentNode != null && this.parentNode.lastChild == this) {
- this.parentNode.lastChild = previousSibling;
+ if (parentNode != null && parentNode.lastChild == this) {
+ parentNode.lastChild = previousSibling;
}
- this.parentNode = null;
+ setParent(null);
this.previousSibling = null;
}
return (OMNode)this;
@@ -161,17 +167,18 @@ public abstract class ChildNode extends
/** Inserts the given sibling next to this item. */
public void insertSiblingAfter(OMNode sibling) throws OMException {
- if (this.parentNode == null) {
+ ParentNode parentNode = parentNode();
+ if (parentNode == null) {
throw new OMException("Parent can not be null");
} else if (this == sibling) {
throw new OMException("Inserting self as the sibling is not allowed");
}
- ((OMNodeEx) sibling).setParent(this.parentNode);
+ ((OMNodeEx) sibling).setParent(parentNode);
if (sibling instanceof ChildNode) {
ChildNode domSibling = (ChildNode) sibling;
domSibling.previousSibling = this;
if (this.nextSibling == null) {
- this.parentNode.setLastChild(sibling);
+ parentNode.setLastChild(sibling);
} else {
this.nextSibling.previousSibling = domSibling;
}
@@ -186,8 +193,9 @@ public abstract class ChildNode extends
/** Inserts the given sibling before this item. */
public void insertSiblingBefore(OMNode sibling) throws OMException {
+ ParentNode parentNode = parentNode();
// ((OMNodeEx)sibling).setParent(this.parentNode);
- if (this.parentNode == null) {
+ if (parentNode == null) {
throw new OMException("Parent can not be null");
} else if (this == sibling) {
throw new OMException("Inserting self as the sibling is not allowed");
@@ -203,10 +211,10 @@ public abstract class ChildNode extends
ChildNode siblingImpl = (ChildNode) sibling;
siblingImpl.nextSibling = this;
if (previousSibling == null) {
- this.parentNode.setFirstChild((OMNode)siblingImpl);
+ parentNode.setFirstChild((OMNode)siblingImpl);
siblingImpl.previousSibling = null;
} else {
- siblingImpl.setParent(this.parentNode);
+ siblingImpl.setParent(parentNode);
previousSibling.setNextOMSibling((OMNode)siblingImpl);
siblingImpl.setPreviousOMSibling((OMNode)previousSibling);
}
@@ -234,6 +242,7 @@ public abstract class ChildNode extends
public void setComplete(boolean state) {
done = state;
+ ParentNode parentNode = parentNode();
if (parentNode != null) {
if (!done) {
parentNode.setComplete(false);
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=1297699&r1=1297698&r2=1297699&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 Tue Mar 6 20:40:38 2012
@@ -833,6 +833,7 @@ public class ElementImpl extends ParentN
}
}
+ ParentNode parentNode = parentNode();
if (parentNode instanceof ElementImpl) {
ElementImpl element = (ElementImpl) parentNode;
return element.getDefaultNamespace();
@@ -850,7 +851,8 @@ public class ElementImpl extends ParentN
}
// go up to check with ancestors
- if (this.parentNode != null) {
+ ParentNode parentNode = parentNode();
+ if (parentNode != null) {
// For the OMDocumentImpl there won't be any explicit namespace
// declarations, so going up the parent chain till the document
// element should be enough.
@@ -879,9 +881,10 @@ public class ElementImpl extends ParentN
(OMNamespace) this.namespaces.get(prefix);
if (ns == null) {
- if (this.parentNode instanceof OMElement) {
+ ParentNode parentNode = parentNode();
+ if (parentNode instanceof OMElement) {
// try with the parent
- return ((OMElement) this.parentNode).findNamespaceURI(prefix);
+ return ((OMElement)parentNode).findNamespaceURI(prefix);
} else {
return null;
}
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=1297699&r1=1297698&r2=1297699&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 Tue Mar 6 20:40:38 2012
@@ -166,18 +166,6 @@ public abstract class NodeImpl implement
return null; // default behavior, overriden in ChildNode
}
- public Node getParentNode() {
- return null; // overriden by ChildNode
- // Document, DocumentFragment, and Attribute will never have parents.
- }
-
- /*
- * Same as getParentNode but returns internal type NodeImpl.
- */
- NodeImpl parentNode() {
- return null;
- }
-
/** Returns the previous child of this node's parent, or null if none. */
public Node getPreviousSibling() {
return null; // default behavior, overriden in ChildNode
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=1297699&r1=1297698&r2=1297699&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 Tue Mar 6 20:40:38 2012
@@ -219,9 +219,9 @@ public abstract class ParentNode extends
DOMException.HIERARCHY_REQUEST_ERR, null));
}
- if (newDomChild.parentNode != null && newDomChild.ownerNode == this.ownerNode) {
+ if (newDomChild.parentNode() != null && newDomChild.ownerNode == this.ownerNode) {
//If the newChild is already in the tree remove it
- newDomChild.parentNode.removeChild(newDomChild);
+ newDomChild.parentNode().removeChild(newDomChild);
}
if (!(this instanceof Document)
@@ -248,8 +248,8 @@ public abstract class ParentNode extends
DOMMessageFormatter.DOM_DOMAIN,
DOMException.HIERARCHY_REQUEST_ERR, null));
}
- if (newDomChild.parentNode == null) {
- newDomChild.parentNode = this;
+ if (newDomChild.parentNode() == null) {
+ newDomChild.setParent(this);
}
} else if (!(newDomChild instanceof CommentImpl
|| newDomChild instanceof ProcessingInstructionImpl
@@ -275,8 +275,8 @@ public abstract class ParentNode extends
this.lastChild = newDomChild;
this.lastChild.nextSibling = null;
}
- if (newDomChild.parentNode == null) {
- newDomChild.parentNode = this;
+ if (newDomChild.parentNode() == null) {
+ newDomChild.setParent(this);
}
} else {
Iterator children = this.getChildren();
@@ -296,7 +296,7 @@ public abstract class ParentNode extends
ChildNode child = docFrag.firstChild;
while (child != null) {
- child.parentNode = this;
+ child.setParent(this);
child = child.nextSibling;
}
@@ -331,7 +331,7 @@ public abstract class ParentNode extends
ChildNode child = docFrag.firstChild;
while (child != null) {
- child.parentNode = this;
+ child.setParent(this);
child = child.nextSibling;
}
@@ -365,8 +365,8 @@ public abstract class ParentNode extends
DOMException.NOT_FOUND_ERR, null));
}
- if (newDomChild.parentNode == null) {
- newDomChild.parentNode = this;
+ if (newDomChild.parentNode() == null) {
+ newDomChild.setParent(this);
}
}
@@ -425,7 +425,7 @@ public abstract class ParentNode extends
//set the parent of all kids to me
while(child != null) {
- child.parentNode = this;
+ child.setParent(this);
child = child.nextSibling;
}
@@ -440,7 +440,7 @@ public abstract class ParentNode extends
}
//Cleanup the current first child
- this.firstChild.parentNode = null;
+ this.firstChild.setParent(null);
this.firstChild.nextSibling = null;
//Set the new first child
@@ -462,14 +462,14 @@ public abstract class ParentNode extends
}
- newDomChild.parentNode = this;
+ newDomChild.setParent(this);
}
found = true;
// remove the old child's references to this tree
oldDomChild.nextSibling = null;
oldDomChild.previousSibling = null;
- oldDomChild.parentNode = null;
+ oldDomChild.setParent(null);
}
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java?rev=1297699&r1=1297698&r2=1297699&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java Tue Mar 6 20:40:38 2012
@@ -258,8 +258,9 @@ public abstract class TextNodeImpl exten
TextImpl newText = (TextImpl) this.getOwnerDocument().createTextNode(
newValue);
- if (this.parentNode != null) {
- newText.setParent(this.parentNode);
+ ParentNode parentNode = parentNode();
+ if (parentNode != null) {
+ newText.setParent(parentNode);
}
this.insertSiblingAfter(newText);
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultSubCodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultSubCodeImpl.java?rev=1297699&r1=1297698&r2=1297699&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultSubCodeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultSubCodeImpl.java Tue Mar 6 20:40:38 2012
@@ -21,6 +21,7 @@ package org.apache.axiom.soap.impl.dom.s
import javax.xml.namespace.QName;
+import org.apache.axiom.om.OMContainer;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.soap.SOAP12Constants;
@@ -70,6 +71,7 @@ public class SOAP11FaultSubCodeImpl exte
public void setSubCode(SOAPFaultSubCode subCode)
throws SOAPProcessingException {
+ OMContainer parentNode = getParent();
if (!((parentNode instanceof SOAP11FaultSubCodeImpl) ||
(parentNode instanceof SOAP11FaultCodeImpl))) {
throw new SOAPProcessingException(