You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2011/12/18 20:18:12 UTC
svn commit: r1220518 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-api/src/main/java/org/apache/axiom/om/
axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/
axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/ axiom...
Author: veithen
Date: Sun Dec 18 19:18:12 2011
New Revision: 1220518
URL: http://svn.apache.org/viewvc?rev=1220518&view=rev
Log:
Changed the OMFactory#createOMAttribute implementations such that a prefix is automatically generated if an OMNamespace object with a null prefix is given. Otherwise, one ends up with an attribute that reports a null prefix even after adding it to an element.
Also fixed an incorrect test case that actually shows the problem, namely an OMAttribute the QName of which has a non empty namespace URI but an empty prefix (which is impossible for an attribute).
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMAttributeGeneratedPrefix.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMAttributeNullPrefixNoNamespace.java (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/attribute/TestGetQNameWithNamespace.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java?rev=1220518&r1=1220517&r2=1220518&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java Sun Dec 18 19:18:12 2011
@@ -266,6 +266,10 @@ public interface OMFactory {
OMXMLParserWrapper builder);
/**
+ * Create an attribute with the given name and value. If the provided {@link OMNamespace} object
+ * has a <code>null</code> prefix, then a prefix will be generated, except if the namespace URI
+ * is the empty string, in which case the result is the same as if a <code>null</code>
+ * {@link OMNamespace} was given.
*
* @param localName
* @param ns
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java?rev=1220518&r1=1220517&r2=1220518&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java Sun Dec 18 19:18:12 2011
@@ -50,6 +50,7 @@ import org.apache.axiom.om.impl.dom.Pare
import org.apache.axiom.om.impl.dom.ProcessingInstructionImpl;
import org.apache.axiom.om.impl.dom.TextImpl;
import org.apache.axiom.om.impl.dom.TextNodeImpl;
+import org.apache.axiom.om.impl.util.OMSerializerUtil;
import org.w3c.dom.Node;
import javax.xml.namespace.QName;
@@ -369,6 +370,14 @@ public class OMDOMFactory implements OMF
public OMAttribute createOMAttribute(String localName, OMNamespace ns,
String value) {
+ if (ns != null && ns.getPrefix() == null) {
+ String namespaceURI = ns.getNamespaceURI();
+ if (namespaceURI.length() == 0) {
+ ns = null;
+ } else {
+ ns = new OMNamespaceImpl(namespaceURI, OMSerializerUtil.getNextNSPrefix());
+ }
+ }
return new AttrImpl(this.getDocument(), localName, ns, value, this);
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java?rev=1220518&r1=1220517&r2=1220518&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java Sun Dec 18 19:18:12 2011
@@ -44,6 +44,7 @@ import org.apache.axiom.om.impl.llom.OME
import org.apache.axiom.om.impl.llom.OMProcessingInstructionImpl;
import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
import org.apache.axiom.om.impl.llom.OMTextImpl;
+import org.apache.axiom.om.impl.util.OMSerializerUtil;
import javax.xml.namespace.QName;
@@ -276,6 +277,14 @@ public class OMLinkedListImplFactory imp
public OMAttribute createOMAttribute(String localName,
OMNamespace ns,
String value) {
+ if (ns != null && ns.getPrefix() == null) {
+ String namespaceURI = ns.getNamespaceURI();
+ if (namespaceURI.length() == 0) {
+ ns = null;
+ } else {
+ ns = new OMNamespaceImpl(namespaceURI, OMSerializerUtil.getNextNSPrefix());
+ }
+ }
return new OMAttributeImpl(localName, ns, value, this);
}
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=1220518&r1=1220517&r2=1220518&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 Sun Dec 18 19:18:12 2011
@@ -230,6 +230,8 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.element.TestUndeclarePrefix(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestWriteTextTo(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestWriteTextToWithNonTextNodes(metaFactory));
+ addTest(new org.apache.axiom.ts.om.factory.TestCreateOMAttributeGeneratedPrefix(metaFactory));
+ addTest(new org.apache.axiom.ts.om.factory.TestCreateOMAttributeNullPrefixNoNamespace(metaFactory));
addTest(new org.apache.axiom.ts.om.factory.TestCreateOMAttributeWithInvalidNamespace(metaFactory));
addTest(new org.apache.axiom.ts.om.factory.TestCreateOMCommentWithoutParent(metaFactory));
addTest(new org.apache.axiom.ts.om.factory.TestCreateOMDocument(metaFactory));
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/attribute/TestGetQNameWithNamespace.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/attribute/TestGetQNameWithNamespace.java?rev=1220518&r1=1220517&r2=1220518&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/attribute/TestGetQNameWithNamespace.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/attribute/TestGetQNameWithNamespace.java Sun Dec 18 19:18:12 2011
@@ -39,11 +39,11 @@ public class TestGetQNameWithNamespace e
String localName = "attr";
String uri = "http://ns1";
OMFactory fac = metaFactory.getOMFactory();
- OMNamespace ns = fac.createOMNamespace(uri, null);
+ OMNamespace ns = fac.createOMNamespace(uri, "p");
OMAttribute attr = fac.createOMAttribute(localName, ns, "value");
QName qname = attr.getQName();
assertEquals("Wrong namespace", uri, qname.getNamespaceURI());
assertEquals("Wrong localPart", localName, qname.getLocalPart());
- assertEquals("Wrong prefix", "", qname.getPrefix());
+ assertEquals("Wrong prefix", "p", qname.getPrefix());
}
}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMAttributeGeneratedPrefix.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMAttributeGeneratedPrefix.java?rev=1220518&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMAttributeGeneratedPrefix.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMAttributeGeneratedPrefix.java Sun Dec 18 19:18:12 2011
@@ -0,0 +1,44 @@
+/*
+ * 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.factory;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link OMFactory#createOMAttribute(String, OMNamespace, String)} generates a prefix if
+ * an {@link OMNamespace} object with a null prefix and a non empty namespace URI is given.
+ */
+public class TestCreateOMAttributeGeneratedPrefix extends AxiomTestCase {
+ public TestCreateOMAttributeGeneratedPrefix(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ OMAttribute attr = factory.createOMAttribute("attr", factory.createOMNamespace("urn:ns", null), "value");
+ OMNamespace ns = attr.getNamespace();
+ assertEquals("urn:ns", ns.getNamespaceURI());
+ assertNotNull(ns.getPrefix());
+ assertTrue(ns.getPrefix().length() > 0);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMAttributeGeneratedPrefix.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMAttributeNullPrefixNoNamespace.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMAttributeNullPrefixNoNamespace.java?rev=1220518&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMAttributeNullPrefixNoNamespace.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMAttributeNullPrefixNoNamespace.java Sun Dec 18 19:18:12 2011
@@ -0,0 +1,44 @@
+/*
+ * 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.factory;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMFactory#createOMAttribute(String, OMNamespace, String)} if an
+ * {@link OMNamespace} object with a null prefix and an empty namespace URI is given. Since it is
+ * not allowed to bind a prefix to the empty namespace URI and an unprefixed attribute has no
+ * namespace, this should give the same result as specifying an empty prefix.
+ */
+public class TestCreateOMAttributeNullPrefixNoNamespace extends AxiomTestCase {
+ public TestCreateOMAttributeNullPrefixNoNamespace(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ OMNamespace ns = factory.createOMNamespace("", null);
+ OMAttribute attr = factory.createOMAttribute("attr", ns, "value");
+ assertNull(attr.getNamespace());
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMAttributeNullPrefixNoNamespace.java
------------------------------------------------------------------------------
svn:eol-style = native