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/06/14 00:13:08 UTC
svn commit: r1685338 - in
/webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom:
DocumentImpl.java ElementImpl.java NSAwareAttribute.java
factory/OMDOMFactory.java
Author: veithen
Date: Sat Jun 13 22:13:08 2015
New Revision: 1685338
URL: http://svn.apache.org/r1685338
Log:
Some more fixes to make the axiom-dom build succeed.
Modified:
webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareAttribute.java
webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=1685338&r1=1685337&r2=1685338&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java (original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java Sat Jun 13 22:13:08 2015
@@ -22,7 +22,10 @@ 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.CoreModelException;
+import org.apache.axiom.core.NodeMigrationPolicy;
import org.apache.axiom.dom.DOMDocument;
+import org.apache.axiom.dom.DOMExceptionUtil;
import org.apache.axiom.om.OMCloneOptions;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
@@ -201,17 +204,11 @@ public class DocumentImpl extends RootNo
if (sourceAttrs != null) {
int length = sourceAttrs.getLength();
for (int index = 0; index < length; index++) {
- Attr attr = (Attr) sourceAttrs.item(index);
- if (attr.getNamespaceURI() != null
- && !attr.getNamespaceURI().equals(
- XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
- Attr newAttr = (Attr) importNode(attr, true);
- newElement.setAttributeNodeNS(newAttr);
- } else { // if (attr.getLocalName() == null) {
- Attr newAttr = (Attr) importNode(attr, true);
- newElement.setAttributeNode(newAttr);
+ try {
+ ((ElementImpl)newElement).coreAppendAttribute((AttrImpl)importNode(sourceAttrs.item(index), true), NodeMigrationPolicy.MOVE_ALWAYS);
+ } catch (CoreModelException ex) {
+ throw DOMExceptionUtil.translate(ex);
}
-
}
}
newNode = newElement;
@@ -222,15 +219,10 @@ public class DocumentImpl extends RootNo
if (importedNode.getLocalName() == null) {
newNode = createAttribute(importedNode.getNodeName());
} else {
- //Check whether it is a default ns decl
- if (XMLConstants.XMLNS_ATTRIBUTE.equals(importedNode.getNodeName())) {
- newNode = createAttribute(importedNode.getNodeName());
- } else {
- String ns = importedNode.getNamespaceURI();
- ns = (ns != null) ? ns.intern() : null;
- newNode = createAttributeNS(ns ,
- importedNode.getNodeName());
- }
+ String ns = importedNode.getNamespaceURI();
+ ns = (ns != null) ? ns.intern() : null;
+ newNode = createAttributeNS(ns ,
+ importedNode.getNodeName());
}
((Attr) newNode).setValue(importedNode.getNodeValue());
break;
Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1685338&r1=1685337&r2=1685338&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java (original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java Sat Jun 13 22:13:08 2015
@@ -92,12 +92,12 @@ public class ElementImpl extends ParentN
private final String checkNamespaceIsDeclared(String prefix, String namespaceURI, boolean allowDefaultNamespace, boolean declare) {
if (prefix == null) {
- if (namespaceURI.isEmpty()) {
+ if (namespaceURI.length() == 0) {
prefix = "";
declare = false;
} else {
prefix = coreLookupPrefix(namespaceURI, true);
- if (prefix != null && (allowDefaultNamespace || !prefix.isEmpty())) {
+ if (prefix != null && (allowDefaultNamespace || prefix.length() != 0)) {
declare = false;
} else {
prefix = OMSerializerUtil.getNextNSPrefix();
@@ -162,7 +162,7 @@ public class ElementImpl extends ParentN
}
try {
- coreSetAttribute(Policies.ATTRIBUTE_MATCHER, (AxiomAttribute)attr, Policies.ATTRIBUTE_MIGRATION_POLICY, true, null, ReturnValue.NONE);
+ coreSetAttribute(Policies.ATTRIBUTE_MATCHER, (AxiomAttribute)attr, NodeMigrationPolicy.MOVE_ALWAYS, true, null, ReturnValue.NONE);
} catch (NodeMigrationException ex) {
DOMExceptionUtil.translate(ex);
}
@@ -408,7 +408,7 @@ public class ElementImpl extends ParentN
if (attr.getOwner() != this) {
throw new OMException("The attribute is not owned by this element");
}
- ((AttrImpl)attr).coreRemove();
+ ((AttrImpl)attr).coreRemove(null);
}
public void setNamespace(OMNamespace namespace) {
@@ -458,10 +458,9 @@ public class ElementImpl extends ParentN
NamedNodeMap attributes = getAttributes();
ArrayList list = new ArrayList();
for (int i = 0; i < attributes.getLength(); i++) {
- OMAttribute item = (OMAttribute) attributes.item(i);
- if (item.getNamespace() == null
- || !(item.getNamespace() != null && XMLConstants.XMLNS_ATTRIBUTE_NS_URI
- .equals(item.getNamespace().getNamespaceURI()))) {
+ AttrImpl item = (AttrImpl) attributes.item(i);
+ // TODO: what about NS unaware attributes here?
+ if (item instanceof TypedAttribute) {
list.add(item);
}
}
@@ -485,13 +484,18 @@ public class ElementImpl extends ParentN
AttrImpl attr = (AttrImpl)attributes.item(i);
AttrImpl clonedAttr = (AttrImpl)attr.clone(options, null, true, false);
clonedAttr.setSpecified(attr.getSpecified());
+ if (namespaceRepairing && attr instanceof NSAwareAttribute) {
+ NSAwareAttribute nsAwareAttr = (NSAwareAttribute)attr;
+ String namespaceURI = nsAwareAttr.coreGetNamespaceURI();
+ if (namespaceURI.length() != 0) {
+ clone.checkNamespaceIsDeclared(nsAwareAttr.coreGetPrefix(), namespaceURI, false, true);
+ }
+ }
try {
clone.coreAppendAttribute(clonedAttr, NodeMigrationPolicy.MOVE_ALWAYS);
} catch (NodeMigrationException ex) {
DOMExceptionUtil.translate(ex);
}
- // TODO: namespace repairing
-// clone.setAttributeNodeNS(clonedAttr, false, namespaceRepairing && !XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attr.getNamespaceURI()));
}
return clone;
}
Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareAttribute.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareAttribute.java?rev=1685338&r1=1685337&r2=1685338&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareAttribute.java (original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareAttribute.java Sat Jun 13 22:13:08 2015
@@ -29,7 +29,6 @@ import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.impl.OMAttributeEx;
import org.apache.axiom.om.impl.common.AxiomAttribute;
import org.apache.axiom.om.impl.common.AxiomText;
-import org.apache.axiom.om.impl.common.OMNamespaceImpl;
import org.w3c.dom.Attr;
public final class NSAwareAttribute extends TypedAttribute implements OMAttributeEx, AxiomAttribute, NamedNode, CoreNSAwareAttribute {
@@ -44,18 +43,6 @@ public final class NSAwareAttribute exte
public NSAwareAttribute(DocumentImpl ownerDocument, String localName,
OMNamespace ns, String value, OMFactory factory) {
super(ownerDocument, factory);
- if (ns != null) {
- if (ns.getNamespaceURI().length() == 0) {
- if (ns.getPrefix().length() > 0) {
- throw new IllegalArgumentException("Cannot create a prefixed attribute with an empty namespace name");
- } else {
- ns = null;
- }
- } else if (ns.getPrefix().length() == 0) {
- // TODO: allowed by DOM
-// throw new IllegalArgumentException("Cannot create an unprefixed attribute with a namespace");
- }
- }
internalSetLocalName(localName);
if (value != null && value.length() != 0) {
coreAppendChild((AxiomText)factory.createOMText(value), false);
@@ -64,34 +51,6 @@ public final class NSAwareAttribute exte
internalSetNamespace(ns);
}
- public NSAwareAttribute(DocumentImpl ownerDocument, String name, String value,
- OMFactory factory) {
- super(ownerDocument, factory);
- internalSetLocalName(name);
- coreAppendChild((AxiomText)factory.createOMText(value), false);
- this.type = OMConstants.XMLATTRTYPE_CDATA;
- }
-
- public NSAwareAttribute(DocumentImpl ownerDocument, String name, OMFactory factory) {
- super(ownerDocument, factory);
- internalSetLocalName(name);
- //If this is a default namespace attr
- if (XMLConstants.XMLNS_ATTRIBUTE.equals(name)) {
- // TODO: this looks wrong; if the attribute name is "xmlns", then the prefix shouldn't be "xmlns"
- internalSetNamespace(new OMNamespaceImpl(
- XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE));
- }
- this.type = OMConstants.XMLATTRTYPE_CDATA;
- }
-
- public NSAwareAttribute(DocumentImpl ownerDocument, String localName,
- OMNamespace namespace, OMFactory factory) {
- super(ownerDocument, factory);
- internalSetLocalName(localName);
- internalSetNamespace(namespace);
- this.type = OMConstants.XMLATTRTYPE_CDATA;
- }
-
public String getName() {
OMNamespace namespace = getNamespace();
String localName = getLocalName();
Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java?rev=1685338&r1=1685337&r2=1685338&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java (original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java Sat Jun 13 22:13:08 2015
@@ -198,6 +198,17 @@ public class OMDOMFactory implements Axi
ns = new OMNamespaceImpl(namespaceURI, OMSerializerUtil.getNextNSPrefix());
}
}
+ if (ns != null) {
+ if (ns.getNamespaceURI().length() == 0) {
+ if (ns.getPrefix().length() > 0) {
+ throw new IllegalArgumentException("Cannot create a prefixed attribute with an empty namespace name");
+ } else {
+ ns = null;
+ }
+ } else if (ns.getPrefix().length() == 0) {
+ throw new IllegalArgumentException("Cannot create an unprefixed attribute with a namespace");
+ }
+ }
return new NSAwareAttribute(null, localName, ns, value, this);
}
@@ -338,7 +349,7 @@ public class OMDOMFactory implements Axi
public final CoreNSAwareAttribute createAttribute(CoreDocument document, String namespaceURI,
String localName, String prefix, String value, String type) {
- return new NSAwareAttribute((DocumentImpl)document, localName, namespaceURI.isEmpty() ? null : new OMNamespaceImpl(namespaceURI, prefix), value, this);
+ return new NSAwareAttribute((DocumentImpl)document, localName, namespaceURI.length() == 0 ? null : new OMNamespaceImpl(namespaceURI, prefix), value, this);
}
public final CoreNamespaceDeclaration createNamespaceDeclaration(CoreDocument document,