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/13 10:48:16 UTC
svn commit: r1685220 [2/2] - in /webservices/axiom/branches/attrs-aspects:
aspects/core-aspects/src/main/java/org/apache/axiom/core/
aspects/dom-aspects/src/main/java/org/apache/axiom/dom/
implementations/axiom-dom/src/main/java/org/apache/axiom/om/imp...
Added: 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=1685220&view=auto
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareAttribute.java (added)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareAttribute.java Sat Jun 13 08:48:15 2015
@@ -0,0 +1,182 @@
+/*
+ * 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.om.impl.dom;
+
+import javax.xml.XMLConstants;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMConstants;
+import org.apache.axiom.om.OMFactory;
+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 AttrImpl implements OMAttributeEx, AxiomAttribute, NamedNode {
+ // TODO: copy isId?
+ NSAwareAttribute(String localName, OMNamespace namespace, String type, OMFactory factory) {
+ super(null, factory);
+ internalSetLocalName(localName);
+ internalSetNamespace(namespace);
+ this.type = type;
+ }
+
+ 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) {
+ throw new IllegalArgumentException("Cannot create an unprefixed attribute with a namespace");
+ }
+ }
+ internalSetLocalName(localName);
+ coreAppendChild((AxiomText)factory.createOMText(value), false);
+ this.type = OMConstants.XMLATTRTYPE_CDATA;
+ 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();
+ if (namespace != null) {
+ if ((XMLConstants.XMLNS_ATTRIBUTE.equals(localName))) {
+ return localName;
+ } else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespace.getNamespaceURI())) {
+ return XMLConstants.XMLNS_ATTRIBUTE + ":" + localName;
+ } else if (namespace.getPrefix().equals("")) {
+ return localName;
+ } else {
+ return namespace.getPrefix() + ":" + localName;
+ }
+ } else {
+ return localName;
+ }
+ }
+
+ public String toString() {
+ OMNamespace namespace = getNamespace();
+ String localName = getLocalName();
+ return (namespace == null) ? localName : namespace
+ .getPrefix()
+ + ":" + localName;
+ }
+
+ /**
+ * An instance of <code>AttrImpl</code> can act as an <code>OMAttribute</code> and as well as an
+ * <code>org.w3c.dom.Attr</code>. So we first check if the object to compare with (<code>obj</code>)
+ * is of type <code>OMAttribute</code> (this includes instances of <code>OMAttributeImpl</code> or
+ * <code>AttrImpl</code> (instances of this class)). If so we check for the equality
+ * of namespaces first (note that if the namespace of this instance is null then for the <code>obj</code>
+ * to be equal its namespace must also be null). This condition solely doesn't determine the equality.
+ * So we check for the equality of names and values (note that the value can also be null in which case
+ * the same argument holds as that for the namespace) of the two instances. If all three conditions are
+ * met then we say the two instances are equal.
+ *
+ * <p>If <code>obj</code> is of type <code>org.w3c.dom.Attr</code> then we perform the same equality check
+ * as before. Note that, however, the implementation of the test for equality in this case is little different
+ * than before.
+ *
+ * <p>If <code>obj</code> is neither of type <code>OMAttribute</code> nor of type <code>org.w3c.dom.Attr</code>
+ * then we return false.
+ *
+ * @param obj The object to compare with this instance
+ * @return True if the two objects are equal or else false. The equality is checked as explained above.
+ */
+ public boolean equals(Object obj) {
+ OMNamespace namespace = getNamespace();
+ String localName = getLocalName();
+ String attrValue = getValue();
+ if (obj instanceof OMAttribute) { // Checks equality of an OMAttributeImpl or an AttrImpl with this instance
+ OMAttribute other = (OMAttribute) obj;
+ return (namespace == null ? other.getNamespace() == null :
+ namespace.equals(other.getNamespace()) &&
+ localName.equals(other.getLocalName()) &&
+ (attrValue == null ? other.getAttributeValue() == null :
+ attrValue.toString().equals(other.getAttributeValue())));
+ } else if (obj instanceof Attr) {// Checks equality of an org.w3c.dom.Attr with this instance
+ Attr other = (Attr)obj;
+ String otherNs = other.getNamespaceURI();
+ if (namespace == null) { // I don't have a namespace
+ if (otherNs != null) {
+ return false; // I don't have a namespace and the other has. So return false
+ } else {
+ // Both of us don't have namespaces. So check for name and value equality only
+ return (localName.equals(other.getLocalName()) &&
+ (attrValue == null ? other.getValue() == null :
+ attrValue.toString().equals(other.getValue())));
+ }
+ } else { // Ok, now I've a namespace
+ String ns = namespace.getNamespaceURI();
+ String prefix = namespace.getPrefix();
+ String otherPrefix = other.getPrefix();
+ // First check for namespaceURI equality. Then check for prefix equality.
+ // Then check for name and value equality
+ return (ns.equals(otherNs) && (prefix == null ? otherPrefix == null : prefix.equals(otherPrefix)) &&
+ (localName.equals(other.getLocalName())) &&
+ (attrValue == null ? other.getValue() == null :
+ attrValue.toString().equals(other.getValue())));
+ }
+ }
+ return false;
+ }
+
+ public int hashCode() {
+ OMNamespace namespace = getNamespace();
+ String localName = getLocalName();
+ String attrValue = getValue();
+ return localName.hashCode() ^ (attrValue != null ? attrValue.toString().hashCode() : 0) ^
+ (namespace != null ? namespace.hashCode() : 0);
+ }
+}
Propchange: webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareAttribute.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamespaceDeclaration.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamespaceDeclaration.java?rev=1685220&view=auto
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamespaceDeclaration.java (added)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamespaceDeclaration.java Sat Jun 13 08:48:15 2015
@@ -0,0 +1,42 @@
+/*
+ * 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.om.impl.dom;
+
+import org.apache.axiom.dom.DOMNamespaceDeclaration;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+
+final class NamespaceDeclaration extends AttrImpl implements DOMNamespaceDeclaration {
+ private OMNamespace declaredNamespace;
+
+ NamespaceDeclaration(DocumentImpl ownerDocument, OMNamespace namespace, OMFactory factory) {
+ super(ownerDocument, factory);
+ coreSetValue(namespace.getNamespaceURI());
+ declaredNamespace = namespace;
+ }
+
+ public String coreGetDeclaredPrefix() {
+ return declaredNamespace.getPrefix();
+ }
+
+ // TODO: should be part of a DOM aspect
+ public String coreGetDeclaredNamespaceURI() {
+ return getValue();
+ }
+}
Propchange: webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamespaceDeclaration.java
------------------------------------------------------------------------------
svn:eol-style = native
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=1685220&r1=1685219&r2=1685220&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 08:48:15 2015
@@ -22,6 +22,8 @@ package org.apache.axiom.om.impl.dom.fac
import org.apache.axiom.core.CoreCDATASection;
import org.apache.axiom.core.CoreCharacterData;
import org.apache.axiom.core.CoreDocument;
+import org.apache.axiom.core.CoreNSAwareAttribute;
+import org.apache.axiom.core.CoreNamespaceDeclaration;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMComment;
import org.apache.axiom.om.OMContainer;
@@ -50,6 +52,7 @@ import org.apache.axiom.om.impl.dom.Docu
import org.apache.axiom.om.impl.dom.DocumentTypeImpl;
import org.apache.axiom.om.impl.dom.ElementImpl;
import org.apache.axiom.om.impl.dom.EntityReferenceImpl;
+import org.apache.axiom.om.impl.dom.NSAwareAttribute;
import org.apache.axiom.om.impl.dom.OMDOMException;
import org.apache.axiom.om.impl.dom.ParentNode;
import org.apache.axiom.om.impl.dom.ProcessingInstructionImpl;
@@ -193,7 +196,7 @@ public class OMDOMFactory implements Axi
ns = new OMNamespaceImpl(namespaceURI, OMSerializerUtil.getNextNSPrefix());
}
}
- return new AttrImpl(null, localName, ns, value, this);
+ return new NSAwareAttribute(null, localName, ns, value, this);
}
public OMDocType createOMDocType(OMContainer parent, String rootName, String publicId,
@@ -322,4 +325,16 @@ public class OMDOMFactory implements Axi
public CoreCDATASection createCDATASection() {
return new CDATASectionImpl(this);
}
+
+ public CoreNSAwareAttribute createAttribute(CoreDocument document, String namespaceURI,
+ String localName, String prefix, String value, String type) {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public final CoreNamespaceDeclaration createNamespaceDeclaration(CoreDocument document,
+ String prefix, String namespaceURI) {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
}
Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderBlockImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderBlockImpl.java?rev=1685220&r1=1685219&r2=1685220&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderBlockImpl.java (original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPHeaderBlockImpl.java Sat Jun 13 08:48:15 2015
@@ -30,6 +30,7 @@ import org.apache.axiom.om.impl.common.O
import org.apache.axiom.om.impl.dom.AttrImpl;
import org.apache.axiom.om.impl.dom.DocumentImpl;
import org.apache.axiom.om.impl.dom.ElementImpl;
+import org.apache.axiom.om.impl.dom.NSAwareAttribute;
import org.apache.axiom.om.impl.dom.ParentNode;
import org.apache.axiom.soap.SOAPCloneOptions;
import org.apache.axiom.soap.SOAPConstants;
@@ -61,7 +62,7 @@ public abstract class SOAPHeaderBlockImp
if (omAttribute != null) {
omAttribute.setAttributeValue(attrValue);
} else {
- OMAttribute attribute = new AttrImpl((DocumentImpl)getOwnerDocument(), attributeName,
+ OMAttribute attribute = new NSAwareAttribute((DocumentImpl)getOwnerDocument(), attributeName,
new OMNamespaceImpl(soapEnvelopeNamespaceURI,
SOAPConstants.SOAP_DEFAULT_NAMESPACE_PREFIX),
attrValue, getOMFactory());
Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12FaultTextImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12FaultTextImpl.java?rev=1685220&r1=1685219&r2=1685220&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12FaultTextImpl.java (original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12FaultTextImpl.java Sat Jun 13 08:48:15 2015
@@ -29,6 +29,7 @@ import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.impl.dom.AttrImpl;
import org.apache.axiom.om.impl.dom.DocumentImpl;
+import org.apache.axiom.om.impl.dom.NSAwareAttribute;
import org.apache.axiom.om.impl.dom.ParentNode;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.soap.SOAPFactory;
@@ -67,7 +68,7 @@ public class SOAP12FaultTextImpl extends
public void setLang(String lang) {
langAttr =
- new AttrImpl((DocumentImpl)getOwnerDocument(),
+ new NSAwareAttribute((DocumentImpl)getOwnerDocument(),
SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_LOCAL_NAME,
langNamespace,
lang, getOMFactory());
Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java?rev=1685220&r1=1685219&r2=1685220&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java (original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java Sat Jun 13 08:48:15 2015
@@ -82,6 +82,10 @@ public class OMAttributeImpl extends OMI
this.value = value;
}
+ public void coreSetValue(String value) {
+ setAttributeValue(value);
+ }
+
public String getAttributeType() {
return type;
}
Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java?rev=1685220&r1=1685219&r2=1685220&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java (original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java Sat Jun 13 08:48:15 2015
@@ -22,6 +22,8 @@ package org.apache.axiom.om.impl.llom.fa
import org.apache.axiom.core.CoreCDATASection;
import org.apache.axiom.core.CoreCharacterData;
import org.apache.axiom.core.CoreDocument;
+import org.apache.axiom.core.CoreNSAwareAttribute;
+import org.apache.axiom.core.CoreNamespaceDeclaration;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMComment;
@@ -343,4 +345,16 @@ public class OMLinkedListImplFactory imp
public CoreCDATASection createCDATASection() {
return new CDATASectionImpl(this);
}
+
+ public CoreNSAwareAttribute createAttribute(CoreDocument document, String namespaceURI,
+ String localName, String prefix, String value, String type) {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public final CoreNamespaceDeclaration createNamespaceDeclaration(CoreDocument document,
+ String prefix, String namespaceURI) {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
}