Author: veithen
Date: Sat Jul 12 19:16:36 2014
New Revision: 1610024
URL: http://svn.apache.org/r1610024
Log:
Unify the code that manages element and attribute names.
Added:
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMAttributeSupport.aj
Modified:
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/INamedInformationItem.java
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMElementSupport.aj
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMNamedInformationItemSupport.aj
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamedNodeSupport.aj
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
Modified:
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/INamedInformationItem.java
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/INamedInformationItem.java?rev=1610024&r1=1610023&r2=1610024&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/INamedInformationItem.java
(original)
+++
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/INamedInformationItem.java
Sat Jul 12 19:16:36 2014
@@ -19,16 +19,7 @@
package org.apache.axiom.om.impl.common;
import org.apache.axiom.om.OMNamedInformationItem;
-import org.apache.axiom.om.OMNamespace;
public interface INamedInformationItem extends OMNamedInformationItem {
- String internalGetLocalName();
- void internalSetLocalName(String localName);
-
- /**
- * Set the namespace of the node without adding a corresponding namespace
declaration.
- *
- * @param namespace
- */
- void internalSetNamespace(OMNamespace namespace);
+
}
Added:
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMAttributeSupport.aj
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMAttributeSupport.aj?rev=1610024&view=auto
==============================================================================
---
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMAttributeSupport.aj
(added)
+++
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMAttributeSupport.aj
Sat Jul 12 19:16:36 2014
@@ -0,0 +1,31 @@
+/*
+ * 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.common;
+
+import org.apache.axiom.om.OMNamespace;
+
+public aspect OMAttributeSupport {
+ public final void IAttribute.setNamespace(OMNamespace namespace, boolean
decl) {
+ internalSetNamespace(handleNamespace((IElement)getOwner(), namespace,
true, decl));
+ }
+
+ public final void IAttribute.setOMNamespace(OMNamespace omNamespace) {
+ internalSetNamespace(omNamespace);
+ }
+}
Modified:
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMElementSupport.aj
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMElementSupport.aj?rev=1610024&r1=1610023&r2=1610024&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMElementSupport.aj
(original)
+++
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMElementSupport.aj
Sat Jul 12 19:16:36 2014
@@ -54,6 +54,14 @@ public aspect OMElementSupport {
return OMNode.ELEMENT_NODE;
}
+ public void IElement.setNamespaceWithNoFindInCurrentScope(OMNamespace
namespace) {
+ internalSetNamespace(namespace);
+ }
+
+ public void IElement.setNamespace(OMNamespace namespace, boolean decl) {
+ internalSetNamespace(handleNamespace(this, namespace, false, decl));
+ }
+
public NamespaceContext IElement.getNamespaceContext(boolean detached) {
if (detached) {
Map namespaces = new HashMap();
Modified:
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMNamedInformationItemSupport.aj
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMNamedInformationItemSupport.aj?rev=1610024&r1=1610023&r2=1610024&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMNamedInformationItemSupport.aj
(original)
+++
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMNamedInformationItemSupport.aj
Sat Jul 12 19:16:36 2014
@@ -18,18 +18,103 @@
*/
package org.apache.axiom.om.impl.common;
+import javax.xml.namespace.QName;
+
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.impl.util.OMSerializerUtil;
public aspect OMNamedInformationItemSupport {
- public final OMNamespace INamedInformationItem.handleNamespace(IElement
context, OMNamespace ns, boolean attr, boolean declare) {
+ /**
+ * The namespace of the information item. Possible values:
+ * <ul>
+ * <li><code>null</code> (if the information item has no namespace)
+ * <li>any {@link OMNamespace} instance, with the following exceptions:
+ * <ul>
+ * <li>an {@link OMNamespace} instance with a <code>null</code> prefix
+ * <li>for elements: an {@link OMNamespace} instance with both prefix and
namespace URI set to
+ * the empty string
+ * <li>for attributes: an {@link OMNamespace} instance with an empty
prefix (because an
+ * unprefixed attribute never has a namespace)
+ * </ul>
+ * </ul>
+ */
+ private OMNamespace INamedInformationItem.namespace;
+
+ private String INamedInformationItem.localName;
+ private QName INamedInformationItem.qName;
+
+ /**
+ * Set the namespace of the node without adding a corresponding namespace
declaration.
+ *
+ * @param namespace
+ */
+ public final void INamedInformationItem.internalSetNamespace(OMNamespace
namespace) {
+ this.namespace = namespace;
+ qName = null;
+ }
+
+ public final String INamedInformationItem.internalGetLocalName() {
+ return localName;
+ }
+
+ public final void INamedInformationItem.internalSetLocalName(String
localName) {
+ this.localName = localName;
+ }
+
+ public OMNamespace INamedInformationItem.getNamespace() {
+ return namespace;
+ }
+
+ public final String INamedInformationItem.getPrefix() {
+ OMNamespace namespace = getNamespace();
+ if (namespace == null) {
+ return null;
+ } else {
+ String prefix = namespace.getPrefix();
+ return prefix.length() == 0 ? null : prefix;
+ }
+ }
+
+ public String INamedInformationItem.getLocalName() {
+ return localName;
+ }
+
+ public void INamedInformationItem.setLocalName(String localName) {
+ this.localName = localName;
+ qName = null;
+ }
+
+ public QName INamedInformationItem.getQName() {
+ if (qName != null) {
+ return qName;
+ }
+
+ if (namespace != null) {
+ qName = new QName(namespace.getNamespaceURI(), localName,
namespace.getPrefix());
+ } else {
+ qName = new QName(localName);
+ }
+ return qName;
+ }
+
+ public boolean INamedInformationItem.hasName(QName name) {
+ if (name.getLocalPart().equals(getLocalName())) {
+ OMNamespace ns = getNamespace();
+ return ns == null && name.getNamespaceURI().length() == 0
+ || ns != null &&
name.getNamespaceURI().equals(ns.getNamespaceURI());
+ } else {
+ return false;
+ }
+ }
+
+ public final OMNamespace INamedInformationItem.handleNamespace(IElement
context, OMNamespace ns, boolean attr, boolean decl) {
String namespaceURI = ns == null ? "" : ns.getNamespaceURI();
String prefix = ns == null ? "" : ns.getPrefix();
if (namespaceURI.length() == 0) {
if (prefix != null && prefix.length() != 0) {
throw new IllegalArgumentException("Cannot bind a prefix to
the empty namespace name");
}
- if (!attr && declare) {
+ if (!attr && decl) {
// Special case: no namespace; we need to generate a namespace
declaration only if
// there is a conflicting namespace declaration (i.e. a
declaration for the default
// namespace with a non empty URI) is in scope
@@ -43,12 +128,12 @@ public aspect OMNamedInformationItemSupp
throw new IllegalArgumentException("An attribute with a
namespace must be prefixed");
}
boolean addNSDecl = false;
- if (context != null && (declare || prefix == null)) {
+ if (context != null && (decl || prefix == null)) {
OMNamespace existingNSDecl =
context.findNamespace(namespaceURI, prefix);
if (existingNSDecl == null
|| (prefix != null &&
!existingNSDecl.getPrefix().equals(prefix))
|| (prefix == null && attr &&
existingNSDecl.getPrefix().length() == 0)) {
- addNSDecl = declare;
+ addNSDecl = decl;
} else {
prefix = existingNSDecl.getPrefix();
ns = existingNSDecl;
Modified:
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java?rev=1610024&r1=1610023&r2=1610024&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
(original)
+++
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
Sat Jul 12 19:16:36 2014
@@ -39,29 +39,12 @@ import org.w3c.dom.Text;
import org.w3c.dom.TypeInfo;
import javax.xml.XMLConstants;
-import javax.xml.namespace.QName;
/** Implementation of <code>org.w3c.dom.Attr</code> and
<code>org.apache.axiom.om.OMAttribute</code> */
public class AttrImpl extends RootNode implements OMAttributeEx, IAttribute,
Attr, NamedNode, NonDeferringParentNode {
- private String localName;
-
private String type;
/**
- * The namespace of this attribute. Possible values:
- * <ul>
- * <li><code>null</code> (if the attribute has no namespace)
- * <li>any {@link OMNamespace} instance, with the following exceptions:
- * <ul>
- * <li>an {@link OMNamespace} instance with a <code>null</code> prefix
- * <li>an {@link OMNamespace} instance with an empty prefix (because an
unprefixed attribute
- * never has a namespace)
- * </ul>
- * </ul>
- */
- private OMNamespace namespace;
-
- /**
* Owner of this attribute. This is either the owner element or the owner
document (if the
* attribute doesn't have an owner element).
*/
@@ -78,8 +61,8 @@ public class AttrImpl extends RootNode i
// TODO: copy isId?
private AttrImpl(String localName, OMNamespace namespace, String type,
OMFactory factory) {
this(null, factory);
- this.localName = localName;
- this.namespace = namespace;
+ internalSetLocalName(localName);
+ internalSetNamespace(namespace);
this.type = type;
}
@@ -97,28 +80,28 @@ public class AttrImpl extends RootNode i
throw new IllegalArgumentException("Cannot create an
unprefixed attribute with a namespace");
}
}
- this.localName = localName;
+ internalSetLocalName(localName);
internalAppendChild(new TextImpl(value, factory));
this.type = OMConstants.XMLATTRTYPE_CDATA;
- this.namespace = ns;
+ internalSetNamespace(ns);
}
public AttrImpl(DocumentImpl ownerDocument, String name, String value,
OMFactory factory) {
this(ownerDocument, factory);
- this.localName = name;
+ internalSetLocalName(name);
internalAppendChild(new TextImpl(value, factory));
this.type = OMConstants.XMLATTRTYPE_CDATA;
}
public AttrImpl(DocumentImpl ownerDocument, String name, OMFactory
factory) {
this(ownerDocument, factory);
- this.localName = name;
+ 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"
- this.namespace = new OMNamespaceImpl(
- XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
XMLConstants.XMLNS_ATTRIBUTE);
+ internalSetNamespace(new OMNamespaceImpl(
+ XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
XMLConstants.XMLNS_ATTRIBUTE));
}
this.type = OMConstants.XMLATTRTYPE_CDATA;
}
@@ -126,8 +109,8 @@ public class AttrImpl extends RootNode i
public AttrImpl(DocumentImpl ownerDocument, String localName,
OMNamespace namespace, OMFactory factory) {
this(ownerDocument, factory);
- this.localName = localName;
- this.namespace = namespace;
+ internalSetLocalName(localName);
+ internalSetNamespace(namespace);
this.type = OMConstants.XMLATTRTYPE_CDATA;
}
@@ -145,11 +128,13 @@ public class AttrImpl extends RootNode i
/** Returns the name of this attribute. */
public String getNodeName() {
- return (this.namespace != null
- && !"".equals(this.namespace.getPrefix()) &&
- !(XMLConstants.XMLNS_ATTRIBUTE.equals(this.localName)))
- ? this.namespace.getPrefix() + ":" + this.localName
- : this.localName;
+ OMNamespace namespace = getNamespace();
+ String localName = getLocalName();
+ return (namespace != null
+ && !"".equals(namespace.getPrefix()) &&
+ !(XMLConstants.XMLNS_ATTRIBUTE.equals(localName)))
+ ? namespace.getPrefix() + ":" + localName
+ : localName;
}
/**
@@ -218,18 +203,20 @@ public class AttrImpl extends RootNode i
// /org.w3c.dom.Attr methods
// /
public String getName() {
- if (this.namespace != null) {
- if ((XMLConstants.XMLNS_ATTRIBUTE.equals(this.localName))) {
- return this.localName;
- } else if
(XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(this.namespace.getNamespaceURI())) {
- return XMLConstants.XMLNS_ATTRIBUTE + ":" + this.localName;
- } else if (this.namespace.getPrefix().equals("")) {
- return this.localName;
+ 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 this.namespace.getPrefix() + ":" + this.localName;
+ return namespace.getPrefix() + ":" + localName;
}
} else {
- return this.localName;
+ return localName;
}
}
@@ -264,35 +251,6 @@ public class AttrImpl extends RootNode i
flags = (short) (specified ? flags & ~DEFAULT_ATTR : flags |
DEFAULT_ATTR);
}
- /**
- * Returns the namespace of the attribute as an <code>OMNamespace</code>.
- *
- * @see org.apache.axiom.om.OMAttribute#getNamespace()
- */
- public OMNamespace getNamespace() {
- return this.namespace;
- }
-
- /**
- * Returns a qname representing the attribute.
- *
- * @see org.apache.axiom.om.OMAttribute#getQName()
- */
- public QName getQName() {
- return (namespace == null) ?
- new QName(this.localName) :
- new QName(namespace.getNamespaceURI(),
- localName,
- namespace.getPrefix());
-
- }
-
- public boolean hasName(QName name) {
- return name.getLocalPart().equals(localName)
- && (namespace == null && name.getNamespaceURI().length() == 0
- || namespace != null &&
name.getNamespaceURI().equals(namespace.getNamespaceURI()));
- }
-
public String getAttributeValue() {
return getValue();
}
@@ -302,32 +260,6 @@ public class AttrImpl extends RootNode i
}
/**
- * Sets the name of attribute.
- *
- * @see org.apache.axiom.om.OMAttribute#setLocalName(String)
- */
- public void setLocalName(String localName) {
- this.localName = localName;
- }
-
- public void internalSetNamespace(OMNamespace namespace) {
- this.namespace = namespace;
- }
-
- public void setNamespace(OMNamespace namespace, boolean declare) {
- this.namespace = handleNamespace(owner instanceof ElementImpl ?
(ElementImpl)owner : null, namespace, true, declare);
- }
-
- /**
- * Sets the namespace of this attribute node.
- *
- * @see org.apache.axiom.om.OMAttribute#setOMNamespace
(org.apache.axiom.om.OMNamespace)
- */
- public void setOMNamespace(OMNamespace omNamespace) {
- internalSetNamespace(omNamespace);
- }
-
- /**
* Sets the attribute value.
*
* @see org.apache.axiom.om.OMAttribute#setAttributeValue(String)
@@ -369,17 +301,14 @@ public class AttrImpl extends RootNode i
return null;
}
- public String getLocalName() {
- return localName;
- }
-
/**
* Returns the namespace URI of this attr node.
*
* @see org.w3c.dom.Node#getNamespaceURI()
*/
public String getNamespaceURI() {
- return (this.namespace != null) ? namespace.getNamespaceURI() : null;
+ OMNamespace namespace = getNamespace();
+ return namespace != null ? namespace.getNamespaceURI() : null;
}
/*
@@ -395,9 +324,11 @@ public class AttrImpl extends RootNode i
}
public String toString() {
- return (this.namespace == null) ? this.localName : this.namespace
+ OMNamespace namespace = getNamespace();
+ String localName = getLocalName();
+ return (namespace == null) ? localName : namespace
.getPrefix()
- + ":" + this.localName;
+ + ":" + localName;
}
public OMElement getOwner() {
@@ -426,6 +357,8 @@ public class AttrImpl extends RootNode i
* @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;
@@ -462,6 +395,8 @@ public class AttrImpl extends RootNode i
}
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);
@@ -473,7 +408,7 @@ public class AttrImpl extends RootNode i
ParentNode shallowClone(OMCloneOptions options, ParentNode targetParent,
boolean namespaceRepairing) {
// Note: targetParent is always null here
- return new AttrImpl(localName, namespace, type, getOMFactory());
+ return new AttrImpl(getLocalName(), getNamespace(), type,
getOMFactory());
}
public final boolean isComplete() {
@@ -499,12 +434,4 @@ public class AttrImpl extends RootNode i
Element ownerElement = getOwnerElement();
return ownerElement == null ? null :
ownerElement.lookupPrefix(namespaceURI);
}
-
- public final String internalGetLocalName() {
- return localName;
- }
-
- public final void internalSetLocalName(String localName) {
- this.localName = localName;
- }
}
Modified:
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java?rev=1610024&r1=1610023&r2=1610024&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
(original)
+++
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
Sat Jul 12 19:16:36 2014
@@ -120,4 +120,8 @@ public abstract class ChildNode extends
public final void setPrefix(String prefix) throws DOMException {
throw DOMUtil.newDOMException(DOMException.NAMESPACE_ERR);
}
+
+ public final String getLocalName() {
+ return null;
+ }
}
Modified:
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java?rev=1610024&r1=1610023&r2=1610024&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
(original)
+++
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
Sat Jul 12 19:16:36 2014
@@ -118,4 +118,8 @@ public class DocumentFragmentImpl extend
public final void setPrefix(String prefix) throws DOMException {
throw DOMUtil.newDOMException(DOMException.NAMESPACE_ERR);
}
+
+ public final String getLocalName() {
+ return null;
+ }
}
Modified:
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=1610024&r1=1610023&r2=1610024&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
(original)
+++
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
Sat Jul 12 19:16:36 2014
@@ -609,4 +609,8 @@ public class DocumentImpl extends RootNo
public final void setPrefix(String prefix) throws DOMException {
throw DOMUtil.newDOMException(DOMException.NAMESPACE_ERR);
}
+
+ public final String getLocalName() {
+ return null;
+ }
}
Modified:
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1610024&r1=1610023&r2=1610024&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
(original)
+++
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
Sat Jul 12 19:16:36 2014
@@ -68,22 +68,6 @@ public class ElementImpl extends ParentN
private int lineNumber;
- /**
- * The namespace of this element. Possible values:
- * <ul>
- * <li><code>null</code> (if the element has no namespace)
- * <li>any {@link OMNamespace} instance, with the following exceptions:
- * <ul>
- * <li>an {@link OMNamespace} instance with a <code>null</code> prefix
- * <li>an {@link OMNamespace} instance with both prefix and namespace URI
set to the empty
- * string
- * </ul>
- * </ul>
- */
- private OMNamespace namespace;
-
- private String localName;
-
private AttributeMap attributes;
private static final EmptyIterator EMPTY_ITERATOR = new EmptyIterator();
@@ -91,14 +75,14 @@ public class ElementImpl extends ParentN
public ElementImpl(ParentNode parentNode, String localName, OMNamespace
ns, OMXMLParserWrapper builder,
OMFactory factory, boolean generateNSDecl) {
super(factory);
- this.localName = localName;
+ internalSetLocalName(localName);
coreSetBuilder(builder);
coreSetState(builder == null ? COMPLETE : INCOMPLETE);
if (parentNode != null) {
((IContainer)parentNode).addChild(this, builder != null);
}
this.attributes = new AttributeMap(this);
- namespace = generateNSDecl ? handleNamespace(this, ns, false, true) :
ns;
+ internalSetNamespace(generateNSDecl ? handleNamespace(this, ns, false,
true) : ns);
}
final ParentNode internalGetOwnerNode() {
@@ -161,26 +145,29 @@ public class ElementImpl extends ParentN
* @see org.w3c.dom.Node#getNodeName()
*/
public String getNodeName() {
- if (this.namespace != null) {
- if (this.namespace.getPrefix() == null
- || "".equals(this.namespace.getPrefix())) {
- return this.localName;
+ OMNamespace namespace = getNamespace();
+ String localName = getLocalName();
+ if (namespace != null) {
+ if (namespace.getPrefix() == null
+ || "".equals(namespace.getPrefix())) {
+ return localName;
} else {
- return this.namespace.getPrefix() + ":" + this.localName;
+ return namespace.getPrefix() + ":" + localName;
}
} else {
- return this.localName;
+ return localName;
}
}
/** Returns the value of the namespace URI. */
public String getNamespaceURI() {
- if (this.namespace == null) {
+ OMNamespace namespace = getNamespace();
+ if (namespace == null) {
return null;
} else {
// If the element has no namespace, the result should be null, not
// an empty string.
- String uri = this.namespace.getNamespaceURI();
+ String uri = namespace.getNamespaceURI();
return uri.length() == 0 ? null : uri.intern();
}
}
@@ -527,6 +514,7 @@ public class ElementImpl extends ParentN
}
public OMNamespace declareDefaultNamespace(String uri) {
+ OMNamespace namespace = getNamespace();
if (namespace == null && uri.length() > 0
|| namespace != null && namespace.getPrefix().length() == 0 &&
!namespace.getNamespaceURI().equals(uri)) {
throw new OMException("Attempt to add a namespace declaration that
conflicts with " +
@@ -695,37 +683,6 @@ public class ElementImpl extends ParentN
return null;
}
- /**
- * Returns the namespace of this element.
- *
- * @see org.apache.axiom.om.OMElement#getNamespace()
- */
- public OMNamespace getNamespace() {
- return namespace;
- }
-
- /**
- * Returns the QName of this element.
- *
- * @see org.apache.axiom.om.OMElement#getQName()
- */
- public QName getQName() {
- QName qName;
- if (namespace != null) {
- qName = new QName(namespace.getNamespaceURI(), this.localName,
- namespace.getPrefix());
- } else {
- qName = new QName(this.localName);
- }
- return qName;
- }
-
- public boolean hasName(QName name) {
- return name.getLocalPart().equals(localName)
- && (namespace == null && name.getNamespaceURI().length() == 0
- || namespace != null &&
name.getNamespaceURI().equals(namespace.getNamespaceURI()));
- }
-
public void removeAttribute(OMAttribute attr) {
if (attr.getOwner() != this) {
throw new OMException("The attribute is not owned by this
element");
@@ -733,31 +690,10 @@ public class ElementImpl extends ParentN
attributes.remove((AttrImpl)attr, false);
}
- /**
- * Sets the local name.
- *
- * @see org.apache.axiom.om.OMElement#setLocalName(String)
- */
- public void setLocalName(String localName) {
- this.localName = localName;
- }
-
- public void internalSetNamespace(OMNamespace namespace) {
- this.namespace = namespace;
- }
-
- public void setNamespace(OMNamespace namespace, boolean declare) {
- this.namespace = handleNamespace(this, namespace, false, declare);
- }
-
public void setNamespace(OMNamespace namespace) {
setNamespace(namespace, true);
}
- public void setNamespaceWithNoFindInCurrentScope(OMNamespace namespace) {
- internalSetNamespace(namespace);
- }
-
public void internalSerialize(Serializer serializer,
OMOutputFormat format, boolean cache)
throws OutputException {
@@ -824,15 +760,6 @@ public class ElementImpl extends ParentN
return list.iterator();
}
- /**
- * Returns the local name of this element node
- *
- * @see org.w3c.dom.Node#getLocalName()
- */
- public String getLocalName() {
- return this.localName;
- }
-
public QName resolveQName(String qname) {
int idx = qname.indexOf(':');
if (idx == -1) {
@@ -854,7 +781,7 @@ public class ElementImpl extends ParentN
if (options.isPreserveModel()) {
clone = (ElementImpl)createClone(options, targetParent,
namespaceRepairing);
} else {
- clone = new ElementImpl(targetParent, localName, namespace, null,
getOMFactory(), namespaceRepairing);
+ clone = new ElementImpl(targetParent, getLocalName(),
getNamespace(), null, getOMFactory(), namespaceRepairing);
}
for (int i=0, l=attributes.getLength(); i<l; i++) {
AttrImpl attr = (AttrImpl)attributes.item(i);
@@ -866,7 +793,7 @@ public class ElementImpl extends ParentN
}
protected OMElement createClone(OMCloneOptions options, ParentNode
targetParent, boolean generateNSDecl) {
- return new ElementImpl(targetParent, localName, namespace, null,
getOMFactory(), generateNSDecl);
+ return new ElementImpl(targetParent, getLocalName(), getNamespace(),
null, getOMFactory(), generateNSDecl);
}
public void setLineNumber(int lineNumber) {
@@ -1088,12 +1015,4 @@ public class ElementImpl extends ParentN
public final void checkChild(OMNode child) {
}
-
- public final String internalGetLocalName() {
- return localName;
- }
-
- public final void internalSetLocalName(String localName) {
- this.localName = localName;
- }
}
Modified:
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamedNodeSupport.aj
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamedNodeSupport.aj?rev=1610024&r1=1610023&r2=1610024&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamedNodeSupport.aj
(original)
+++
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamedNodeSupport.aj
Sat Jul 12 19:16:36 2014
@@ -23,16 +23,6 @@ import org.apache.axiom.om.impl.common.O
import org.w3c.dom.DOMException;
aspect NamedNodeSupport {
- public final String NamedNode.getPrefix() {
- OMNamespace ns = getNamespace();
- if (ns == null) {
- return null;
- } else {
- String prefix = ns.getPrefix();
- return prefix.length() == 0 ? null : prefix;
- }
- }
-
public final void NamedNode.setPrefix(String prefix) throws DOMException {
if (prefix == null) {
prefix = "";
Modified:
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java?rev=1610024&r1=1610023&r2=1610024&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
(original)
+++
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
Sat Jul 12 19:16:36 2014
@@ -102,10 +102,6 @@ public abstract class NodeImpl extends I
return false; // Override in ParentNode
}
- public String getLocalName() {
- return null; // Override in AttrImpl and ElementImpl
- }
-
public String getNamespaceURI() {
return null; // Override in AttrImpl and ElementImpl
}
Modified:
webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java?rev=1610024&r1=1610023&r2=1610024&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
(original)
+++
webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
Sat Jul 12 19:16:36 2014
@@ -28,32 +28,12 @@ import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.common.IAttribute;
-import javax.xml.namespace.QName;
-
/** Class OMAttributeImpl */
public class OMAttributeImpl implements IAttribute {
- private String localName;
-
private String value;
private String type;
- /**
- * The namespace of this attribute. Possible values:
- * <ul>
- * <li><code>null</code> (if the attribute has no namespace)
- * <li>any {@link OMNamespace} instance, with the following exceptions:
- * <ul>
- * <li>an {@link OMNamespace} instance with a <code>null</code> prefix
- * <li>an {@link OMNamespace} instance with an empty prefix (because an
unprefixed attribute
- * never has a namespace)
- * </ul>
- * </ul>
- */
- private OMNamespace namespace;
-
- private QName qName;
-
/** <code>OMFactory</code> that created this <code>OMAttribute</code> */
private OMFactory factory;
@@ -84,56 +64,15 @@ public class OMAttributeImpl implements
}
}
- this.localName = localName;
+ internalSetLocalName(localName);
this.value = value;
- this.namespace = ns;
+ internalSetNamespace(ns);
this.type = OMConstants.XMLATTRTYPE_CDATA;
this.factory = factory;
}
- /** @return Returns QName. */
- public QName getQName() {
- if (qName != null) {
- return qName;
- }
-
- if (namespace != null) {
- this.qName = new QName(namespace.getNamespaceURI(), localName,
namespace.getPrefix());
- } else {
- this.qName = new QName(localName);
- }
- return this.qName;
- }
-
- public boolean hasName(QName name) {
- return name.getLocalPart().equals(localName)
- && (namespace == null && name.getNamespaceURI().length() == 0
- || namespace != null &&
name.getNamespaceURI().equals(namespace.getNamespaceURI()));
- }
-
// -------- Getters and Setters
- /**
- * Method getLocalName.
- *
- * @return Returns local name.
- */
- public String getLocalName() {
- return localName;
- }
-
- /**
- * Method setLocalName.
- *
- * @param localName
- */
- public void setLocalName(String localName) {
- if (localName == null || localName.trim().length() == 0)
- throw new IllegalArgumentException("Local name may not be null or
empty");
- this.localName = localName;
- this.qName = null;
- }
-
public String getAttributeValue() {
return value;
}
@@ -160,45 +99,6 @@ public class OMAttributeImpl implements
this.type = type;
}
- public final void internalSetNamespace(OMNamespace namespace) {
- this.namespace = namespace;
- this.qName = null;
- }
-
- public void setNamespace(OMNamespace namespace, boolean declare) {
- this.namespace = handleNamespace(owner, namespace, true, declare);
- this.qName = null;
- }
-
- /**
- * Method setOMNamespace.
- *
- * @param omNamespace
- */
- public void setOMNamespace(OMNamespace omNamespace) {
- this.namespace = omNamespace;
- this.qName = null;
- }
-
- /**
- * Method getNamespace.
- *
- * @return Returns namespace.
- */
- public OMNamespace getNamespace() {
- return namespace;
- }
-
- public String getPrefix() {
- OMNamespace ns = getNamespace();
- if (ns == null) {
- return null;
- } else {
- String prefix = ns.getPrefix();
- return prefix.length() == 0 ? null : prefix;
- }
- }
-
public String getNamespaceURI() {
OMNamespace ns = getNamespace();
if (ns == null) {
@@ -238,6 +138,8 @@ public class OMAttributeImpl implements
public boolean equals(Object obj) {
if (! (obj instanceof OMAttribute)) return false;
OMAttribute other = (OMAttribute)obj;
+ OMNamespace namespace = getNamespace();
+ String localName = getLocalName();
//first check namespace then localName then value to improve
performance
return (namespace == null ? other.getNamespace() == null :
namespace.equals(other.getNamespace()) &&
@@ -248,19 +150,13 @@ public class OMAttributeImpl implements
}
public int hashCode() {
+ OMNamespace namespace = getNamespace();
+ String localName = getLocalName();
return localName.hashCode() ^ (value != null ? value.hashCode() : 0) ^
(namespace != null ? namespace.hashCode() : 0);
}
public OMInformationItem clone(OMCloneOptions options) {
- return new OMAttributeImpl(localName, namespace, value, factory);
- }
-
- public final String internalGetLocalName() {
- return localName;
- }
-
- public final void internalSetLocalName(String localName) {
- this.localName = localName;
+ return new OMAttributeImpl(getLocalName(), getNamespace(), value,
factory);
}
}
Modified:
webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=1610024&r1=1610023&r2=1610024&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
(original)
+++
webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
Sat Jul 12 19:16:36 2014
@@ -58,25 +58,6 @@ public class OMElementImpl extends OMNod
private static final Log log = LogFactory.getLog(OMElementImpl.class);
- /**
- * The namespace of this element. Possible values:
- * <ul>
- * <li><code>null</code> (if the element has no namespace)
- * <li>any {@link OMNamespace} instance, with the following exceptions:
- * <ul>
- * <li>an {@link OMNamespace} instance with a <code>null</code> prefix
- * <li>an {@link OMNamespace} instance with both prefix and namespace URI
set to the empty
- * string
- * </ul>
- * </ul>
- */
- private OMNamespace ns;
-
- /** Field localName */
- private String localName;
-
- private QName qName;
-
/** Field namespaces */
protected HashMap namespaces = null;
@@ -92,13 +73,13 @@ public class OMElementImpl extends OMNod
if (localName == null || localName.trim().length() == 0) {
throw new OMException("localname can not be null or empty");
}
- this.localName = localName;
+ internalSetLocalName(localName);
coreSetBuilder(builder);
coreSetState(builder == null ? COMPLETE : INCOMPLETE);
if (parent != null) {
((IContainer)parent).addChild(this, builder != null);
}
- this.ns = generateNSDecl ? handleNamespace(this, ns, false, true) : ns;
+ internalSetNamespace(generateNSDecl ? handleNamespace(this, ns, false,
true) : ns);
}
/**
@@ -114,8 +95,8 @@ public class OMElementImpl extends OMNod
if (parent != null) {
parent.addChild(this);
}
- localName = qname.getLocalPart();
- this.ns = handleNamespace(qname);
+ internalSetLocalName(qname.getLocalPart());
+ internalSetNamespace(handleNamespace(qname));
}
/**
@@ -194,8 +175,9 @@ public class OMElementImpl extends OMNod
}
public OMNamespace declareDefaultNamespace(String uri) {
- if (ns == null && uri.length() > 0
- || ns != null && ns.getPrefix().length() == 0 &&
!ns.getNamespaceURI().equals(uri)) {
+ OMNamespace elementNamespace = getNamespace();
+ if (elementNamespace == null && uri.length() > 0
+ || elementNamespace != null &&
elementNamespace.getPrefix().length() == 0 &&
!elementNamespace.getNamespaceURI().equals(uri)) {
throw new OMException("Attempt to add a namespace declaration that
conflicts with " +
"the namespace information of the element");
}
@@ -565,35 +547,6 @@ public class OMElementImpl extends OMNod
return null;
}
- /**
- * Method getLocalName.
- *
- * @return Returns local name.
- */
- public String getLocalName() {
- return localName;
- }
-
- /** Method setLocalName. */
- public void setLocalName(String localName) {
- this.localName = localName;
- this.qName = null;
- }
-
- public OMNamespace getNamespace() {
- return ns;
- }
-
- public String getPrefix() {
- OMNamespace ns = getNamespace();
- if (ns == null) {
- return null;
- } else {
- String prefix = ns.getPrefix();
- return prefix.length() == 0 ? null : prefix;
- }
- }
-
public String getNamespaceURI() {
OMNamespace ns = getNamespace();
if (ns == null) {
@@ -608,49 +561,6 @@ public class OMElementImpl extends OMNod
setNamespace(namespace, true);
}
- public final void internalSetNamespace(OMNamespace namespace) {
- this.ns = namespace;
- this.qName = null;
- }
-
- public void setNamespaceWithNoFindInCurrentScope(OMNamespace namespace) {
- this.ns = namespace;
- this.qName = null;
- }
-
- public void setNamespace(OMNamespace namespace, boolean declare) {
- this.ns = handleNamespace(this, namespace, false, declare);
- this.qName = null;
- }
-
- /**
- * Method getQName.
- *
- * @return Returns QName.
- */
- public QName getQName() {
- if (qName != null) {
- return qName;
- }
-
- if (ns != null) {
- qName = new QName(ns.getNamespaceURI(), localName, ns.getPrefix());
- } else {
- qName = new QName(localName);
- }
- return qName;
- }
-
- public boolean hasName(QName name) {
- if (name.getLocalPart().equals(getLocalName())) {
- OMNamespace ns = getNamespace();
- return ns == null && name.getNamespaceURI().length() == 0
- || ns != null &&
name.getNamespaceURI().equals(ns.getNamespaceURI());
- } else {
- return false;
- }
- }
-
public String toStringWithConsume() throws XMLStreamException {
StringWriter writer = new StringWriter();
XMLStreamWriter writer2 = StAXUtils.createXMLStreamWriter(writer);
@@ -762,13 +672,5 @@ public class OMElementImpl extends OMNod
this.setComplete(true);
}
}
-
- public final String internalGetLocalName() {
- return localName;
- }
-
- public final void internalSetLocalName(String localName) {
- this.localName = localName;
- }
}
Modified:
webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=1610024&r1=1610023&r2=1610024&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
(original)
+++
webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
Sat Jul 12 19:16:36 2014
@@ -530,14 +530,6 @@ public class OMSourcedElementImpl extend
}
}
- public String getPrefix() {
- return super.getPrefix();
- }
-
- public String getNamespaceURI() {
- return super.getNamespaceURI();
- }
-
public void setNamespace(OMNamespace namespace) {
forceExpand();
super.setNamespace(namespace);