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/11/13 20:10:29 UTC
svn commit: r1201478 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-api/src/main/java/org/apache/axiom/om/
axiom-api/src/main/java/org/apache/axiom/om/impl/
axiom-api/src/main/java/org/apache/axiom/om/impl/builder/
axiom-api/src/main/java...
Author: veithen
Date: Sun Nov 13 19:10:28 2011
New Revision: 1201478
URL: http://svn.apache.org/viewvc?rev=1201478&view=rev
Log:
* AXIOM-28: Don't allow declareDefaultNamespace to change the namespace of the element.
* AXIOM-376: Throw an exception if an attempt is made to use declareDefaultNamespace to add a conflicting namespace declaration (in particular in the case considered in AXIOM-28).
* Changed the code in the builder to bypass these checks internally (so that they only apply when manipulating the OM tree programmatically).
* Fixed a couple of test cases that were attempting to create conflicting namespace declarations.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMElementEx.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict1.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict2.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/impl/builder/SAXOMBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAPBuilderHelper.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-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.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/element/TestChildReDeclaringGrandParentsDefaultNSWithPrefix.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestChildReDeclaringParentsDefaultNSWithPrefix.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespace1.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestMultipleDefaultNS.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=1201478&r1=1201477&r2=1201478&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 Sun Nov 13 19:10:28 2011
@@ -120,11 +120,17 @@ public interface OMElement extends OMNod
/**
* Add a namespace declaration for the default namespace to this element.
+ * <p>
+ * Note that this method will never change the namespace of the element itself. If an attempt is
+ * made to add a namespace declaration that conflicts with the namespace information of the
+ * element, an exception is thrown.
*
* @param uri
* The default namespace to declare in the current scope. The caller is expected to
* ensure that the URI is a valid namespace name.
* @return the created namespace information item
+ * @throws OMException
+ * if an attempt is made to add a conflicting namespace declaration
*/
OMNamespace declareDefaultNamespace(String uri);
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMElementEx.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMElementEx.java?rev=1201478&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMElementEx.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMElementEx.java Sun Nov 13 19:10:28 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.om.impl;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+
+/**
+ * Interface that is used internally by Axiom and that should not be considered being part of the
+ * public API.
+ */
+public interface OMElementEx extends OMElement, OMNodeEx, OMContainerEx {
+ /**
+ * Adds a namespace declaration without doing any additional checks. This method is used
+ * internally by the builder (which can safely assume that the data received from the parser is
+ * well formed with respect to namespaces).
+ * <p>
+ * In contrast to {@link OMElement#declareNamespace(String, String)} this method can be used to
+ * declare the default namespace.
+ *
+ * @param uri
+ * the namespace to declare
+ * @param prefix
+ * the prefix to associate with the given namespace
+ * @return the created namespace information item
+ */
+ OMNamespace addNamespaceDeclaration(String uri, String prefix);
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMElementEx.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java?rev=1201478&r1=1201477&r2=1201478&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java Sun Nov 13 19:10:28 2011
@@ -29,6 +29,7 @@ import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.impl.OMContainerEx;
+import org.apache.axiom.om.impl.OMElementEx;
import org.apache.axiom.om.impl.OMNodeEx;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
@@ -126,11 +127,7 @@ public class SAXOMBuilder extends Defaul
if (nextElem == null) {
nextElem = createNextElement(null);
}
- if (prefix.length() == 0) {
- nextElem.declareDefaultNamespace(uri);
- } else {
- nextElem.declareNamespace(uri, prefix);
- }
+ ((OMElementEx)nextElem).addNamespaceDeclaration(uri, prefix);
}
public void endPrefixMapping(String arg0) throws SAXException {
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java?rev=1201478&r1=1201477&r2=1201478&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java Sun Nov 13 19:10:28 2011
@@ -30,6 +30,7 @@ import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.impl.OMContainerEx;
+import org.apache.axiom.om.impl.OMElementEx;
import org.apache.axiom.om.impl.OMNodeEx;
import org.apache.axiom.om.util.StAXUtils;
import org.apache.axiom.util.stax.XMLEventUtils;
@@ -583,35 +584,35 @@ public class StAXOMBuilder extends StAXB
* @param node
*/
protected void processNamespaceData(OMElement node) {
- // set the own namespace
- String namespaceURI = parser.getNamespaceURI();
- String prefix = parser.getPrefix();
-
-
int namespaceCount = parser.getNamespaceCount();
for (int i = 0; i < namespaceCount; i++) {
- String nsprefix = parser.getNamespacePrefix(i);
+ String prefix = parser.getNamespacePrefix(i);
//if the namespace is not defined already when we write the start tag declare it
// check whether this is the default namespace and make sure we have not declared that earlier
- String namespaceURIFromParser = parser.getNamespaceURI(i);
- if (nsprefix == null || "".equals(nsprefix)) {
- String nsuri = parser.getNamespaceURI(i);
- node.declareDefaultNamespace(nsuri == null ? "" : nsuri);
- } else {
- // NOTE_A:
- // By default most parsers don't intern the namespace.
- // Unfortunately the property to detect interning on the delegate parsers is hard to detect.
- // Woodstox has a proprietary property on the XMLInputFactory.
- // IBM has a proprietary property on the XMLStreamReader.
- // For now only force the interning if requested.
- if (isNamespaceURIInterning()) {
- namespaceURIFromParser = namespaceURIFromParser.intern();
- }
- node.declareNamespace(namespaceURIFromParser, nsprefix);
+ String namespaceURI = parser.getNamespaceURI(i);
+
+ // NOTE_A:
+ // By default most parsers don't intern the namespace.
+ // Unfortunately the property to detect interning on the delegate parsers is hard to detect.
+ // Woodstox has a proprietary property on the XMLInputFactory.
+ // IBM has a proprietary property on the XMLStreamReader.
+ // For now only force the interning if requested.
+ if (isNamespaceURIInterning()) {
+ namespaceURI = namespaceURI.intern();
}
+
+ if (prefix == null) {
+ prefix = "";
+ }
+
+ ((OMElementEx)node).addNamespaceDeclaration(namespaceURI, prefix);
}
+ // set the own namespace
+ String namespaceURI = parser.getNamespaceURI();
+ String prefix = parser.getPrefix();
+
if (namespaceURI != null && namespaceURI.length() > 0) {
OMNamespace namespace = node.findNamespaceURI(prefix == null ? "" : prefix);
if (namespace == null || !namespace.getNamespaceURI().equals(namespaceURI)) {
@@ -619,11 +620,10 @@ public class StAXOMBuilder extends StAXB
if (isNamespaceURIInterning()) {
namespaceURI = namespaceURI.intern();
}
- if (prefix == null || "".equals(prefix)) {
- namespace = node.declareDefaultNamespace(namespaceURI);
- } else {
- namespace = node.declareNamespace(namespaceURI, prefix);
+ if (prefix == null) {
+ prefix = "";
}
+ namespace = ((OMElementEx)node).addNamespaceDeclaration(namespaceURI, prefix);
}
node.setNamespaceWithNoFindInCurrentScope(namespace);
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAPBuilderHelper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAPBuilderHelper.java?rev=1201478&r1=1201477&r2=1201478&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAPBuilderHelper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAPBuilderHelper.java Sun Nov 13 19:10:28 2011
@@ -21,6 +21,7 @@ package org.apache.axiom.soap.impl.build
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.impl.OMElementEx;
import org.apache.axiom.om.impl.exception.OMBuilderException;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
@@ -43,12 +44,7 @@ public abstract class SOAPBuilderHelper
protected void processNamespaceData(OMElement node, boolean checkSOAPNamespace) {
int namespaceCount = parser.getNamespaceCount();
for (int i = 0; i < namespaceCount; i++) {
- String prefix = parser.getNamespacePrefix(i);
- if (prefix == null || prefix.length() == 0) {
- node.declareDefaultNamespace(parser.getNamespaceURI());
- } else {
- node.declareNamespace(parser.getNamespaceURI(i), prefix);
- }
+ ((OMElementEx)node).addNamespaceDeclaration(parser.getNamespaceURI(i), parser.getNamespacePrefix(i));
}
// set the own namespace
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=1201478&r1=1201477&r2=1201478&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 Sun Nov 13 19:10:28 2011
@@ -28,6 +28,7 @@ import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.OMElementEx;
import org.apache.axiom.om.impl.OMNodeEx;
import org.apache.axiom.om.impl.common.NamespaceIterator;
import org.apache.axiom.om.impl.common.OMChildElementIterator;
@@ -63,7 +64,7 @@ import java.util.HashMap;
import java.util.Iterator;
/** Implementation of the org.w3c.dom.Element and org.apache.axiom.om.Element interfaces. */
-public class ElementImpl extends ParentNode implements Element, OMElement, OMNodeEx,
+public class ElementImpl extends ParentNode implements Element, OMElementEx, OMNodeEx,
OMConstants {
private static final Log log = LogFactory.getLog(ElementImpl.class);
@@ -734,6 +735,15 @@ public class ElementImpl extends ParentN
return addAttribute(new AttrImpl(ownerNode, localName, ns, value, factory));
}
+ public OMNamespace addNamespaceDeclaration(String uri, String prefix) {
+ if (namespaces == null) {
+ this.namespaces = new HashMap(5);
+ }
+ OMNamespace ns = new OMNamespaceImpl(uri, prefix);
+ namespaces.put(prefix, ns);
+ return ns;
+ }
+
/**
* Allows overriding an existing declaration if the same prefix was used.
*
@@ -746,9 +756,7 @@ public class ElementImpl extends ParentN
if (namespace != null) {
String prefix = namespace.getPrefix();
- if ("".equals(prefix)) {
- namespace = declareDefaultNamespace(namespace.getNamespaceURI());
- } else if (prefix == null) {
+ if (prefix == null) {
prefix = OMSerializerUtil.getNextNSPrefix();
namespace = new OMNamespaceImpl(namespace.getNamespaceURI(), prefix);
}
@@ -781,6 +789,12 @@ public class ElementImpl extends ParentN
}
public OMNamespace declareDefaultNamespace(String uri) {
+ if (namespace == null && uri.length() > 0
+ || namespace != null && namespace.getPrefix().length() == 0 && !namespace.getNamespaceURI().equals(uri)) {
+ throw new OMException("Attempt to add a namespace declaration that conflicts with " +
+ "the namespace information of the element");
+ }
+
OMNamespaceImpl ns = new OMNamespaceImpl(uri, "");
if (namespaces == null) {
this.namespaces = new HashMap(5);
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=1201478&r1=1201477&r2=1201478&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 Sun Nov 13 19:10:28 2011
@@ -31,6 +31,7 @@ import org.apache.axiom.om.OMSourcedElem
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.impl.OMContainerEx;
+import org.apache.axiom.om.impl.OMElementEx;
import org.apache.axiom.om.impl.OMNodeEx;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.impl.common.NamespaceIterator;
@@ -69,7 +70,7 @@ import java.util.LinkedHashMap;
/** Class OMElementImpl */
public class OMElementImpl extends OMNodeImpl
- implements OMElement, OMConstants, OMContainerEx {
+ implements OMElementEx, OMConstants, OMContainerEx {
private static final Log log = LogFactory.getLog(OMElementImpl.class);
@@ -384,6 +385,11 @@ public class OMElementImpl extends OMNod
}
public OMNamespace declareDefaultNamespace(String uri) {
+ if (ns == null && uri.length() > 0
+ || ns != null && ns.getPrefix().length() == 0 && !ns.getNamespaceURI().equals(uri)) {
+ throw new OMException("Attempt to add a namespace declaration that conflicts with " +
+ "the namespace information of the element");
+ }
OMNamespaceImpl namespace = new OMNamespaceImpl(uri == null ? "" : uri, "");
@@ -391,10 +397,6 @@ public class OMElementImpl extends OMNod
this.namespaces = new HashMap(5);
}
namespaces.put("", namespace);
- if (ns == null || "".equals(ns.getPrefix())) {
- ns = namespace;
- this.qName = null;
- }
return namespace;
}
@@ -410,6 +412,15 @@ public class OMElementImpl extends OMNod
return null;
}
+ public OMNamespace addNamespaceDeclaration(String uri, String prefix) {
+ if (namespaces == null) {
+ this.namespaces = new HashMap(5);
+ }
+ OMNamespace ns = new OMNamespaceImpl(uri, prefix);
+ namespaces.put(prefix, ns);
+ return ns;
+ }
+
/** @return Returns namespace. */
public OMNamespace declareNamespace(OMNamespace namespace) {
if (namespaces == null) {
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=1201478&r1=1201477&r2=1201478&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java Sun Nov 13 19:10:28 2011
@@ -360,6 +360,10 @@ public class OMSourcedElementImpl extend
return super.declareNamespace(namespace);
}
+ public OMNamespace addNamespaceDeclaration(String uri, String prefix) {
+ return super.addNamespaceDeclaration(uri, prefix);
+ }
+
public void undeclarePrefix(String prefix) {
forceExpand();
super.undeclarePrefix(prefix);
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=1201478&r1=1201477&r2=1201478&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 Nov 13 19:10:28 2011
@@ -114,6 +114,8 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.element.TestChildReDeclaringParentsDefaultNSWithPrefix(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestDeclareDefaultNamespace1(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestDeclareDefaultNamespace2(metaFactory));
+ addTest(new org.apache.axiom.ts.om.element.TestDeclareDefaultNamespaceConflict1(metaFactory));
+ addTest(new org.apache.axiom.ts.om.element.TestDeclareDefaultNamespaceConflict2(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestDeclareNamespace1(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestDeclareNamespaceInvalid1(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestDeclareNamespaceInvalid2(metaFactory));
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestChildReDeclaringGrandParentsDefaultNSWithPrefix.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestChildReDeclaringGrandParentsDefaultNSWithPrefix.java?rev=1201478&r1=1201477&r2=1201478&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestChildReDeclaringGrandParentsDefaultNSWithPrefix.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestChildReDeclaringGrandParentsDefaultNSWithPrefix.java Sun Nov 13 19:10:28 2011
@@ -32,8 +32,8 @@ public class TestChildReDeclaringGrandPa
protected void runTest() throws Throwable {
OMFactory fac = metaFactory.getOMFactory();
- OMElement elem = fac.createOMElement("RequestSecurityToken", null);
- elem.declareDefaultNamespace("http://schemas.xmlsoap.org/ws/2005/02/trust");
+ OMElement elem = fac.createOMElement("RequestSecurityToken",
+ fac.createOMNamespace("http://schemas.xmlsoap.org/ws/2005/02/trust", ""));
fac.createOMElement(new QName("TokenType"), elem).setText("test");
fac.createOMElement(new QName("RequestType"), elem).setText("test1");
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestChildReDeclaringParentsDefaultNSWithPrefix.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestChildReDeclaringParentsDefaultNSWithPrefix.java?rev=1201478&r1=1201477&r2=1201478&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestChildReDeclaringParentsDefaultNSWithPrefix.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestChildReDeclaringParentsDefaultNSWithPrefix.java Sun Nov 13 19:10:28 2011
@@ -36,8 +36,8 @@ public class TestChildReDeclaringParents
protected void runTest() throws Throwable {
OMFactory fac = metaFactory.getOMFactory();
- OMElement elem = fac.createOMElement("RequestSecurityToken", null);
- elem.declareDefaultNamespace("http://schemas.xmlsoap.org/ws/2005/02/trust");
+ OMElement elem = fac.createOMElement("RequestSecurityToken",
+ fac.createOMNamespace("http://schemas.xmlsoap.org/ws/2005/02/trust", ""));
fac.createOMElement(new QName("TokenType"), elem).setText("test");
fac.createOMElement(new QName("RequestType"), elem).setText("test1");
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespace1.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespace1.java?rev=1201478&r1=1201477&r2=1201478&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespace1.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespace1.java Sun Nov 13 19:10:28 2011
@@ -40,16 +40,15 @@ public class TestDeclareDefaultNamespace
OMFactory omFac = metaFactory.getOMFactory();
- OMElement documentElement = omFac.createOMElement("RootElement", null);
- documentElement.declareDefaultNamespace("http://one.org");
+ OMElement documentElement = omFac.createOMElement("RootElement",
+ omFac.createOMNamespace("http://one.org", ""));
OMNamespace ns = omFac.createOMNamespace("http://ws.apache.org/axis2", "ns2");
OMElement childOne = omFac.createOMElement("ChildElementOne", ns, documentElement);
childOne.declareDefaultNamespace("http://two.org");
- OMElement childTwo = omFac.createOMElement("ChildElementTwo", null, childOne);
- childTwo.declareDefaultNamespace("http://one.org");
-
+ OMElement childTwo = omFac.createOMElement("ChildElementTwo",
+ omFac.createOMNamespace("http://one.org", ""), childOne);
assertEquals(2, getNumberOfOccurrences(documentElement.toStringWithConsume(),
"xmlns=\"http://one.org\""));
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict1.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict1.java?rev=1201478&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict1.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict1.java Sun Nov 13 19:10:28 2011
@@ -0,0 +1,49 @@
+/*
+ * 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.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link OMElement#declareDefaultNamespace(String)} throws an exception if an attempt is
+ * made to add a namespace declaration that would conflict with the namespace information of the
+ * element. The case considered in this test is adding a default namespace declaration with a non
+ * empty namespace URI on an element that has no namespace. This is a regression test for <a
+ * href="https://issues.apache.org/jira/browse/AXIOM-376">AXIOM-376</a>.
+ */
+public class TestDeclareDefaultNamespaceConflict1 extends AxiomTestCase {
+ public TestDeclareDefaultNamespaceConflict1(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ OMElement element = factory.createOMElement("test", null);
+ try {
+ element.declareDefaultNamespace("urn:test");
+ fail("Expected OMException");
+ } catch (OMException ex) {
+ // Expected
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict1.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict2.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict2.java?rev=1201478&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict2.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict2.java Sun Nov 13 19:10:28 2011
@@ -0,0 +1,51 @@
+/*
+ * 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.OMException;
+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 OMElement#declareDefaultNamespace(String)} throws an exception if an attempt is
+ * made to add a namespace declaration that would conflict with the namespace information of the
+ * element. The case considered in this test is adding a default namespace declaration on an
+ * unprefixed element that belongs to a different namespace. This is a regression test for <a
+ * href="https://issues.apache.org/jira/browse/AXIOM-376">AXIOM-376</a>.
+ */
+public class TestDeclareDefaultNamespaceConflict2 extends AxiomTestCase {
+ public TestDeclareDefaultNamespaceConflict2(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ OMNamespace ns = factory.createOMNamespace("urn:ns1", "");
+ OMElement element = factory.createOMElement("test", ns);
+ try {
+ element.declareDefaultNamespace("urn:ns2");
+ fail("Expected OMException");
+ } catch (OMException ex) {
+ // Expected
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict2.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestMultipleDefaultNS.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestMultipleDefaultNS.java?rev=1201478&r1=1201477&r2=1201478&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestMultipleDefaultNS.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestMultipleDefaultNS.java Sun Nov 13 19:10:28 2011
@@ -34,8 +34,8 @@ public class TestMultipleDefaultNS exten
OMNamespace defaultNS1 = omFactory.createOMNamespace("http://defaultNS1.org", null);
OMNamespace defaultNS2 = omFactory.createOMNamespace("http://defaultNS2.org", null);
- OMElement omElementOne = omFactory.createOMElement("DocumentElement", null);
- omElementOne.declareDefaultNamespace("http://defaultNS1.org");
+ OMElement omElementOne = omFactory.createOMElement("DocumentElement",
+ omFactory.createOMNamespace("http://defaultNS1.org", ""));
OMElement omElementOneChild = omFactory.createOMElement("ChildOne", null, omElementOne);