Author: chinthaka
Date: Mon Apr 24 03:08:32 2006
New Revision: 396499
URL: http://svn.apache.org/viewcvs?rev=396499&view=rev
Log:
Fixing a small bug pointed out by Ruchith. Test case is also added to that.
Modified:
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/util/OMSerializerUtil.java
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java
Modified:
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/util/OMSerializerUtil.java
URL:
http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/util/OMSerializerUtil.java?rev=396499&r1=396498&r2=396499&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/util/OMSerializerUtil.java
(original)
+++
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/util/OMSerializerUtil.java
Mon Apr 24 03:08:32 2006
@@ -111,7 +111,7 @@
writer.setDefaultNamespace(uri);
} else {
prefix = prefix == null ? getNextNSPrefix(writer) : prefix;
- if (prefix != null && !prefix.equals(prefixFromWriter)) {
+ if (prefix != null && !prefix.equals(prefixFromWriter) &&
!checkForPrefixInTheCurrentContext(writer, uri, prefix)) {
writer.writeNamespace(prefix, uri);
writer.setPrefix(prefix, uri);
}
@@ -192,16 +192,7 @@
// In both the above cases this xml may contain more
than one prefix for the
// same URI. Check them all.
- Iterator prefixesIter =
writer.getNamespaceContext().getPrefixes(nameSpaceName);
- boolean found = false;
- while (prefixesIter.hasNext()) {
- String prefix_w = (String) prefixesIter.next();
- if (prefix_w.equals(prefix)) {
- // if found do not declare the ns
- writer.writeStartElement(nameSpaceName,
element.getLocalName());
- found = true;
- }
- }
+ boolean found =
checkForPrefixInTheCurrentContext(writer, nameSpaceName, prefix);
if (!found) {
// seems we haven't found one in the current
scope. So declare it.
@@ -209,6 +200,8 @@
nameSpaceName);
writer.writeNamespace(prefix, nameSpaceName);
writer.setPrefix(prefix, nameSpaceName);
+ }else {
+ writer.writeStartElement(nameSpaceName,
element.getLocalName());
}
}
@@ -234,6 +227,18 @@
// add the elements attributes
serializeAttributes(element, writer);
+ }
+
+ private static boolean checkForPrefixInTheCurrentContext(XMLStreamWriter
writer, String nameSpaceName, String prefix) throws XMLStreamException {
+ Iterator prefixesIter =
writer.getNamespaceContext().getPrefixes(nameSpaceName);
+ while (prefixesIter.hasNext()) {
+ String prefix_w = (String) prefixesIter.next();
+ if (prefix_w.equals(prefix)) {
+ // if found do not declare the ns
+ return true;
+ }
+ }
+ return false;
}
public static void serializeNamespaces
Modified:
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java
URL:
http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java?rev=396499&r1=396498&r2=396499&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java
Mon Apr 24 03:08:32 2006
@@ -86,25 +86,27 @@
}
-// public void testChildReDeclaringParentsDefaultNSWithPrefix() {
-// try {
-// OMFactory fac = OMAbstractFactory.getOMFactory();
-// OMElement elem = fac.createOMElement("RequestSecurityToken",
null);
-//
elem.declareDefaultNamespace("http://schemas.xmlsoap.org/ws/2005/02/trust");
-// fac.createOMElement(new QName("TokenType"),
elem).setText("test");
-// fac.createOMElement(new QName("RequestType"),
elem).setText("test1");;
-//
-// fac.createOMElement(new
QName("http://schemas.xmlsoap.org/ws/2005/02/trust","Entropy", "wst"), elem);
-// String xml = elem.toString();
-//
-// XMLStreamReader reader =
XMLInputFactory.newInstance().createXMLStreamReader(new
ByteArrayInputStream(xml.getBytes()));
-//
-// StAXOMBuilder builder = new StAXOMBuilder(reader);
-// builder.getDocumentElement().build();
-// }catch (Exception e) {
-// fail(e.getMessage());
-// }
-// }
+ public void testChildReDeclaringParentsDefaultNSWithPrefix() {
+ try {
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMElement elem = fac.createOMElement("RequestSecurityToken", null);
+
elem.declareDefaultNamespace("http://schemas.xmlsoap.org/ws/2005/02/trust");
+ fac.createOMElement(new QName("TokenType"), elem).setText("test");
+ fac.createOMElement(new QName("RequestType"),
elem).setText("test1");
+
+ fac.createOMElement(new
QName("http://schemas.xmlsoap.org/ws/2005/02/trust","Entropy", "wst"), elem);
+ String xml = elem.toString();
+
+ XMLStreamReader reader =
XMLInputFactory.newInstance().createXMLStreamReader(new
ByteArrayInputStream(xml.getBytes()));
+
+ StAXOMBuilder builder = new StAXOMBuilder(reader);
+ builder.getDocumentElement().build();
+
+ assertTrue(xml.indexOf("<wst:Entropy
xmlns:wst=\"http://schemas.xmlsoap.org/ws/2005/02/trust\" />") != -1);
+ }catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
public static void main(String[] args) {
try {