Author: thomas.diesler(a)jboss.com
Date: 2007-03-27 07:06:26 -0400 (Tue, 27 Mar 2007)
New Revision: 2691
Modified:
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/binding/QNameSerializer.java
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/binding/SerializerSupport.java
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/soap/XMLContent.java
Log:
Fix recursive expand to DOMValid->XMLValid->DOMValid transitions
Modified:
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/binding/QNameSerializer.java
===================================================================
---
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/binding/QNameSerializer.java 2007-03-27
05:05:34 UTC (rev 2690)
+++
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/binding/QNameSerializer.java 2007-03-27
11:06:26 UTC (rev 2691)
@@ -47,25 +47,26 @@
public Result serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
{
- if(log.isDebugEnabled()) log.debug("serialize: [xmlName=" + xmlName +
",xmlType=" + xmlType + "]");
+ log.debug("serialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
QName qnameValue = (QName)value;
String nsURI = qnameValue.getNamespaceURI();
NamespaceRegistry nsRegistry = serContext.getNamespaceRegistry();
- Set<String> additionalNamespaces = new HashSet<String>();
+ Set<String> nsExtras = new HashSet<String>();
+
// Remove prefix and register again
if (nsURI.length() > 0)
{
qnameValue = new QName(nsURI, qnameValue.getLocalPart());
qnameValue = nsRegistry.registerQName(qnameValue);
- if (!nsURI.equals(xmlName.getNamespaceURI()))
- additionalNamespaces.add(nsURI);
+ if (nsURI.equals(xmlName.getNamespaceURI()) == false)
+ nsExtras.add(nsURI);
}
String valueStr = SimpleTypeBindings.marshalQName(qnameValue, nsRegistry);
- String xmlFragment = wrapValueStr(xmlName, valueStr, nsRegistry,
additionalNamespaces, attributes, true);
+ String xmlFragment = wrapValueStr(xmlName, valueStr, nsRegistry, nsExtras,
attributes, true);
return stringToResult(xmlFragment);
}
Modified:
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/binding/SerializerSupport.java
===================================================================
---
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/binding/SerializerSupport.java 2007-03-27
05:05:34 UTC (rev 2690)
+++
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/binding/SerializerSupport.java 2007-03-27
11:06:26 UTC (rev 2691)
@@ -25,6 +25,8 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
import javax.xml.namespace.QName;
@@ -88,11 +90,12 @@
/** Wrap the value string in a XML fragment with the given name
*/
- protected String wrapValueStr(QName xmlName, String valueStr, NamespaceRegistry
nsRegistry, Set<String> additionalNamespaces, NamedNodeMap attributes,
- boolean normalize)
+ protected String wrapValueStr(QName xmlName, String valueStr, NamespaceRegistry
nsRegistry, Set<String> nsExtras, NamedNodeMap attributes, boolean normalize)
{
- String nsURI = xmlName.getNamespaceURI();
+ String xmlNameURI = xmlName.getNamespaceURI();
String localPart = xmlName.getLocalPart();
+
+ Map<String, String> namespaces = new HashMap<String, String>();
StringBuilder nsAttr = new StringBuilder("");
if (attributes != null)
@@ -103,45 +106,62 @@
String attrName = attr.getNodeName();
String attrValue = attr.getNodeValue();
nsAttr.append(" " + attrName + "='" + attrValue +
"'");
+
+ if (attrName.startsWith("xmlns:"))
+ {
+ String prefix = attrName.substring(6);
+ namespaces.put(attrValue, prefix);
+ }
}
}
String elName;
- if (nsURI.length() > 0)
+ if (xmlNameURI.length() > 0)
{
xmlName = nsRegistry.registerQName(xmlName);
String prefix = xmlName.getPrefix();
elName = prefix + ":" + localPart;
-
- nsAttr.append(" xmlns:" + prefix + "='" + nsURI +
"'");
+ if (namespaces.get(xmlNameURI) == null ||
!prefix.equals(namespaces.get(xmlNameURI)))
+ {
+ nsAttr.append(" xmlns:" + prefix + "='" + xmlNameURI
+ "'");
+ namespaces.put(xmlNameURI, prefix);
+ }
}
else
{
elName = localPart;
}
- if (additionalNamespaces != null)
+ if (nsExtras != null)
{
- for (String ns : additionalNamespaces)
+ for (String nsURI : nsExtras)
{
- if (ns.equals(nsURI))
- continue;
-
- String prefix = nsRegistry.getPrefix(ns);
- nsAttr.append(" xmlns:" + prefix + "='" + ns +
"'");
+ String prefix = nsRegistry.getPrefix(nsURI);
+ if (namespaces.get(nsURI) == null || !prefix.equals(namespaces.get(nsURI)))
+ {
+ nsAttr.append(" xmlns:" + prefix + "='" + nsURI +
"'");
+ namespaces.put(nsURI, prefix);
+ }
}
}
String xmlFragment;
if (valueStr == null)
{
- String xmlns = " xmlns:" + Constants.PREFIX_XSI + "='" +
Constants.NS_SCHEMA_XSI + "'";
- xmlFragment = "<" + elName + nsAttr + " " +
Constants.PREFIX_XSI + ":nil='1'" + xmlns + "/>";
+ String xsins = "";
+ if (namespaces.get(Constants.NS_SCHEMA_XSI) == null ||
!Constants.PREFIX_XSI.equals(namespaces.get(xmlNameURI)))
+ {
+ xsins = " xmlns:" + Constants.PREFIX_XSI + "='" +
Constants.NS_SCHEMA_XSI + "'";
+ namespaces.put(Constants.NS_SCHEMA_XSI, Constants.PREFIX_XSI);
+ }
+
+ xmlFragment = "<" + elName + nsAttr + " " +
Constants.PREFIX_XSI + ":nil='1'" + xsins + "/>";
}
else
{
if (normalize)
valueStr = normalize(valueStr);
+
xmlFragment = "<" + elName + nsAttr + ">" + valueStr +
"</" + elName + ">";
}
Modified:
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java
===================================================================
---
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java 2007-03-27
05:05:34 UTC (rev 2690)
+++
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPElementImpl.java 2007-03-27
11:06:26 UTC (rev 2691)
@@ -638,7 +638,7 @@
Iterator it = getChildElements();
while (it.hasNext())
{
- SOAPElement el = (SOAPElement)it.next();
+ Node el = (Node)it.next();
el.detachNode();
}
}
Modified:
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/soap/XMLContent.java
===================================================================
---
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/soap/XMLContent.java 2007-03-27
05:05:34 UTC (rev 2690)
+++
branches/jbossws-1.2.1/jbossws-core/src/java/org/jboss/ws/core/soap/XMLContent.java 2007-03-27
11:06:26 UTC (rev 2691)
@@ -37,6 +37,7 @@
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
@@ -256,7 +257,10 @@
*/
private void expandContainerChildren()
{
+ // Do nothing if the source of the XMLFragment is the container itself
Element domElement = xmlFragment.toElement();
+ if (domElement == container)
+ return;
String rootLocalName = domElement.getLocalName();
String rootPrefix = domElement.getPrefix();