Author: veithen
Date: Fri Apr 1 18:56:29 2011
New Revision: 1087848
URL: http://svn.apache.org/viewvc?rev=1087848&view=rev
Log:
AXIOM-356: Fixed the algorithm used to resolve QNames.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestResolveQNameWithUnboundPrefix.java
(with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java?rev=1087848&r1=1087847&r2=1087848&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
Fri Apr 1 18:56:29 2011
@@ -376,11 +376,16 @@ public interface OMElement extends OMNod
/**
- * Turns a prefix:local qname string into a proper QName, evaluating it in
the OMElement
- * context. Unprefixed qnames resolve to the local namespace.
- *
- * @param qname prefixed qname string to resolve
- * @return Returns null for any failure to extract a qname.
+ * Resolves a QName literal in the namespace context defined by this
element and produces a
+ * corresponding {@link QName} object. The implementation uses the
algorithm defined by the XML
+ * Schema specification. In particular, the namespace for an unprefixed
QName is the default
+ * namespace (not the null namespace), i.e. QNames are resolved in the
same way as element
+ * names.
+ *
+ * @param qname
+ * the QName literal to resolve
+ * @return the {@link QName} object, or <code>null</code> if the QName
can't be resolved, i.e.
+ * if the prefix is not bound in the namespace context of this
element
*/
QName resolveQName(String qname);
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java?rev=1087848&r1=1087847&r2=1087848&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java
Fri Apr 1 18:56:29 2011
@@ -64,12 +64,9 @@ public class ElementHelper {
}
/**
- * Turns a prefix:local qname string into a proper QName, evaluating it in
the OMElement
- * context.
- *
- * @param qname qname to resolve
- * @param defaultToParentNameSpace flag that controls behaviour when there
is no namespace.
- * @return Returns null for any failure to extract a qname.
+ * @deprecated The algorithm used by this method is incorrect. See <a
+ *
href="https://issues.apache.org/jira/browse/AXIOM-356">AXIOM-356</a> for more
+ * details.
*/
public QName resolveQName(String qname, boolean defaultToParentNameSpace) {
int colon = qname.indexOf(':');
@@ -103,11 +100,9 @@ public class ElementHelper {
}
/**
- * Turns a prefix:local qname string into a proper QName, evaluating it in
the OMElement
- * context. Unprefixed qnames resolve to the local namespace.
- *
- * @param qname prefixed qname string to resolve
- * @return Returns null for any failure to extract a qname.
+ * @deprecated The algorithm used by this method is incorrect. See <a
+ *
href="https://issues.apache.org/jira/browse/AXIOM-356">AXIOM-356</a> for more
+ * details.
*/
public QName resolveQName(String qname) {
return resolveQName(qname, true);
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=1087848&r1=1087847&r2=1087848&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
Fri Apr 1 18:56:29 2011
@@ -35,7 +35,6 @@ import org.apache.axiom.om.impl.traverse
import org.apache.axiom.om.impl.traverse.OMQualifiedNameFilterIterator;
import org.apache.axiom.om.impl.util.EmptyIterator;
import org.apache.axiom.om.impl.util.OMSerializerUtil;
-import org.apache.axiom.om.util.ElementHelper;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
@@ -1159,16 +1158,16 @@ public class ElementImpl extends ParentN
}
}
- /**
- * Turn a prefix:local qname string into a proper QName, evaluating it in
the OMElement context
- * unprefixed qnames resolve to the local namespace
- *
- * @param qname prefixed qname string to resolve
- * @return Returns null for any failure to extract a qname.
- */
public QName resolveQName(String qname) {
- ElementHelper helper = new ElementHelper(this);
- return helper.resolveQName(qname);
+ int idx = qname.indexOf(':');
+ if (idx == -1) {
+ OMNamespace ns = getDefaultNamespace();
+ return ns == null ? new QName(qname) : new
QName(ns.getNamespaceURI(), qname, "");
+ } else {
+ String prefix = qname.substring(0, idx);
+ OMNamespace ns = findNamespace(null, prefix);
+ return ns == null ? null : new QName(ns.getNamespaceURI(),
qname.substring(idx+1), prefix);
+ }
}
/**
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java?rev=1087848&r1=1087847&r2=1087848&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
Fri Apr 1 18:56:29 2011
@@ -25,8 +25,6 @@ import org.apache.axiom.om.impl.dom.fact
import org.apache.axiom.ts.OMTestSuiteBuilder;
import
org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCDATAEventFromElement;
import
org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithOMSourcedElementDescendant;
-import org.apache.axiom.ts.om.element.TestResolveQNameWithDefaultNamespace;
-import org.apache.axiom.ts.om.element.TestResolveQNameWithoutNamespace;
import org.apache.axiom.ts.om.element.TestSetTextQName;
import
org.apache.axiom.ts.om.factory.TestCreateOMElementFromQNameWithDefaultNamespace;
import org.apache.axiom.ts.om.node.TestInsertSiblingAfterOnChild;
@@ -46,10 +44,6 @@ public class OMImplementationTest extend
builder.exclude(org.apache.axiom.ts.om.document.TestSerializeAndConsumeWithIncompleteDescendant.class);
builder.exclude(org.apache.axiom.ts.om.element.TestSerializeAndConsumeWithIncompleteDescendant.class);
- // TODO: resolveQName appears to have issues resolving QNames without
prefixes; needs further investigation
- builder.exclude(TestResolveQNameWithDefaultNamespace.class);
- builder.exclude(TestResolveQNameWithoutNamespace.class);
-
// TODO: Axiom should throw an exception if an attempt is made to
create a cyclic parent-child relationship
builder.exclude(TestInsertSiblingAfterOnChild.class);
builder.exclude(TestInsertSiblingBeforeOnChild.class);
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=1087848&r1=1087847&r2=1087848&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
Fri Apr 1 18:56:29 2011
@@ -48,7 +48,6 @@ import org.apache.axiom.om.impl.traverse
import org.apache.axiom.om.impl.traverse.OMChildrenQNameIterator;
import org.apache.axiom.om.impl.util.EmptyIterator;
import org.apache.axiom.om.impl.util.OMSerializerUtil;
-import org.apache.axiom.om.util.ElementHelper;
import org.apache.axiom.om.util.StAXUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -1009,16 +1008,16 @@ public class OMElementImpl extends OMNod
}
}
- /**
- * Converts a prefix:local qname string into a proper QName, evaluating it
in the OMElement
- * context. Unprefixed qnames resolve to the local namespace.
- *
- * @param qname prefixed qname string to resolve
- * @return Returns null for any failure to extract a qname.
- */
public QName resolveQName(String qname) {
- ElementHelper helper = new ElementHelper(this);
- return helper.resolveQName(qname);
+ int idx = qname.indexOf(':');
+ if (idx == -1) {
+ OMNamespace ns = getDefaultNamespace();
+ return ns == null ? new QName(qname) : new
QName(ns.getNamespaceURI(), qname, "");
+ } else {
+ String prefix = qname.substring(0, idx);
+ OMNamespace ns = findNamespace(null, prefix);
+ return ns == null ? null : new QName(ns.getNamespaceURI(),
qname.substring(idx+1), prefix);
+ }
}
public OMElement cloneOMElement() {
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java?rev=1087848&r1=1087847&r2=1087848&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java
Fri Apr 1 18:56:29 2011
@@ -24,8 +24,6 @@ import junit.framework.TestSuite;
import org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory;
import org.apache.axiom.ts.OMTestSuiteBuilder;
import
org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithOMSourcedElementDescendant;
-import org.apache.axiom.ts.om.element.TestResolveQNameWithDefaultNamespace;
-import org.apache.axiom.ts.om.element.TestResolveQNameWithoutNamespace;
import org.apache.axiom.ts.om.node.TestInsertSiblingAfterOnChild;
import org.apache.axiom.ts.om.node.TestInsertSiblingBeforeOnChild;
@@ -35,10 +33,6 @@ public class OMImplementationTest extend
// TODO: this looks like a bug
builder.exclude(org.apache.axiom.ts.om.document.TestIsCompleteAfterAddingIncompleteChild.class);
- // TODO: resolveQName appears to have issues resolving QNames without
prefixes; needs further investigation
- builder.exclude(TestResolveQNameWithDefaultNamespace.class);
- builder.exclude(TestResolveQNameWithoutNamespace.class);
-
// TODO: Axiom should throw an exception if an attempt is made to
create a cyclic parent-child relationship
builder.exclude(TestInsertSiblingAfterOnChild.class);
builder.exclude(TestInsertSiblingBeforeOnChild.class);
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java?rev=1087848&r1=1087847&r2=1087848&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
Fri Apr 1 18:56:29 2011
@@ -107,6 +107,7 @@ public class OMTestSuiteBuilder extends
addTest(new
org.apache.axiom.ts.om.element.TestResolveQNameWithDefaultNamespace(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestResolveQNameWithNonDefaultNamespace(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestResolveQNameWithoutNamespace(metaFactory));
+ addTest(new
org.apache.axiom.ts.om.element.TestResolveQNameWithUnboundPrefix(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestSerialization(metaFactory, "D", "D",
"<person
xmlns=\"urn:ns\"><name>John</name><age>34</age><weight>50</weight></person>"));
addTest(new
org.apache.axiom.ts.om.element.TestSerialization(metaFactory, "D", "U",
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestResolveQNameWithUnboundPrefix.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestResolveQNameWithUnboundPrefix.java?rev=1087848&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestResolveQNameWithUnboundPrefix.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestResolveQNameWithUnboundPrefix.java
Fri Apr 1 18:56:29 2011
@@ -0,0 +1,39 @@
+/*
+ * 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.ts.om.element;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.util.AXIOMUtil;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMElement#resolveQName(String)} if the prefix
of the QName is not
+ * bound in the namespace context of the element.
+ */
+public class TestResolveQNameWithUnboundPrefix extends AxiomTestCase {
+ public TestResolveQNameWithUnboundPrefix(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(),
"<p:root xmlns:p='urn:ns1' xmlns='urn:ns2'/>");
+ assertNull(element.resolveQName("ns:test"));
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestResolveQNameWithUnboundPrefix.java
------------------------------------------------------------------------------
svn:eol-style = native