Author: veithen
Date: Mon Jul 21 18:38:55 2014
New Revision: 1612380
URL: http://svn.apache.org/r1612380
Log:
Rewrite DOOM's insertBefore method and fix a couple of issues.
Modified:
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreChildNodeSupport.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/CoreChildNodeSupport.aj
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreChildNodeSupport.aj?rev=1612380&r1=1612379&r2=1612380&view=diff
==============================================================================
---
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreChildNodeSupport.aj
(original)
+++
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreChildNodeSupport.aj
Mon Jul 21 18:38:55 2014
@@ -140,7 +140,6 @@ public aspect CoreChildNodeSupport {
}
sibling.coreDetach(null);
sibling.internalSetParent(parent);
- CoreChildNode previousSibling = this.previousSibling;
sibling.nextSibling = this;
if (previousSibling == null) {
parent.firstChild = sibling;
@@ -148,7 +147,31 @@ public aspect CoreChildNodeSupport {
previousSibling.nextSibling = sibling;
}
sibling.previousSibling = previousSibling;
- this.previousSibling = sibling;
+ previousSibling = sibling;
+ }
+
+ public final void
CoreChildNode.coreInsertSiblingsBefore(CoreDocumentFragment fragment) {
+ if (fragment.firstChild == null) {
+ // Fragment is empty; nothing to do
+ return;
+ }
+ CoreParentNode parent = coreGetParent();
+ // TODO: check parent != null
+ CoreChildNode child = fragment.firstChild;
+ while (child != null) {
+ child.internalSetParent(parent);
+ child = child.nextSibling;
+ }
+ fragment.lastChild.nextSibling = this;
+ if (previousSibling == null) {
+ parent.firstChild = fragment.firstChild;
+ } else {
+ previousSibling.nextSibling = fragment.firstChild;
+ }
+ fragment.firstChild.previousSibling = previousSibling;
+ previousSibling = fragment.lastChild;
+ fragment.firstChild = null;
+ fragment.lastChild = null;
}
public final void CoreChildNode.coreDetach(CoreDocument newOwnerDocument) {
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=1612380&r1=1612379&r2=1612380&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
Mon Jul 21 18:38:55 2014
@@ -26,7 +26,6 @@ import org.apache.axiom.core.CoreDocumen
import org.apache.axiom.dom.DOMParentNode;
import org.apache.axiom.om.OMCloneOptions;
import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMSourcedElement;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -85,125 +84,22 @@ public abstract class ParentNode extends
* 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();
- }
- // if there are no children
- if (coreGetLastKnownChild() == null &&
coreGetFirstChildIfAvailable() == null) {
- coreSetLastChild((CoreChildNode)newDomChild);
- coreSetFirstChild((CoreChildNode)newDomChild);
- newDomChild.setParent(this);
- } else {
-
((NodeImpl)coreGetLastKnownChild()).internalSetNextSibling(newDomChild);
-
newDomChild.internalSetPreviousSibling((NodeImpl)coreGetLastKnownChild());
- coreSetLastChild((CoreChildNode)newDomChild);
-
((NodeImpl)coreGetLastKnownChild()).internalSetNextSibling(null);
- }
- if (newDomChild.parentNode() == null) {
- newDomChild.setParent(this);
- }
+ if (refChild == null) {
+ return appendChild(newChild);
} else {
- NodeImpl tempNode = (NodeImpl)getFirstChild();
- boolean found = false;
- while (tempNode != null) {
- if (tempNode.equals(refChild)) {
- // RefChild found
- if (coreGetFirstChildIfAvailable() == tempNode) { // If
the refChild is the
- // first child
-
- if (newChild instanceof DocumentFragmentImpl) {
- // The new child is a DocumentFragment
- DocumentFragmentImpl docFrag =
- (DocumentFragmentImpl) newChild;
-
- NodeImpl child =
(NodeImpl)docFrag.coreGetFirstChildIfAvailable();
- while (child != null) {
- child.setParent(this);
- child = child.internalGetNextSibling();
- }
-
-
coreSetFirstChild(docFrag.coreGetFirstChildIfAvailable());
-
((NodeImpl)docFrag.coreGetLastKnownChild()).internalSetNextSibling(refDomChild);
-
refDomChild.internalSetPreviousSibling(((NodeImpl)docFrag.coreGetLastKnownChild()).internalGetNextSibling());
-
- docFrag.coreSetFirstChild(null);
- docFrag.coreSetLastChild(null);
- } else {
-
- // Make the newNode the first Child
- coreSetFirstChild((CoreChildNode)newDomChild);
-
- newDomChild.internalSetNextSibling(refDomChild);
-
refDomChild.internalSetPreviousSibling(newDomChild);
-
- newDomChild.internalSetPreviousSibling(null); //
Just to be
- // sure :-)
-
- }
- } else { // If the refChild is not the fist child
- NodeImpl previousNode =
refDomChild.internalGetPreviousSibling();
-
- if (newChild instanceof DocumentFragmentImpl) {
- // the newChild is a document fragment
- DocumentFragmentImpl docFrag =
- (DocumentFragmentImpl) newChild;
-
- NodeImpl child =
(NodeImpl)docFrag.coreGetFirstChildIfAvailable();
- while (child != null) {
- child.setParent(this);
- child = child.internalGetNextSibling();
- }
-
-
previousNode.internalSetNextSibling((NodeImpl)docFrag.coreGetFirstChildIfAvailable());
-
((NodeImpl)docFrag.coreGetFirstChildIfAvailable()).internalSetPreviousSibling(previousNode);
-
-
((NodeImpl)docFrag.coreGetLastKnownChild()).internalSetNextSibling(refDomChild);
-
refDomChild.internalSetPreviousSibling((NodeImpl)docFrag.coreGetLastKnownChild());
-
- docFrag.coreSetFirstChild(null);
- docFrag.coreSetLastChild(null);
- } else {
-
- previousNode.internalSetNextSibling(newDomChild);
-
newDomChild.internalSetPreviousSibling(previousNode);
-
- newDomChild.internalSetNextSibling(refDomChild);
-
refDomChild.internalSetPreviousSibling(newDomChild);
- }
-
- }
- found = true;
- break;
- }
- tempNode = (NodeImpl)tempNode.getNextSibling();
- }
-
- if (!found) {
+ if (!(refChild instanceof CoreChildNode &&
((CoreChildNode)refChild).coreGetParent() == this)) {
throw newDOMException(DOMException.NOT_FOUND_ERR);
}
-
- if (!(newDomChild instanceof DocumentFragmentImpl) &&
newDomChild.parentNode() == null) {
- newDomChild.setParent(this);
+ checkNewChild(newChild);
+ if (newChild instanceof CoreChildNode) {
+
((CoreChildNode)refChild).coreInsertSiblingBefore((CoreChildNode)newChild);
+ } else if (newChild instanceof CoreDocumentFragment) {
+
((CoreChildNode)refChild).coreInsertSiblingsBefore((CoreDocumentFragment)newChild);
+ } else {
+ throw newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
}
-
- }
-
- if (!newDomChild.isComplete() && !(newDomChild instanceof
OMSourcedElement)) {
- setComplete(false);
+ return newChild;
}
-
- return newChild;
}
/** Replaces the oldChild with the newChild. */
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=1612380&r1=1612379&r2=1612380&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
Mon Jul 21 18:38:55 2014
@@ -55,7 +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/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)");
builder.exclude(W3CTestCase.class,
"(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/processinginstructionsetdatanomodificationallowederr)");
@@ -69,13 +68,11 @@ 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_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_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)");
builder.exclude(W3CTestCase.class,
"(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore5)");
builder.exclude(W3CTestCase.class,
"(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore7)");
builder.exclude(W3CTestCase.class,
"(id=http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrnormalize)");
@@ -351,10 +348,8 @@ public class DOMImplementationTest exten
builder.exclude(W3CTestCase.class,
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodegettextcontent19)");
builder.exclude(W3CTestCase.class,
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeinsertbefore02)");
builder.exclude(W3CTestCase.class,
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeinsertbefore05)");
- builder.exclude(W3CTestCase.class,
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeinsertbefore12)");
builder.exclude(W3CTestCase.class,
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeinsertbefore14)");
builder.exclude(W3CTestCase.class,
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeinsertbefore17)");
- builder.exclude(W3CTestCase.class,
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeinsertbefore20)");
builder.exclude(W3CTestCase.class,
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeinsertbefore25)");
builder.exclude(W3CTestCase.class,
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeisdefaultnamespace01)");
builder.exclude(W3CTestCase.class,
"(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeisdefaultnamespace02)");