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 2016/04/22 21:41:25 UTC
svn commit: r1740592 - in /webservices/axiom/trunk:
aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/
implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/
testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/ te...
Author: veithen
Date: Fri Apr 22 19:41:24 2016
New Revision: 1740592
URL: http://svn.apache.org/viewvc?rev=1740592&view=rev
Log:
Move more DOM code to dom-aspects.
Added:
webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildForeignImplementation.java (with props)
Modified:
webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMDocumentSupport.aj
webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMParentNodeSupport.aj
webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
Modified: webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMDocumentSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMDocumentSupport.aj?rev=1740592&r1=1740591&r2=1740592&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMDocumentSupport.aj (original)
+++ webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMDocumentSupport.aj Fri Apr 22 19:41:24 2016
@@ -18,6 +18,8 @@
*/
package org.apache.axiom.dom.impl.mixin;
+import static org.apache.axiom.dom.DOMExceptionUtil.newDOMException;
+
import javax.xml.XMLConstants;
import org.apache.axiom.core.CoreChildNode;
@@ -377,4 +379,10 @@ public aspect DOMDocumentSupport {
return null;
}
}
+
+ final void DOMDocument.checkNewChild0(DOMNode newChild) {
+ if (newChild instanceof DOMText) {
+ throw newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
+ }
+ }
}
Modified: webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMParentNodeSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMParentNodeSupport.aj?rev=1740592&r1=1740591&r2=1740592&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMParentNodeSupport.aj (original)
+++ webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMParentNodeSupport.aj Fri Apr 22 19:41:24 2016
@@ -18,7 +18,10 @@
*/
package org.apache.axiom.dom.impl.mixin;
+import static org.apache.axiom.dom.DOMExceptionUtil.newDOMException;
+
import org.apache.axiom.core.CoreChildNode;
+import org.apache.axiom.core.CoreDocumentFragment;
import org.apache.axiom.core.CoreModelException;
import org.apache.axiom.dom.DOMConfigurationImpl;
import org.apache.axiom.dom.DOMExceptionUtil;
@@ -98,5 +101,89 @@ public aspect DOMParentNodeSupport {
} catch (CoreModelException ex) {
throw DOMExceptionUtil.toUncheckedException(ex);
}
+ }
+
+ private void DOMParentNode.checkNewChild(Node newChild) {
+ if (newChild instanceof DOMNode) {
+ DOMNode newDomChild = (DOMNode)newChild;
+ if (!coreHasSameOwnerDocument(newDomChild)) {
+ throw newDOMException(DOMException.WRONG_DOCUMENT_ERR);
+ }
+ checkNewChild0((DOMNode)newChild);
+ } else {
+ throw newDOMException(DOMException.WRONG_DOCUMENT_ERR);
+ }
+ }
+
+ void DOMParentNode.checkNewChild0(DOMNode newChild) {
+ }
+
+ public final Node DOMParentNode.appendChild(Node newChild) {
+ try {
+ checkNewChild(newChild);
+ if (newChild instanceof CoreChildNode) {
+ coreAppendChild((CoreChildNode)newChild);
+ } else if (newChild instanceof CoreDocumentFragment) {
+ coreAppendChildren((CoreDocumentFragment)newChild);
+ } else {
+ throw newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
+ }
+ return newChild;
+ } catch (CoreModelException ex) {
+ throw DOMExceptionUtil.toUncheckedException(ex);
+ }
+ }
+
+ // TODO: should be final
+ public Node DOMParentNode.insertBefore(Node newChild, Node refChild) {
+ try {
+ if (refChild == null) {
+ return appendChild(newChild);
+ } else {
+ if (!(refChild instanceof CoreChildNode && ((CoreChildNode)refChild).coreGetParent() == this)) {
+ throw newDOMException(DOMException.NOT_FOUND_ERR);
+ }
+ 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);
+ }
+ return newChild;
+ }
+ } catch (CoreModelException ex) {
+ throw DOMExceptionUtil.toUncheckedException(ex);
+ }
+ }
+
+ public final Node DOMParentNode.replaceChild(Node newChild, Node _oldChild) {
+ try {
+ if (!(_oldChild instanceof CoreChildNode)) {
+ throw newDOMException(DOMException.NOT_FOUND_ERR);
+ }
+ CoreChildNode oldChild = (CoreChildNode)_oldChild;
+ if (oldChild.coreGetParent() != this) {
+ throw newDOMException(DOMException.NOT_FOUND_ERR);
+ }
+ checkNewChild(newChild);
+ if (newChild instanceof CoreChildNode) {
+ oldChild.coreReplaceWith(((CoreChildNode)newChild), DOMSemantics.INSTANCE);
+ } else if (newChild instanceof CoreDocumentFragment) {
+ CoreChildNode nextSibling = oldChild.coreGetNextSibling();
+ oldChild.coreDetach(DOMSemantics.INSTANCE);
+ if (nextSibling == null) {
+ coreAppendChildren((CoreDocumentFragment)newChild);
+ } else {
+ nextSibling.coreInsertSiblingsBefore((CoreDocumentFragment)newChild);
+ }
+ } else {
+ throw newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
+ }
+ return _oldChild;
+ } catch (CoreModelException ex) {
+ throw DOMExceptionUtil.toUncheckedException(ex);
+ }
}
}
Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java?rev=1740592&r1=1740591&r2=1740592&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java (original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java Fri Apr 22 19:41:24 2016
@@ -292,10 +292,4 @@ public abstract class NodeImpl implement
final DocumentImpl ownerDocument() {
return (DocumentImpl)coreGetOwnerDocument(true);
}
-
- void checkSameOwnerDocument(Node otherNode) {
- if (!(otherNode instanceof NodeImpl && coreHasSameOwnerDocument((NodeImpl)otherNode))) {
- throw newDOMException(DOMException.WRONG_DOCUMENT_ERR);
- }
- }
}
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=1740592&r1=1740591&r2=1740592&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 Fri Apr 22 19:41:24 2016
@@ -19,104 +19,8 @@
package org.apache.axiom.om.impl.dom;
-import static org.apache.axiom.dom.DOMExceptionUtil.newDOMException;
-
-import org.apache.axiom.core.CoreCharacterDataNode;
-import org.apache.axiom.core.CoreChildNode;
-import org.apache.axiom.core.CoreDocumentFragment;
-import org.apache.axiom.core.CoreModelException;
-import org.apache.axiom.dom.DOMExceptionUtil;
import org.apache.axiom.dom.DOMParentNode;
-import org.apache.axiom.dom.DOMSemantics;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
public abstract class ParentNode extends NodeImpl implements DOMParentNode {
- // /
- // /DOM Node methods
- // /
-
- public final Node appendChild(Node newChild) throws DOMException {
- try {
- checkNewChild(newChild, null);
- if (newChild instanceof CoreChildNode) {
- coreAppendChild((CoreChildNode)newChild);
- } else if (newChild instanceof CoreDocumentFragment) {
- coreAppendChildren((CoreDocumentFragment)newChild);
- } else {
- throw newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
- }
- return newChild;
- } catch (CoreModelException ex) {
- throw DOMExceptionUtil.toUncheckedException(ex);
- }
- }
-
- private void checkNewChild(Node newChild, Node replacedChild) {
- NodeImpl newDomChild = (NodeImpl) newChild;
-
- checkSameOwnerDocument(newDomChild);
-
- if (this instanceof Document && newDomChild instanceof CoreCharacterDataNode) {
- throw newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
- }
- }
-
- /**
- * 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 {
- try {
- if (refChild == null) {
- return appendChild(newChild);
- } else {
- if (!(refChild instanceof CoreChildNode && ((CoreChildNode)refChild).coreGetParent() == this)) {
- throw newDOMException(DOMException.NOT_FOUND_ERR);
- }
- checkNewChild(newChild, null);
- 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);
- }
- return newChild;
- }
- } catch (CoreModelException ex) {
- throw DOMExceptionUtil.toUncheckedException(ex);
- }
- }
- /** Replaces the oldChild with the newChild. */
- public final Node replaceChild(Node newChild, Node _oldChild) throws DOMException {
- try {
- if (!(_oldChild instanceof CoreChildNode)) {
- throw newDOMException(DOMException.NOT_FOUND_ERR);
- }
- CoreChildNode oldChild = (CoreChildNode)_oldChild;
- if (oldChild.coreGetParent() != this) {
- throw newDOMException(DOMException.NOT_FOUND_ERR);
- }
- checkNewChild(newChild, _oldChild);
- if (newChild instanceof CoreChildNode) {
- oldChild.coreReplaceWith(((CoreChildNode)newChild), DOMSemantics.INSTANCE);
- } else if (newChild instanceof CoreDocumentFragment) {
- CoreChildNode nextSibling = oldChild.coreGetNextSibling();
- oldChild.coreDetach(DOMSemantics.INSTANCE);
- if (nextSibling == null) {
- coreAppendChildren((CoreDocumentFragment)newChild);
- } else {
- nextSibling.coreInsertSiblingsBefore((CoreDocumentFragment)newChild);
- }
- } else {
- throw newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
- }
- return _oldChild;
- } catch (CoreModelException ex) {
- throw DOMExceptionUtil.toUncheckedException(ex);
- }
- }
}
Modified: webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java?rev=1740592&r1=1740591&r2=1740592&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java (original)
+++ webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java Fri Apr 22 19:41:24 2016
@@ -84,6 +84,7 @@ public final class DOMTestSuiteBuilder e
addTest(new org.apache.axiom.ts.dom.document.TestAdoptNodeToSameDocument(dbf));
addTest(new org.apache.axiom.ts.dom.document.TestAdoptNodeWithParent(dbf));
addTest(new org.apache.axiom.ts.dom.document.TestAllowedChildren(dbf));
+ addTest(new org.apache.axiom.ts.dom.document.TestAppendChildForeignImplementation(dbf));
addTest(new org.apache.axiom.ts.dom.document.TestAppendChildWrongDocument(dbf));
for (XMLSample file : getInstances(XMLSample.class)) {
addTest(new org.apache.axiom.ts.dom.document.TestCloneNode(dbf, file));
Added: webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildForeignImplementation.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildForeignImplementation.java?rev=1740592&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildForeignImplementation.java (added)
+++ webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildForeignImplementation.java Fri Apr 22 19:41:24 2016
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.dom.document;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class TestAppendChildForeignImplementation extends DOMTestCase {
+ public TestAppendChildForeignImplementation(DocumentBuilderFactory dbf) {
+ super(dbf);
+ }
+
+ @Override
+ protected void runTest() throws Throwable {
+ Document document = dbf.newDocumentBuilder().newDocument();
+ Element element = mock(Element.class);
+ try {
+ document.appendChild(element);
+ fail("Expected DOMException");
+ } catch (DOMException ex) {
+ assertThat(ex.code).isEqualTo(DOMException.WRONG_DOCUMENT_ERR);
+ }
+ }
+}
Propchange: webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildForeignImplementation.java
------------------------------------------------------------------------------
svn:eol-style = native