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 2014/07/20 11:20:39 UTC
svn commit: r1612065 - in /webservices/axiom/trunk:
aspects/core-aspects/src/main/java/org/apache/axiom/core/
implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/
implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/
Author: veithen
Date: Sun Jul 20 09:20:38 2014
New Revision: 1612065
URL: http://svn.apache.org/r1612065
Log:
Some fixes to the appendChild method.
Modified:
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNodeSupport.aj
webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNodeSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNodeSupport.aj?rev=1612065&r1=1612064&r2=1612065&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNodeSupport.aj (original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNodeSupport.aj Sun Jul 20 09:20:38 2014
@@ -25,7 +25,6 @@ import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.impl.builder.StAXBuilder;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.w3c.dom.Node;
public aspect CoreParentNodeSupport {
CoreChildNode CoreParentNode.firstChild;
@@ -123,6 +122,29 @@ public aspect CoreParentNodeSupport {
lastChild = child;
}
+ public final void CoreParentNode.coreAppendChildren(CoreDocumentFragment fragment) {
+ fragment.build();
+ if (fragment.firstChild == null) {
+ // Fragment is empty; nothing to do
+ return;
+ }
+ build();
+ CoreChildNode child = fragment.firstChild;
+ while (child != null) {
+ child.internalSetParent(this);
+ child = child.nextSibling;
+ }
+ if (firstChild == null) {
+ firstChild = fragment.firstChild;
+ } else {
+ fragment.firstChild.previousSibling = lastChild;
+ lastChild.nextSibling = fragment.firstChild;
+ }
+ lastChild = fragment.lastChild;
+ fragment.firstChild = null;
+ fragment.lastChild = null;
+ }
+
public final void CoreParentNode.coreRemoveChildren(CoreDocument newOwnerDocument) {
// We need to call this first because if may modify the state (applies to OMSourcedElements)
CoreChildNode child = coreGetFirstChildIfAvailable();
Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java?rev=1612065&r1=1612064&r2=1612065&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java (original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java Sun Jul 20 09:20:38 2014
@@ -22,6 +22,7 @@ package org.apache.axiom.om.impl.dom;
import static org.apache.axiom.dom.DOMExceptionUtil.newDOMException;
import org.apache.axiom.core.CoreChildNode;
+import org.apache.axiom.core.CoreDocumentFragment;
import org.apache.axiom.dom.DOMParentNode;
import org.apache.axiom.om.OMCloneOptions;
import org.apache.axiom.om.OMFactory;
@@ -40,28 +41,26 @@ public abstract class ParentNode extends
// /
public final Node appendChild(Node newChild) throws DOMException {
- return insertBefore(newChild, null);
+ checkNewChild(newChild);
+ if (newChild instanceof CoreChildNode) {
+ coreAppendChild((CoreChildNode)newChild, false);
+ } else if (newChild instanceof CoreDocumentFragment) {
+ coreAppendChildren((CoreDocumentFragment)newChild);
+ } else {
+ throw newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
+ }
+ return newChild;
}
- /**
- * Inserts newChild before the refChild. If the refChild is null then the newChild is made the
- * last child.
- */
- public Node insertBefore(Node newChild, Node refChild) throws DOMException {
+ private void checkNewChild(Node newChild) {
NodeImpl newDomChild = (NodeImpl) newChild;
- NodeImpl refDomChild = (NodeImpl) refChild;
-
+
checkSameOwnerDocument(newDomChild);
if (isAncestorOrSelf(newChild)) {
throw newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
}
- if (newDomChild.parentNode() != null) {
- //If the newChild is already in the tree remove it
- newDomChild.parentNode().removeChild(newDomChild);
- }
-
if (this instanceof Document) {
if (newDomChild instanceof ElementImpl) {
if (((DocumentImpl) this).getOMDocumentElement() != null) {
@@ -79,6 +78,23 @@ public abstract class ParentNode extends
}
}
+ }
+
+ /**
+ * Inserts newChild before the refChild. If the refChild is null then the newChild is made the
+ * last child.
+ */
+ public Node insertBefore(Node newChild, Node refChild) throws DOMException {
+ NodeImpl newDomChild = (NodeImpl) newChild;
+ NodeImpl refDomChild = (NodeImpl) refChild;
+
+ checkNewChild(newDomChild);
+
+ if (newDomChild.parentNode() != null) {
+ //If the newChild is already in the tree remove it
+ newDomChild.parentNode().removeChild(newDomChild);
+ }
+
if (refChild == null) { // Append the child to the end of the list
if (!isComplete()) {
build();
Modified: webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java?rev=1612065&r1=1612064&r2=1612065&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java (original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java Sun Jul 20 09:20:38 2014
@@ -55,8 +55,6 @@ public class DOMImplementationTest exten
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/elementsetattributenomodificationallowederr)");
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/namednodemapremovenameditem)");
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/namednodemapremovenameditemgetvalue)");
- builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/nodeappendchilddocfragment)");
- builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/nodeappendchildinvalidnodetype)");
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/nodeinsertbeforeinvalidnodetype)");
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/nodereplacechildinvalidnodetype)");
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/nodereplacechildnewchildexists)");
@@ -71,13 +69,10 @@ public class DOMImplementationTest exten
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_elementnormalize2)");
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_elementremoveattributeaftercreate)");
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_elementreplaceattributewithself)");
- builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_nodeappendchilddocfragment)");
- builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_nodeappendchildinvalidnodetype)");
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_nodeinsertbeforeinvalidnodetype)");
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_nodereplacechildinvalidnodetype)");
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_nodereplacechildnewchildexists)");
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrappendchild2)");
- builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrappendchild3)");
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrappendchild4)");
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrgetvalue2)");
builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore3)");