Author: veithen
Date: Wed Dec 21 15:37:42 2011
New Revision: 1221771
URL: http://svn.apache.org/viewvc?rev=1221771&view=rev
Log:
AXIOM-398: Normalize the return value of getNamespace for OMAttribute instances.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/attribute/TestGetNamespaceNormalized.java
(with props)
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-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.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-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=1221771&r1=1221770&r2=1221771&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
Wed Dec 21 15:37:42 2011
@@ -80,8 +80,12 @@ public class AttrImpl extends NodeImpl i
public AttrImpl(DocumentImpl ownerDocument, String localName,
OMNamespace ns, String value, OMFactory factory) {
super(ownerDocument, factory);
- if (ns != null && ns.getNamespaceURI().length() == 0 &&
ns.getPrefix().length() > 0) {
- throw new IllegalArgumentException("Cannot create a prefixed
attribute with an empty namespace name");
+ if (ns != null && ns.getNamespaceURI().length() == 0) {
+ if (ns.getPrefix().length() > 0) {
+ throw new IllegalArgumentException("Cannot create a prefixed
attribute with an empty namespace name");
+ } else {
+ ns = null;
+ }
}
this.attrName = localName;
this.attrValue = new TextImpl(ownerDocument, value, factory);
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?rev=1221771&r1=1221770&r2=1221771&view=diff
==============================================================================
---
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 Dec 21 15:37:42 2011
@@ -72,8 +72,12 @@ public class OMAttributeImpl implements
if (localName == null || localName.trim().length() == 0)
throw new IllegalArgumentException("Local name may not be null or
empty");
- if (ns != null && ns.getNamespaceURI().length() == 0 &&
ns.getPrefix().length() > 0) {
- throw new IllegalArgumentException("Cannot create a prefixed
attribute with an empty namespace name");
+ if (ns != null && ns.getNamespaceURI().length() == 0) {
+ if (ns.getPrefix().length() > 0) {
+ throw new IllegalArgumentException("Cannot create a prefixed
attribute with an empty namespace name");
+ } else {
+ ns = null;
+ }
}
this.localName = localName;
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=1221771&r1=1221770&r2=1221771&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
Wed Dec 21 15:37:42 2011
@@ -54,6 +54,7 @@ public class OMTestSuiteBuilder extends
addTest(new
org.apache.axiom.ts.om.attribute.TestDigestWithNamespace(metaFactory));
addTest(new
org.apache.axiom.ts.om.attribute.TestDigestWithoutNamespace(metaFactory));
addTest(new
org.apache.axiom.ts.om.attribute.TestEqualsHashCode(metaFactory));
+ addTest(new
org.apache.axiom.ts.om.attribute.TestGetNamespaceNormalized(metaFactory));
addTest(new
org.apache.axiom.ts.om.attribute.TestGetNamespaceURIWithNamespace(metaFactory));
addTest(new
org.apache.axiom.ts.om.attribute.TestGetNamespaceURIWithoutNamespace(metaFactory));
addTest(new
org.apache.axiom.ts.om.attribute.TestGetPrefixWithNamespace(metaFactory));
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/attribute/TestGetNamespaceNormalized.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/attribute/TestGetNamespaceNormalized.java?rev=1221771&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/attribute/TestGetNamespaceNormalized.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/attribute/TestGetNamespaceNormalized.java
Wed Dec 21 15:37:42 2011
@@ -0,0 +1,47 @@
+/*
+ * 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.attribute;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamedInformationItem;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link OMNamedInformationItem#getNamespace()} returns
<code>null</code> for an
+ * attribute without namespace, even if during creation an {@link OMNamespace}
object with empty
+ * prefix and namespace URI was given.
+ * <p>
+ * This is a regression test for <a
+ * href="https://issues.apache.org/jira/browse/AXIOM-398">AXIOM-398</a>.
+ */
+public class TestGetNamespaceNormalized extends AxiomTestCase {
+ public TestGetNamespaceNormalized(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ OMNamespace ns = factory.createOMNamespace("", "");
+ OMAttribute attr = factory.createOMAttribute("parent", ns, "value");
+ assertNull(attr.getNamespace());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/attribute/TestGetNamespaceNormalized.java
------------------------------------------------------------------------------
svn:eol-style = native