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 2015/10/01 00:37:45 UTC
svn commit: r1706166 - in /webservices/axiom/trunk: ./
aspects/core-aspects/src/main/java/org/apache/axiom/core/
aspects/dom-aspects/src/main/java/org/apache/axiom/dom/
aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/
implementations/a...
Author: veithen
Date: Wed Sep 30 22:37:45 2015
New Revision: 1706166
URL: http://svn.apache.org/viewvc?rev=1706166&view=rev
Log:
Fix some DOM issues and simplify the core model API.
Added:
webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeForeignImplementation.java (with props)
webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeNotOwner.java
- copied, changed from r1704765, webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNotOwner.java
webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSForeignImplementation.java (with props)
Removed:
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/NodeInUseException.java
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/NodeMigrationException.java
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/NodeMigrationPolicy.java
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/WrongDocumentException.java
webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNotOwner.java
Modified:
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElement.java
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElementSupport.aj
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/DetachPolicy.java
webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMElementSupport.aj
webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMExceptionTranslator.java
webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/Policies.java
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomElementSupport.aj
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Policies.java
webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
webservices/axiom/trunk/pom.xml
webservices/axiom/trunk/testing/dom-testsuite/pom.xml
webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElement.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElement.java?rev=1706166&r1=1706165&r2=1706166&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElement.java (original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElement.java Wed Sep 30 22:37:45 2015
@@ -22,30 +22,6 @@ import java.util.Iterator;
public interface CoreElement extends CoreChildNode, CoreMixedContentContainer, CoreNamedNode, DeferringParentNode {
/**
- * Specifies the value that should be returned by
- * {@link CoreElement#coreSetAttribute(AttributeMatcher, String, String, CoreAttribute, NodeMigrationPolicy, ReturnValue)}.
- */
- public enum ReturnValue {
- /**
- * Nothing should be returned.
- */
- NONE,
-
- /**
- * The method will return the attribute that was effectively added to the element (which may
- * be a clone of the attribute requested to be added if
- * {@link NodeMigrationPolicy.Action#CLONE} is used).
- */
- ADDED_ATTRIBUTE,
-
- /**
- * The method will return the attribute that was replaced by the new attribute, or
- * <code>null</code> if no matching attribute existed.
- */
- REPLACED_ATTRIBUTE,
- }
-
- /**
* Get the first attribute of this element.
*
* @return the first attribute, or <code>null</code> if this element has no attributes
@@ -103,16 +79,13 @@ public interface CoreElement extends Cor
* Add a new attribute or replace an existing attribute based on a given
* {@link AttributeMatcher}. If a matching attribute on this element is found, it is replaced by
* the specified attribute. If no matching attribute is found, then the specified attribute is
- * added to this element. If the attribute is already owned by this element, then calling this method
- * has no effect.
+ * added to this element. If the attribute is already owned by this element, then calling this
+ * method has no effect.
*
* @param matcher
* the {@link AttributeMatcher} implementation to use
* @param attr
* the new attribute to add
- * @param policy
- * the policy to apply if the attribute already has an owner element or belongs to a
- * different document
* @param changeDocumentOfReplacedAttribute
* specifies if the owner document of the replaced attribute (if any) should be
* changed
@@ -121,12 +94,10 @@ public interface CoreElement extends Cor
* attribute will have its own owner document (which may be created lazily at a later
* moment); only meaningful if <code>changeDocumentOfReplacedAttribute</code> is
* <code>true</code
- * @param returnValue
- * specifies the expected return value of the method
- * @return the attribute as specified by the <code>returnValue</code> parameter
- * @throws NodeMigrationException
+ * @return the attribute that was replaced by the new attribute, or <code>null</code> if no
+ * matching attribute existed.
*/
- CoreAttribute coreSetAttribute(AttributeMatcher matcher, CoreAttribute attr, NodeMigrationPolicy policy, boolean changeDocumentOfReplacedAttribute, CoreDocument newDocument, ReturnValue returnValue) throws NodeMigrationException;
+ CoreAttribute coreSetAttribute(AttributeMatcher matcher, CoreAttribute attr, boolean changeDocumentOfReplacedAttribute, CoreDocument newDocument);
/**
* Append an attribute to this element. The attribute is simply added at the end of the list of
@@ -135,13 +106,8 @@ public interface CoreElement extends Cor
*
* @param attr
* the attribute to append
- * @param policy
- * the policy to apply if the attribute already has an owner element or belongs to a
- * different document
- * @throws NodeMigrationException
- * if appending the attribute was rejected by the policy
*/
- void coreAppendAttribute(CoreAttribute attr, NodeMigrationPolicy policy) throws NodeMigrationException;
+ void coreAppendAttribute(CoreAttribute attr);
/**
* Remove an attribute based on a given {@link AttributeMatcher}.
Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElementSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElementSupport.aj?rev=1706166&r1=1706165&r2=1706166&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElementSupport.aj (original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElementSupport.aj Wed Sep 30 22:37:45 2015
@@ -56,47 +56,9 @@ public aspect CoreElementSupport {
return attr;
}
- private CoreAttribute CoreElement.accept(CoreAttribute attr, NodeMigrationPolicy policy) throws NodeMigrationException {
- boolean hasParent = attr.coreHasOwnerElement();
- boolean isForeignDocument = !coreHasSameOwnerDocument(attr);
- boolean isForeignModel = attr.coreGetNodeFactory() != coreGetNodeFactory();
- if (hasParent || isForeignDocument || isForeignModel) {
- switch (policy.getAction(hasParent, isForeignDocument, isForeignModel)) {
- case REJECT:
- if (isForeignDocument) {
- // Note that since isForeignModel implies isForeignDocument, we also get here
- // if isForeignModel is true.
- throw new WrongDocumentException();
- } else {
- // We get here if isForeignDocument and isForeignModel are false. Since at least
- // one of the three booleans must be true, this implies that hasParent is true.
- throw new NodeInUseException();
- }
- case MOVE:
- if (isForeignDocument || isForeignModel) {
- // TODO
-// throw new UnsupportedOperationException();
- return attr;
- } else {
- attr.coreRemove(null); // TODO
- return attr;
- }
- case CLONE:
- // TODO: probably we need to distinguish between cloning an attribute from the same model and importing it from another model (does that actually ever occur?)
- throw new UnsupportedOperationException();
-// return cloneAttribute(attr);
- default:
- // Should never get here unless new values are added to the enum
- throw new IllegalStateException();
- }
- } else {
- return attr;
- }
- }
-
- public final void CoreElement.coreAppendAttribute(CoreAttribute attr, NodeMigrationPolicy policy) throws NodeMigrationException {
- // TODO: we should probably check if the attribute is already owned by the element
- internalAppendAttribute(accept(attr, policy));
+ public final void CoreElement.coreAppendAttribute(CoreAttribute attr) {
+ attr.coreRemove(DetachPolicy.NEW_DOCUMENT);
+ internalAppendAttribute(attr);
}
private void CoreElement.internalAppendAttribute(CoreAttribute attr) {
@@ -129,13 +91,12 @@ public aspect CoreElementSupport {
}
}
- public final CoreAttribute CoreElement.coreSetAttribute(AttributeMatcher matcher, CoreAttribute coreAttr, NodeMigrationPolicy policy, boolean changeDocumentOfReplacedAttribute, CoreDocument newDocument, ReturnValue returnValue) throws NodeMigrationException {
- if (coreAttr.coreGetOwnerElement() == this) {
+ public final CoreAttribute CoreElement.coreSetAttribute(AttributeMatcher matcher, CoreAttribute attr, boolean changeDocumentOfReplacedAttribute, CoreDocument newDocument) {
+ if (attr.coreGetOwnerElement() == this) {
// TODO: document this and add assertion
- // TODO: take returnValue into account
- return coreAttr;
+ return attr;
}
- CoreAttribute attr = accept(coreAttr, policy);
+ attr.coreRemove(DetachPolicy.NEW_DOCUMENT);
String namespaceURI = matcher.getNamespaceURI(attr);
String name = matcher.getName(attr);
CoreAttribute existingAttr = coreGetFirstAttribute();
@@ -161,11 +122,7 @@ public aspect CoreElementSupport {
attr.internalSetNextAttribute(existingAttr.coreGetNextAttribute());
existingAttr.internalSetNextAttribute(null);
}
- switch (returnValue) {
- case ADDED_ATTRIBUTE: return attr;
- case REPLACED_ATTRIBUTE: return existingAttr;
- default: return null;
- }
+ return existingAttr;
}
public final boolean CoreElement.coreRemoveAttribute(AttributeMatcher matcher, String namespaceURI, String name, DetachPolicy detachPolicy) {
Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/DetachPolicy.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/DetachPolicy.java?rev=1706166&r1=1706165&r2=1706166&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/DetachPolicy.java (original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/DetachPolicy.java Wed Sep 30 22:37:45 2015
@@ -22,6 +22,12 @@ package org.apache.axiom.core;
* Determines how nodes are detached from an object model tree.
*/
public interface DetachPolicy {
+ public static final DetachPolicy NEW_DOCUMENT = new DetachPolicy() {
+ public CoreDocument getNewOwnerDocument(CoreParentNode owner) {
+ return null;
+ }
+ };
+
/**
* Get the new owner document for the node (or group of child nodes) to be detached. This method
* is called before any node is detached.
Modified: webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMElementSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMElementSupport.aj?rev=1706166&r1=1706165&r2=1706166&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMElementSupport.aj (original)
+++ webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMElementSupport.aj Wed Sep 30 22:37:45 2015
@@ -22,7 +22,6 @@ import javax.xml.XMLConstants;
import org.apache.axiom.core.AttributeMatcher;
import org.apache.axiom.core.CoreElement;
-import org.apache.axiom.core.CoreModelException;
import org.apache.axiom.core.CoreNSAwareAttribute;
import org.apache.axiom.core.CoreNamespaceDeclaration;
import org.apache.axiom.core.ElementAction;
@@ -136,12 +135,21 @@ public aspect DOMElementSupport {
}
public final Attr DOMElement.setAttributeNodeNS(Attr _newAttr) throws DOMException {
+ if (!(_newAttr instanceof DOMAttribute)) {
+ throw DOMExceptionTranslator.newDOMException(DOMException.WRONG_DOCUMENT_ERR);
+ }
DOMAttribute newAttr = (DOMAttribute)_newAttr;
- if (newAttr.coreGetOwnerElement() == this) {
+ CoreElement owner = newAttr.coreGetOwnerElement();
+ if (owner == this) {
// This means that the "new" attribute is already linked to the element
// and replaces itself.
return newAttr;
+ } else if (owner != null) {
+ throw DOMExceptionTranslator.newDOMException(DOMException.INUSE_ATTRIBUTE_ERR);
} else {
+ if (!coreHasSameOwnerDocument(newAttr)) {
+ throw DOMExceptionTranslator.newDOMException(DOMException.WRONG_DOCUMENT_ERR);
+ }
AttributeMatcher matcher;
if (newAttr instanceof CoreNSAwareAttribute) {
matcher = Policies.DOM2_ATTRIBUTE_MATCHER;
@@ -151,22 +159,22 @@ public aspect DOMElementSupport {
// Must be a DOM1 (namespace unaware) attribute
matcher = Policies.DOM1_ATTRIBUTE_MATCHER;
}
- try {
- return (DOMAttribute)coreSetAttribute(matcher, newAttr, Policies.ATTRIBUTE_MIGRATION_POLICY, false, null, ReturnValue.REPLACED_ATTRIBUTE);
- } catch (CoreModelException ex) {
- throw DOMExceptionTranslator.translate(ex);
- }
+ return (DOMAttribute)coreSetAttribute(matcher, newAttr, false, null);
}
}
public final Attr DOMElement.removeAttributeNode(Attr oldAttr) throws DOMException {
- DOMAttribute attr = (DOMAttribute)oldAttr;
- if (attr.coreGetOwnerElement() != this) {
- throw DOMExceptionTranslator.newDOMException(DOMException.NOT_FOUND_ERR);
+ if (oldAttr instanceof DOMAttribute) {
+ DOMAttribute attr = (DOMAttribute)oldAttr;
+ if (attr.coreGetOwnerElement() != this) {
+ throw DOMExceptionTranslator.newDOMException(DOMException.NOT_FOUND_ERR);
+ } else {
+ attr.coreRemove(Policies.DETACH_POLICY);
+ }
+ return attr;
} else {
- attr.coreRemove(Policies.DETACH_POLICY);
+ throw DOMExceptionTranslator.newDOMException(DOMException.NOT_FOUND_ERR);
}
- return attr;
}
public final void DOMElement.removeAttribute(String name) throws DOMException {
Modified: webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMExceptionTranslator.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMExceptionTranslator.java?rev=1706166&r1=1706165&r2=1706166&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMExceptionTranslator.java (original)
+++ webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMExceptionTranslator.java Wed Sep 30 22:37:45 2015
@@ -24,8 +24,6 @@ import java.util.ResourceBundle;
import org.apache.axiom.core.CoreModelException;
import org.apache.axiom.core.ExceptionTranslator;
-import org.apache.axiom.core.NodeInUseException;
-import org.apache.axiom.core.WrongDocumentException;
import org.w3c.dom.DOMException;
public final class DOMExceptionTranslator implements ExceptionTranslator {
@@ -73,13 +71,7 @@ public final class DOMExceptionTranslato
}
public static RuntimeException translate(CoreModelException ex) {
- if (ex instanceof WrongDocumentException) {
- return newDOMException(DOMException.WRONG_DOCUMENT_ERR);
- } else if (ex instanceof NodeInUseException) {
- return newDOMException(DOMException.INUSE_ATTRIBUTE_ERR);
- } else {
- throw new IllegalArgumentException("Don't know how to translate " + ex.getClass().getName());
- }
+ throw new IllegalArgumentException("Don't know how to translate " + ex.getClass().getName());
}
public RuntimeException toUncheckedException(CoreModelException ex) {
Modified: webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/Policies.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/Policies.java?rev=1706166&r1=1706165&r2=1706166&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/Policies.java (original)
+++ webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/Policies.java Wed Sep 30 22:37:45 2015
@@ -29,7 +29,6 @@ import org.apache.axiom.core.CoreParentN
import org.apache.axiom.core.DetachPolicy;
import org.apache.axiom.core.NSAwareAttributeMatcher;
import org.apache.axiom.core.NamespaceDeclarationMatcher;
-import org.apache.axiom.core.NodeMigrationPolicy;
import org.apache.axiom.core.NodeType;
public final class Policies {
@@ -89,18 +88,6 @@ public final class Policies {
public static final AttributeMatcher NAMESPACE_DECLARATION_MATCHER = new NamespaceDeclarationMatcher(DETACH_POLICY);
- public static final NodeMigrationPolicy ATTRIBUTE_MIGRATION_POLICY = new NodeMigrationPolicy() {
- public Action getAction(boolean hasParent, boolean isForeignDocument, boolean isForeignModel) {
- return Action.REJECT;
- }
- };
-
- public static final NodeMigrationPolicy NODE_MIGRATION_POLICY = new NodeMigrationPolicy() {
- public Action getAction(boolean hasParent, boolean isForeignDocument, boolean isForeignModel) {
- return isForeignDocument ? Action.REJECT : Action.MOVE;
- }
- };
-
public static final ClonePolicy<Void> DEEP_CLONE = new ClonePolicy<Void>() {
public Class<? extends CoreNode> getTargetNodeClass(Void options, CoreNode node) {
// This is not specified by the API, but it's compatible with versions before 1.2.14
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomElementSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomElementSupport.aj?rev=1706166&r1=1706165&r2=1706166&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomElementSupport.aj (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomElementSupport.aj Wed Sep 30 22:37:45 2015
@@ -36,8 +36,6 @@ import org.apache.axiom.core.CoreAttribu
import org.apache.axiom.core.CoreParentNode;
import org.apache.axiom.core.ElementAction;
import org.apache.axiom.core.IdentityMapper;
-import org.apache.axiom.core.NodeMigrationException;
-import org.apache.axiom.core.NodeMigrationPolicy;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMConstants;
import org.apache.axiom.om.OMContainer;
@@ -280,11 +278,7 @@ public aspect AxiomElementSupport {
}
public final void AxiomElement.internalAppendAttribute(OMAttribute attr) {
- try {
- coreSetAttribute(Policies.ATTRIBUTE_MATCHER, (AxiomAttribute)attr, NodeMigrationPolicy.MOVE_ALWAYS, true, null, ReturnValue.NONE);
- } catch (NodeMigrationException ex) {
- AxiomExceptionTranslator.translate(ex);
- }
+ coreSetAttribute(Policies.ATTRIBUTE_MATCHER, (AxiomAttribute)attr, true, null);
}
public final OMAttribute AxiomElement.addAttribute(OMAttribute attr){
@@ -355,23 +349,14 @@ public aspect AxiomElementSupport {
OMNamespace ns = new OMNamespaceImpl(uri, prefix);
AxiomNamespaceDeclaration decl = coreGetNodeFactory().createNode(AxiomNamespaceDeclaration.class);
decl.setDeclaredNamespace(ns);
- try {
- coreAppendAttribute(decl, NodeMigrationPolicy.MOVE_ALWAYS);
- } catch (NodeMigrationException ex) {
- throw AxiomExceptionTranslator.translate(ex);
- }
+ coreAppendAttribute(decl);
return ns;
}
public final void AxiomElement.addNamespaceDeclaration(OMNamespace ns) {
AxiomNamespaceDeclaration decl = coreGetNodeFactory().createNode(AxiomNamespaceDeclaration.class);
decl.setDeclaredNamespace(ns);
- try {
- coreSetAttribute(Policies.NAMESPACE_DECLARATION_MATCHER, decl,
- NodeMigrationPolicy.MOVE_ALWAYS, true, null, ReturnValue.NONE);
- } catch (NodeMigrationException ex) {
- throw AxiomExceptionTranslator.translate(ex);
- }
+ coreSetAttribute(Policies.NAMESPACE_DECLARATION_MATCHER, decl, true, null);
}
@SuppressWarnings("rawtypes")
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Policies.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Policies.java?rev=1706166&r1=1706165&r2=1706166&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Policies.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Policies.java Wed Sep 30 22:37:45 2015
@@ -27,7 +27,6 @@ import org.apache.axiom.core.CoreParentN
import org.apache.axiom.core.DetachPolicy;
import org.apache.axiom.core.NSAwareAttributeMatcher;
import org.apache.axiom.core.NamespaceDeclarationMatcher;
-import org.apache.axiom.core.NodeMigrationPolicy;
import org.apache.axiom.core.NodeType;
import org.apache.axiom.om.OMCloneOptions;
import org.apache.axiom.om.impl.intf.AxiomAttribute;
@@ -50,19 +49,6 @@ public final class Policies {
public static final AttributeMatcher NAMESPACE_DECLARATION_MATCHER = new NamespaceDeclarationMatcher(DETACH_POLICY);
- public static final NodeMigrationPolicy ATTRIBUTE_MIGRATION_POLICY = new NodeMigrationPolicy() {
- public Action getAction(boolean hasParent, boolean isForeignDocument, boolean isForeignModel) {
- // TODO: doesn't look correct for foreign documents
- return Action.CLONE;
- }
- };
-
- public static final NodeMigrationPolicy NODE_MIGRATION_POLICY = new NodeMigrationPolicy() {
- public Action getAction(boolean hasParent, boolean isForeignDocument, boolean isForeignModel) {
- return isForeignModel ? Action.CLONE : Action.MOVE;
- }
- };
-
public static final ClonePolicy<OMCloneOptions> CLONE_POLICY = new ClonePolicy<OMCloneOptions>() {
public Class<? extends CoreNode> getTargetNodeClass(OMCloneOptions options, CoreNode node) {
if (options != null && options.isPreserveModel()) {
Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=1706166&r1=1706165&r2=1706166&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java (original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java Wed Sep 30 22:37:45 2015
@@ -28,7 +28,6 @@ import java.util.Vector;
import org.apache.axiom.core.CoreChildNode;
import org.apache.axiom.core.CoreModelException;
-import org.apache.axiom.core.NodeMigrationPolicy;
import org.apache.axiom.dom.DOMDocument;
import org.apache.axiom.dom.DOMExceptionTranslator;
import org.apache.axiom.om.OMNode;
@@ -102,11 +101,7 @@ public class DocumentImpl extends Parent
if (sourceAttrs != null) {
int length = sourceAttrs.getLength();
for (int index = 0; index < length; index++) {
- try {
- ((ElementImpl)newElement).coreAppendAttribute((AttrImpl)importNode(sourceAttrs.item(index), true), NodeMigrationPolicy.MOVE_ALWAYS);
- } catch (CoreModelException ex) {
- throw DOMExceptionTranslator.translate(ex);
- }
+ ((ElementImpl)newElement).coreAppendAttribute((AttrImpl)importNode(sourceAttrs.item(index), true));
}
}
newNode = newElement;
Modified: webservices/axiom/trunk/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/pom.xml?rev=1706166&r1=1706165&r2=1706166&view=diff
==============================================================================
--- webservices/axiom/trunk/pom.xml (original)
+++ webservices/axiom/trunk/pom.xml Wed Sep 30 22:37:45 2015
@@ -473,6 +473,11 @@
<artifactId>abdera-parser</artifactId>
<version>1.1.3</version>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.10.19</version>
+ </dependency>
</dependencies>
</dependencyManagement>
Modified: webservices/axiom/trunk/testing/dom-testsuite/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/dom-testsuite/pom.xml?rev=1706166&r1=1706165&r2=1706166&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/dom-testsuite/pom.xml (original)
+++ webservices/axiom/trunk/testing/dom-testsuite/pom.xml Wed Sep 30 22:37:45 2015
@@ -83,6 +83,10 @@
<artifactId>asm</artifactId>
<version>5.0.3</version>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ </dependency>
</dependencies>
<build>
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=1706166&r1=1706165&r2=1706166&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 Wed Sep 30 22:37:45 2015
@@ -149,7 +149,8 @@ public final class DOMTestSuiteBuilder e
addTest(new org.apache.axiom.ts.dom.element.TestLookupPrefixEmptyNamespace(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestLookupPrefixExplicitMasked(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestLookupPrefixImplicitMasked(dbf));
- addTest(new org.apache.axiom.ts.dom.element.TestRemoveAttributeNotOwner(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestRemoveAttributeNodeForeignImplementation(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestRemoveAttributeNodeNotOwner(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestRemoveFirstChild(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestRemoveLastChild(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestRemoveSingleChild(dbf));
@@ -168,6 +169,7 @@ public final class DOMTestSuiteBuilder e
addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildSingle(dbf, false));
addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildSingle(dbf, true));
addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildWrongDocument(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSForeignImplementation(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSInUse(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSReplace(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSWrongDocument(dbf));
Added: webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeForeignImplementation.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeForeignImplementation.java?rev=1706166&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeForeignImplementation.java (added)
+++ webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeForeignImplementation.java Wed Sep 30 22:37:45 2015
@@ -0,0 +1,49 @@
+/*
+ * 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.element;
+
+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.Attr;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class TestRemoveAttributeNodeForeignImplementation extends DOMTestCase {
+ public TestRemoveAttributeNodeForeignImplementation(DocumentBuilderFactory dbf) {
+ super(dbf);
+ }
+
+ @Override
+ protected void runTest() throws Throwable {
+ Document document = dbf.newDocumentBuilder().newDocument();
+ Element element = document.createElementNS(null, "test");
+ Attr attr = mock(Attr.class);
+ try {
+ element.removeAttributeNode(attr);
+ fail("Expected DOMException");
+ } catch (DOMException ex) {
+ assertThat(ex.code).isEqualTo(DOMException.NOT_FOUND_ERR);
+ }
+ }
+}
Propchange: webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeForeignImplementation.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeNotOwner.java (from r1704765, webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNotOwner.java)
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeNotOwner.java?p2=webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeNotOwner.java&p1=webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNotOwner.java&r1=1704765&r2=1706166&rev=1706166&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNotOwner.java (original)
+++ webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeNotOwner.java Wed Sep 30 22:37:45 2015
@@ -30,8 +30,8 @@ import org.w3c.dom.Element;
* Tests the behavior of {@link Element#removeAttributeNode(Attr)} if the given attribute is not
* owned by the element.
*/
-public class TestRemoveAttributeNotOwner extends DOMTestCase {
- public TestRemoveAttributeNotOwner(DocumentBuilderFactory dbf) {
+public class TestRemoveAttributeNodeNotOwner extends DOMTestCase {
+ public TestRemoveAttributeNodeNotOwner(DocumentBuilderFactory dbf) {
super(dbf);
}
Added: webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSForeignImplementation.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSForeignImplementation.java?rev=1706166&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSForeignImplementation.java (added)
+++ webservices/axiom/trunk/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSForeignImplementation.java Wed Sep 30 22:37:45 2015
@@ -0,0 +1,49 @@
+/*
+ * 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.element;
+
+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.Attr;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class TestSetAttributeNodeNSForeignImplementation extends DOMTestCase {
+ public TestSetAttributeNodeNSForeignImplementation(DocumentBuilderFactory dbf) {
+ super(dbf);
+ }
+
+ @Override
+ protected void runTest() throws Throwable {
+ Document document = dbf.newDocumentBuilder().newDocument();
+ Element element = document.createElementNS(null, "test");
+ Attr attr = mock(Attr.class);
+ try {
+ element.setAttributeNodeNS(attr);
+ 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/element/TestSetAttributeNodeNSForeignImplementation.java
------------------------------------------------------------------------------
svn:eol-style = native