You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2010/04/25 14:52:13 UTC
svn commit: r937790 - in
/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom:
om/impl/util/NamespaceContextImpl.java
util/namespace/AbstractNamespaceContext.java
util/namespace/ScopedNamespaceContext.java
Author: veithen
Date: Sun Apr 25 12:52:13 2010
New Revision: 937790
URL: http://svn.apache.org/viewvc?rev=937790&view=rev
Log:
Merged common code from NamespaceContextImpl and ScopedNamespaceContext into a common base class.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/AbstractNamespaceContext.java (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/NamespaceContextImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/ScopedNamespaceContext.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/NamespaceContextImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/NamespaceContextImpl.java?rev=937790&r1=937789&r2=937790&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/NamespaceContextImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/NamespaceContextImpl.java Sun Apr 25 12:52:13 2010
@@ -19,58 +19,26 @@
package org.apache.axiom.om.impl.util;
-import javax.xml.XMLConstants;
-import javax.xml.namespace.NamespaceContext;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-public class NamespaceContextImpl
- implements
- NamespaceContext {
+import org.apache.axiom.util.namespace.AbstractNamespaceContext;
+
+public class NamespaceContextImpl extends AbstractNamespaceContext {
protected Map namespaces;
public NamespaceContextImpl(Map map) {
namespaces = map;
}
- /**
- * Get the URI given a prefix
- *
- * @param prefix
- * @return uri string
- */
- public String getNamespaceURI(String prefix) {
- if (prefix == null) {
- throw new IllegalArgumentException("null prefix argument is invalid");
- } else if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
- return XMLConstants.XML_NS_URI;
- } else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
- return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
- } else if (namespaces.containsKey(prefix)) {
- return (String) namespaces.get(prefix);
- }
- return null;
+ protected String doGetNamespaceURI(String prefix) {
+ return (String) namespaces.get(prefix);
}
- /**
- * Get the prefix for a uri
- *
- * @param nsURI
- * @return prefix string
- */
- public String getPrefix(String nsURI) {
- if (nsURI == null) {
- throw new IllegalArgumentException("invalid null nsURI");
- } else if (nsURI.length() == 0) {
- throw new IllegalArgumentException("invalid empty nsURI");
- } else if (nsURI.equals(XMLConstants.XML_NS_URI)) {
- return XMLConstants.XML_NS_PREFIX;
- } else if (nsURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
- return XMLConstants.XMLNS_ATTRIBUTE;
- }
+ protected String doGetPrefix(String nsURI) {
Iterator iter = namespaces.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
@@ -85,21 +53,7 @@ public class NamespaceContextImpl
return null;
}
- /**
- * Get list of prefixes
- *
- * @param nsURI
- * @return iterator (of strings)
- */
- public Iterator getPrefixes(String nsURI) {
- if (nsURI == null) {
- throw new IllegalArgumentException("invalid null nsURI");
- } else if (nsURI.equals(XMLConstants.XML_NS_URI)) {
- return Collections.singleton(XMLConstants.XML_NS_PREFIX).iterator();
- } else if (nsURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
- return Collections.singleton(XMLConstants.XMLNS_ATTRIBUTE)
- .iterator();
- }
+ protected Iterator doGetPrefixes(String nsURI) {
Set prefixes = null;
Iterator iter = namespaces.entrySet().iterator();
while (iter.hasNext()) {
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/AbstractNamespaceContext.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/AbstractNamespaceContext.java?rev=937790&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/AbstractNamespaceContext.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/AbstractNamespaceContext.java Sun Apr 25 12:52:13 2010
@@ -0,0 +1,107 @@
+/*
+ * 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.util.namespace;
+
+import java.util.Collections;
+import java.util.Iterator;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+
+/**
+ * Partial {@link NamespaceContext} implementation that takes care of the
+ * implicit namespace bindings (for the <tt>xml</tt> and <tt>xmlns</tt>
+ * prefixes) defined in the {@link NamespaceContext} Javadoc.
+ */
+public abstract class AbstractNamespaceContext implements NamespaceContext {
+
+ public final String getNamespaceURI(String prefix) {
+ if (prefix == null) {
+ throw new IllegalArgumentException("prefix can't be null");
+ } else if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
+ return XMLConstants.XML_NS_URI;
+ } else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
+ return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
+ } else {
+ return doGetNamespaceURI(prefix);
+ }
+ }
+
+ /**
+ * Get namespace URI bound to a prefix in the current scope. The contract of
+ * this method is the same as
+ * {@link NamespaceContext#getNamespaceURI(String)}, except that the
+ * implementation is not required to handle the implicit namespace bindings.
+ *
+ * @param prefix
+ * prefix to look up
+ * @return namespace URI bound to prefix in the current scope
+ */
+ protected abstract String doGetNamespaceURI(String prefix);
+
+ public final String getPrefix(String namespaceURI) {
+ if (namespaceURI == null) {
+ throw new IllegalArgumentException("namespaceURI can't be null");
+ } else if (namespaceURI.equals(XMLConstants.XML_NS_URI)) {
+ return XMLConstants.XML_NS_PREFIX;
+ } else if (namespaceURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
+ return XMLConstants.XMLNS_ATTRIBUTE;
+ } else {
+ return doGetPrefix(namespaceURI);
+ }
+ }
+
+ /**
+ * Get prefix bound to namespace URI in the current scope. The contract of
+ * this method is the same as {@link NamespaceContext#getPrefix(String)},
+ * except that the implementation is not required to handle the implicit
+ * namespace bindings.
+ *
+ * @param namespaceURI
+ * URI of namespace to lookup
+ * @return prefix bound to namespace URI in current context
+ */
+ protected abstract String doGetPrefix(String namespaceURI);
+
+ public final Iterator getPrefixes(String namespaceURI) {
+ if (namespaceURI == null) {
+ throw new IllegalArgumentException("namespaceURI can't be null");
+ } else if (namespaceURI.equals(XMLConstants.XML_NS_URI)) {
+ return Collections.singleton(XMLConstants.XML_NS_PREFIX).iterator();
+ } else if (namespaceURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
+ return Collections.singleton(XMLConstants.XMLNS_ATTRIBUTE).iterator();
+ } else {
+ return doGetPrefixes(namespaceURI);
+ }
+ }
+
+ /**
+ * Get all prefixes bound to a namespace URI in the current scope. The
+ * contract of this method is the same as
+ * {@link NamespaceContext#getPrefixes(String)}, except that the
+ * implementation is not required to handle the implicit namespace bindings.
+ *
+ * @param namespaceURI
+ * URI of namespace to lookup
+ * @return iterator for all prefixes bound to the namespace URI in the
+ * current scope
+ */
+ protected abstract Iterator doGetPrefixes(String namespaceURI);
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/AbstractNamespaceContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/ScopedNamespaceContext.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/ScopedNamespaceContext.java?rev=937790&r1=937789&r2=937790&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/ScopedNamespaceContext.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/ScopedNamespaceContext.java Sun Apr 25 12:52:13 2010
@@ -22,7 +22,6 @@ package org.apache.axiom.util.namespace;
import java.util.Iterator;
import java.util.NoSuchElementException;
-import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;
/**
@@ -31,7 +30,7 @@ import javax.xml.namespace.NamespaceCont
* handling masked namespace bindings. Masking occurs when the same prefix is bound to a different
* namespace URI in a nested scope.
*/
-public class ScopedNamespaceContext implements NamespaceContext {
+public class ScopedNamespaceContext extends AbstractNamespaceContext {
/**
* Array containing the prefixes for the namespace bindings.
*/
@@ -109,48 +108,32 @@ public class ScopedNamespaceContext impl
bindings = scopeIndexes[--scopes];
}
- public String getNamespaceURI(String prefix) {
- if (prefix == null) {
- throw new IllegalArgumentException("prefix can't be null");
- } else if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
- return XMLConstants.XML_NS_URI;
- } else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
- return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
- } else {
- for (int i=bindings-1; i>=0; i--) {
- if (prefix.equals(prefixArray[i])) {
- return uriArray[i];
- }
+ protected String doGetNamespaceURI(String prefix) {
+ for (int i=bindings-1; i>=0; i--) {
+ if (prefix.equals(prefixArray[i])) {
+ return uriArray[i];
}
- return null;
}
+ return null;
}
- public String getPrefix(String namespaceURI) {
- if (namespaceURI == null) {
- throw new IllegalArgumentException("namespaceURI can't be null");
- } else if (namespaceURI.equals(XMLConstants.XML_NS_URI)) {
- return XMLConstants.XML_NS_PREFIX;
- } else if (namespaceURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
- return XMLConstants.XMLNS_ATTRIBUTE;
- } else {
- outer: for (int i=bindings-1; i>=0; i--) {
- if (namespaceURI.equals(uriArray[i])) {
- String prefix = prefixArray[i];
- // Now check that the prefix is not masked
- for (int j=i+1; j<bindings; j++) {
- if (prefix.equals(prefixArray[j])) {
- continue outer;
- }
+ protected String doGetPrefix(String namespaceURI) {
+ outer: for (int i=bindings-1; i>=0; i--) {
+ if (namespaceURI.equals(uriArray[i])) {
+ String prefix = prefixArray[i];
+ // Now check that the prefix is not masked
+ for (int j=i+1; j<bindings; j++) {
+ if (prefix.equals(prefixArray[j])) {
+ continue outer;
}
- return prefix;
}
+ return prefix;
}
- return null;
}
+ return null;
}
- public Iterator getPrefixes(final String namespaceURI) {
+ protected Iterator doGetPrefixes(final String namespaceURI) {
return new Iterator() {
private int binding = bindings;
private String next;