Author: darran.lofthouse(a)jboss.com
Date: 2007-08-13 10:16:55 -0400 (Mon, 13 Aug 2007)
New Revision: 4336
Modified:
legacy/branches/jbossws-1.0.4.GA_JBWS-1786/src/main/java/org/jboss/ws/utils/DOMWriter.java
legacy/branches/jbossws-1.0.4.GA_JBWS-1786/src/test/java/org/jboss/test/ws/common/utils/DOMWriterTestCase.java
Log:
[JBWS-1786] Failed to parse source: Element loginResponse is not bound as a Failed to
parse source: Element XXXX is not bound as a global element.
Modified:
legacy/branches/jbossws-1.0.4.GA_JBWS-1786/src/main/java/org/jboss/ws/utils/DOMWriter.java
===================================================================
---
legacy/branches/jbossws-1.0.4.GA_JBWS-1786/src/main/java/org/jboss/ws/utils/DOMWriter.java 2007-08-13
13:20:25 UTC (rev 4335)
+++
legacy/branches/jbossws-1.0.4.GA_JBWS-1786/src/main/java/org/jboss/ws/utils/DOMWriter.java 2007-08-13
14:16:55 UTC (rev 4336)
@@ -102,6 +102,8 @@
private Node rootNode;
// True if we want namespace completion
private boolean completeNamespaces = true;
+ // The current default namespace
+ private String currentDefaultNamespace;
public DOMWriter(Writer w)
{
@@ -275,6 +277,7 @@
Map nsMap = new HashMap();
String elPrefix = node.getPrefix();
+ String elNamespaceURI = node.getNamespaceURI();
if (elPrefix != null)
{
String nsURI = getNamespaceURI(elPrefix, element, rootNode);
@@ -289,6 +292,9 @@
String atName = attr.getNodeName();
String atValue = normalize(attr.getNodeValue(), canonical);
+ if (atName.equals("xmlns"))
+ currentDefaultNamespace = atValue;
+
if (atPrefix != null && !atPrefix.equals("xmlns")
&& !atPrefix.equals("xml"))
{
String nsURI = getNamespaceURI(atPrefix, element, rootNode);
@@ -328,6 +334,18 @@
}
}
+ // The SAX ContentHandler will by default not add the namespace declaration
+ // <Hello xmlns='http://somens'>World</Hello>
+ if (elPrefix == null && elNamespaceURI != null)
+ {
+ String defaultNamespace = element.getAttribute("xmlns");
+ if (defaultNamespace.length() == 0 &&
!elNamespaceURI.equals(currentDefaultNamespace))
+ {
+ out.print(" xmlns='" + elNamespaceURI +
"'");
+ currentDefaultNamespace = elNamespaceURI;
+ }
+ }
+
if (hasChildNodes)
{
out.print('>');
Modified:
legacy/branches/jbossws-1.0.4.GA_JBWS-1786/src/test/java/org/jboss/test/ws/common/utils/DOMWriterTestCase.java
===================================================================
---
legacy/branches/jbossws-1.0.4.GA_JBWS-1786/src/test/java/org/jboss/test/ws/common/utils/DOMWriterTestCase.java 2007-08-13
13:20:25 UTC (rev 4335)
+++
legacy/branches/jbossws-1.0.4.GA_JBWS-1786/src/test/java/org/jboss/test/ws/common/utils/DOMWriterTestCase.java 2007-08-13
14:16:55 UTC (rev 4336)
@@ -156,6 +156,34 @@
assertEquals(expStr, wasStr);
}
+ /** The envelope defines a default namespace
+ */
+ public void testNamespaceCompletionDefault() throws Exception
+ {
+ String inStr =
+ "<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'
xmlns='http://somens'>" +
+ "<env:Body>" +
+ "<rpc>" +
+ "<param1/>" +
+ "<param2/>" +
+ "</rpc>" +
+ "</env:Body>" +
+ "</env:Envelope>";
+
+ Element env = DOMUtils.parse(inStr);
+ Element body = DOMUtils.getFirstChildElement(env);
+ Element rpc = DOMUtils.getFirstChildElement(body);
+
+ String expStr =
+ "<rpc xmlns='http://somens'>" +
+ "<param1/>" +
+ "<param2/>" +
+ "</rpc>";
+
+ String wasStr = DOMWriter.printNode(rpc, false);
+ assertEquals(expStr, wasStr);
+ }
+
/** The element does not contain the required attribute ns declaration.
*/
public void testNamespaceCompletionAttribute() throws Exception