Author: veithen
Date: Sun Oct 10 15:14:03 2010
New Revision: 1006304
URL: http://svn.apache.org/viewvc?rev=1006304&view=rev
Log:
WSCOMMONS-556: Avoid unnecessary overhead when parsing a qualified name. In
particular avoid the regular expression compilation caused by the usage of
String#split.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMImplementationImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMUtil.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java?rev=1006304&r1=1006303&r2=1006304&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
Sun Oct 10 15:14:03 2010
@@ -355,7 +355,7 @@ public class AttrImpl extends NodeImpl i
*/
public String getLocalName() {
return (this.namespace == null) ? this.attrName : DOMUtil
- .getNameAndPrefix(this.attrName)[1];
+ .getLocalName(this.attrName);
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMImplementationImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMImplementationImpl.java?rev=1006304&r1=1006303&r2=1006304&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMImplementationImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMImplementationImpl.java
Sun Oct 10 15:14:03 2010
@@ -41,10 +41,9 @@ public class DOMImplementationImpl imple
DocumentImpl doc = new DocumentImpl(fac);
fac.setDocument(doc);
- String[] nameAndPrefix = DOMUtil.getNameAndPrefix(qualifiedName);
-
- new ElementImpl(doc, nameAndPrefix[1],
- new NamespaceImpl(namespaceURI, nameAndPrefix[0]),
fac);
+ new ElementImpl(doc, DOMUtil.getLocalName(qualifiedName),
+ new NamespaceImpl(namespaceURI, DOMUtil
+ .getPrefix(qualifiedName)), fac);
return doc;
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMUtil.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMUtil.java?rev=1006304&r1=1006303&r2=1006304&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMUtil.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMUtil.java
Sun Oct 10 15:14:03 2010
@@ -19,14 +19,9 @@
package org.apache.axiom.om.impl.dom;
-/**
- * Utility class for the OM-DOM implementation
- */
+/** Utility class for the OM-DOM implementation */
class DOMUtil {
- private static String separator = ":";
-
-
public static boolean isQualifiedName(String value) {
// TODO check for valid characters
// throw new UnsupportedOperationException("TODO");
@@ -34,9 +29,9 @@ class DOMUtil {
}
/**
+ * @deprecated please use isQualifiedName
* @param value
* @return
- * @deprecated please use isQualifiedName
*/
public static boolean isValidChras(String value) {
// TODO check for valid characters
@@ -60,56 +55,22 @@ class DOMUtil {
}
/**
- * Substitute method for getLocalName and getPrefix
- *
- * @param qualifiedName
- * @return qualified name split in to Prefix and localName
- * stringArray[0] is the prefix
- * stringArray[1] is the localName
- */
- public static String[] getNameAndPrefix(String qualifiedName) {
- if (qualifiedName.indexOf(DOMUtil.separator) > -1) {
- if (!qualifiedName.trim().endsWith(DOMUtil.separator))
- return qualifiedName.split(DOMUtil.separator);
- else {
- String[] container = new String[2];
- container[0] = null;
- container[1] = qualifiedName;
- return container;
-
- }
- } else {
- String[] container = new String[2];
- container[0] = null;
- container[1] = qualifiedName;
- return container;
- }
- }
-
- /**
* Get the local name from a qualified name
*
* @param qualifiedName
*/
- /*public static String getLocalName(String qualifiedName) {
- if (qualifiedName.indexOf(DOMUtil.separator) > -1
- && !qualifiedName.trim().endsWith(DOMUtil.separator)) {
- return qualifiedName.split(DOMUtil.separator)[1];
- } else {
- return qualifiedName;
- }
+ public static String getLocalName(String qualifiedName) {
+ int idx = qualifiedName.indexOf(':');
+ return idx == -1 ? qualifiedName : qualifiedName.substring(idx+1);
}
- *//**
+ /**
* Get the prefix from a qualified name
*
* @param qualifiedName
- *//*
+ */
public static String getPrefix(String qualifiedName) {
- if (qualifiedName.indexOf(DOMUtil.separator) > -1) {
- return qualifiedName.split(DOMUtil.separator)[0];
- } else {
- return null;
- }
- }*/
+ int idx = qualifiedName.indexOf(':');
+ return idx == -1 ? null : qualifiedName.substring(0, idx);
+ }
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=1006304&r1=1006303&r2=1006304&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
Sun Oct 10 15:14:03 2010
@@ -167,9 +167,8 @@ public class DocumentImpl extends Parent
public Attr createAttributeNS(String namespaceURI, String qualifiedName)
throws DOMException {
- String[] nameAndPrefix = DOMUtil.getNameAndPrefix(qualifiedName);
- String localName = nameAndPrefix[1];
- String prefix = nameAndPrefix[0];
+ String localName = DOMUtil.getLocalName(qualifiedName);
+ String prefix = DOMUtil.getPrefix(qualifiedName);
if (!OMConstants.XMLNS_NS_PREFIX.equals(localName)) {
this.checkQName(prefix, localName);
@@ -203,10 +202,8 @@ public class DocumentImpl extends Parent
if (ns == null) ns = "";
- String[] nameAndPrefix = DOMUtil.getNameAndPrefix(qualifiedName);
- String localName = nameAndPrefix[1];
- String prefix = nameAndPrefix[0];
-
+ String localName = DOMUtil.getLocalName(qualifiedName);
+ String prefix = DOMUtil.getPrefix(qualifiedName);
if(prefix == null) {
prefix = "";
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1006304&r1=1006303&r2=1006304&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
Sun Oct 10 15:14:03 2010
@@ -255,7 +255,7 @@ public class ElementImpl extends ParentN
}
if (name.startsWith(OMConstants.XMLNS_NS_PREFIX)) {
- String namespacePrefix = DOMUtil.getNameAndPrefix(name)[1];
+ String namespacePrefix = DOMUtil.getLocalName(name);
if (this.findNamespaceURI(namespacePrefix) != null) {
this.removeNamespace(namespacePrefix);
}
@@ -285,7 +285,7 @@ public class ElementImpl extends ParentN
if (OMConstants.XMLNS_NS_URI.equals(namespaceURI)) {
//look in the ns list
if (this.namespaces != null) {
- this.namespaces.remove(DOMUtil.getNameAndPrefix(localName)[1]);
+ this.namespaces.remove(DOMUtil.getLocalName(localName));
}
} else if (this.attributes != null) {
@@ -431,7 +431,7 @@ public class ElementImpl extends ParentN
if (attr.getNodeName().startsWith(OMConstants.XMLNS_NS_PREFIX + ":")) {
// This is a ns declaration
this.declareNamespace(attr.getNodeValue(), DOMUtil
- .getNameAndPrefix(attr.getName())[1]);
+ .getLocalName(attr.getName()));
//Don't add this to attr list, since its a namespace
return attr;
@@ -464,7 +464,7 @@ public class ElementImpl extends ParentN
}
if (name.startsWith(OMConstants.XMLNS_NS_PREFIX + ":")) {
// This is a ns declaration
- this.declareNamespace(value, DOMUtil.getNameAndPrefix(name)[1]);
+ this.declareNamespace(value, DOMUtil.getLocalName(name));
} else if (name.equals(OMConstants.XMLNS_NS_PREFIX)) {
this.declareDefaultNamespace(value);
} else {
@@ -540,14 +540,16 @@ public class ElementImpl extends ParentN
*/
public void setAttributeNS(String namespaceURI, String qualifiedName,
String value) throws DOMException {
- String[] nameAndPrefix = DOMUtil.getNameAndPrefix(qualifiedName);
if (namespaceURI != null && !"".equals(namespaceURI)) {
if (namespaceURI.equals(OMConstants.XMLNS_NS_URI)) {
- this.declareNamespace(value, nameAndPrefix[1]);
+ this.declareNamespace(value, DOMUtil
+ .getLocalName(qualifiedName));
} else {
- AttrImpl attr = new AttrImpl(this.ownerNode, nameAndPrefix[1],
value, this.factory);
- attr.setOMNamespace(new NamespaceImpl(namespaceURI,
nameAndPrefix[0]));
+ AttrImpl attr = new AttrImpl(this.ownerNode, DOMUtil
+ .getLocalName(qualifiedName), value, this.factory);
+ attr.setOMNamespace(new NamespaceImpl(namespaceURI, DOMUtil
+ .getPrefix(qualifiedName)));
this.setAttributeNodeNS(attr);
}
@@ -555,7 +557,7 @@ public class ElementImpl extends ParentN
// When the namespace is null, the attr name given better not be
// a qualified name
// But anyway check and set it
- this.setAttribute(nameAndPrefix[1], value);
+ this.setAttribute(DOMUtil.getLocalName(qualifiedName), value);
}
}
@@ -588,20 +590,20 @@ public class ElementImpl extends ParentN
}
// Check whether there's an existing Attr with same local name and
// namespace URI
- String[] nameAndPrefix = DOMUtil.getNameAndPrefix(qualifiedName);
- Attr attributeNode = this.getAttributeNodeNS(namespaceURI,
nameAndPrefix[1]);
-// Attr attributeNode = this.getAttributeNodeNS(namespaceURI,
DOMUtil
-// .getLocalName(qualifiedName));
+ String localName = DOMUtil.getLocalName(qualifiedName);
+ Attr attributeNode = this.getAttributeNodeNS(namespaceURI,
localName);
if (attributeNode != null) {
AttrImpl tempAttr = ((AttrImpl) attributeNode);
- tempAttr.setOMNamespace(new NamespaceImpl(namespaceURI,
nameAndPrefix[0]));
+ tempAttr.setOMNamespace(new NamespaceImpl(namespaceURI, DOMUtil
+ .getPrefix(qualifiedName)));
tempAttr.setAttributeValue(value);
this.attributes.setNamedItem(tempAttr);
return tempAttr;
} else {
- NamespaceImpl ns = new NamespaceImpl(namespaceURI,
nameAndPrefix[0]);
+ NamespaceImpl ns = new NamespaceImpl(namespaceURI, DOMUtil
+ .getPrefix(qualifiedName));
AttrImpl attr = new AttrImpl((DocumentImpl) this
- .getOwnerDocument(), nameAndPrefix[1], ns, value,
this.factory);
+ .getOwnerDocument(), localName, ns, value,
this.factory);
this.attributes.setNamedItem(attr);
return attr;
}