Author: gdaniels
Date: Wed Mar 28 18:21:34 2007
New Revision: 523523
URL: http://svn.apache.org/viewvc?view=rev&rev=523523
Log:
Resolve https://issues.apache.org/jira/browse/WSCOMMONS-140
Guard against null prefixes when creating QNames. Also introduce test
directory for axiom-impl, with the hope that eventually we will get rid of (or
at least substantially reduce) axiom-tests.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/apache/axiom/om/impl/dom/AttributeTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/test/
webservices/commons/trunk/modules/axiom/modules/axiom-impl/test/org/
webservices/commons/trunk/modules/axiom/modules/axiom-impl/test/org/apache/
webservices/commons/trunk/modules/axiom/modules/axiom-impl/test/org/apache/axiom/
webservices/commons/trunk/modules/axiom/modules/axiom-impl/test/org/apache/axiom/om/
webservices/commons/trunk/modules/axiom/modules/axiom-impl/test/org/apache/axiom/om/impl/
webservices/commons/trunk/modules/axiom/modules/axiom-impl/test/org/apache/axiom/om/impl/llom/
webservices/commons/trunk/modules/axiom/modules/axiom-impl/test/org/apache/axiom/om/impl/llom/AttributeImplTest.java
Modified:
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/AttrImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/pom.xml
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
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?view=diff&rev=523523&r1=523522&r2=523523
==============================================================================
---
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
Wed Mar 28 18:21:34 2007
@@ -61,8 +61,13 @@
if (defaultToParentNameSpace) {
//get the parent ns and use it for the child
OMNamespace namespace = element.getNamespace();
- if (namespace != null)
- return new QName(namespace.getNamespaceURI(), qname,
namespace.getPrefix());
+ if (namespace != null) {
+ // Guard against QName implementation sillyness.
+ if (namespace.getPrefix() == null)
+ return new QName(namespace.getNamespaceURI(), qname);
+ else
+ return new QName(namespace.getNamespaceURI(), qname,
namespace.getPrefix());
+ }
}
//else things without no prefix are local.
return new QName(qname);
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?view=diff&rev=523523&r1=523522&r2=523523
==============================================================================
---
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
Wed Mar 28 18:21:34 2007
@@ -226,9 +226,16 @@
* @see org.apache.axiom.om.OMAttribute#getQName()
*/
public QName getQName() {
- return (this.namespace == null) ? new QName(this.attrName) : new QName(
- this.namespace.getNamespaceURI(), this.attrName, this.namespace
- .getPrefix());
+ return (namespace == null) ?
+ new QName(this.attrName) :
+ // This next bit is because QName is kind of stupid, and
throws an
+ // IllegalArgumentException on null prefix instead of treating
it exactly
+ // as if no prefix had been passed. Grr.
+ (namespace.getPrefix() == null ?
+ new QName(namespace.getNamespaceURI(), attrName) :
+ new QName(namespace.getNamespaceURI(),
+ attrName,
+ namespace.getPrefix()));
}
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/apache/axiom/om/impl/dom/AttributeTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/apache/axiom/om/impl/dom/AttributeTest.java?view=auto&rev=523523
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/apache/axiom/om/impl/dom/AttributeTest.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/apache/axiom/om/impl/dom/AttributeTest.java
Wed Mar 28 18:21:34 2007
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ *
+ * Licensed 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 junit.framework.TestCase;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.impl.dom.factory.OMDOMFactory;
+
+import javax.xml.namespace.QName;
+
+public class AttributeTest extends TestCase {
+ /**
+ * Make sure getQName() works correctly on AttrImpl
+ * @throws Exception
+ */
+ public void testQNames() throws Exception {
+ String ATTR = "attr";
+ String NSURI = "http://ns1";
+ OMFactory fac = new OMDOMFactory();
+ OMNamespace ns = new NamespaceImpl(NSURI);
+ OMAttribute attr = fac.createOMAttribute(ATTR, ns, "value");
+ QName qname = attr.getQName();
+ assertEquals("Wrong namespace", NSURI, qname.getNamespaceURI());
+ assertEquals("Wrong localPart", ATTR, qname.getLocalPart());
+ assertEquals("Wrong prefix", "", qname.getPrefix());
+ }
+}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/pom.xml
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/pom.xml?view=diff&rev=523523&r1=523522&r2=523523
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/pom.xml
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/pom.xml Wed Mar
28 18:21:34 2007
@@ -29,6 +29,10 @@
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</dependency>
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java?view=diff&rev=523523&r1=523522&r2=523523
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
Wed Mar 28 18:21:34 2007
@@ -57,7 +57,12 @@
/** @return Returns QName. */
public QName getQName() {
if (namespace != null) {
- return new QName(namespace.getNamespaceURI(), localName,
namespace.getPrefix());
+ // Guard against QName implementation sillyness.
+ if (namespace.getPrefix() == null) {
+ return new QName(namespace.getNamespaceURI(), localName);
+ } else {
+ return new QName(namespace.getNamespaceURI(), localName,
namespace.getPrefix());
+ }
} else {
return new QName(localName);
}
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/test/org/apache/axiom/om/impl/llom/AttributeImplTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/test/org/apache/axiom/om/impl/llom/AttributeImplTest.java?view=auto&rev=523523
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-impl/test/org/apache/axiom/om/impl/llom/AttributeImplTest.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-impl/test/org/apache/axiom/om/impl/llom/AttributeImplTest.java
Wed Mar 28 18:21:34 2007
@@ -0,0 +1,40 @@
+package org.apache.axiom.om.impl.llom;
+
+import junit.framework.TestCase;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory;
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+public class AttributeImplTest extends TestCase {
+ public void testQNames() throws Exception {
+ String ATTR = "attr";
+ String NSURI = "http://ns1";
+ OMFactory fac = new OMLinkedListImplFactory();
+ OMNamespace ns = fac.createOMNamespace(NSURI, null);
+ OMAttribute attr = new OMAttributeImpl(ATTR, ns, "value", fac);
+ QName qname = attr.getQName();
+ assertEquals("Wrong namespace", NSURI, qname.getNamespaceURI());
+ assertEquals("Wrong localPart", ATTR, qname.getLocalPart());
+ assertEquals("Wrong prefix", "", qname.getPrefix());
+
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]