Author: heiko.braun(a)jboss.com
Date: 2007-02-05 17:13:19 -0500 (Mon, 05 Feb 2007)
New Revision: 2284
Added:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/DOMContent.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/ObjectContent.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContent.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentAccess.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLContent.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLFragment.java
branches/hbraun/1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/XMLFragmentTestCase.java
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/SOAPFaultHelperJAXRPC.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Deserializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Serializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarDeserializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarSerializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateDeserializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateSerializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DeserializerSupport.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementDeserializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementSerializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexDeserializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexSerializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBDeserializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBSerializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/NullValueSerializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameDeserializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameSerializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArrayDeserializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArraySerializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementDeserializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementSerializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SerializerSupport.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleDeserializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleSerializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBDeserializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBSerializer.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderStax.java
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentElement.java
branches/hbraun/1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/jbossxb/SerializerDeserializerTestCase.java
branches/hbraun/1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java
Log:
Source and Result are used towards the binding layer. Cleaned up SOAPContentElement
transitions
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/SOAPFaultHelperJAXRPC.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/SOAPFaultHelperJAXRPC.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/SOAPFaultHelperJAXRPC.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -23,47 +23,31 @@
// $Id$
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.xml.namespace.QName;
-import javax.xml.rpc.JAXRPCException;
-import javax.xml.rpc.encoding.TypeMapping;
-import javax.xml.rpc.soap.SOAPFaultException;
-import javax.xml.soap.Detail;
-import javax.xml.soap.DetailEntry;
-import javax.xml.soap.MessageFactory;
-import javax.xml.soap.Name;
-import javax.xml.soap.SOAPBody;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPFault;
-import javax.xml.soap.SOAPMessage;
-
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
import org.jboss.ws.WSException;
import org.jboss.ws.core.CommonMessageContext;
-import org.jboss.ws.core.jaxrpc.binding.BindingException;
-import org.jboss.ws.core.jaxrpc.binding.DeserializerFactoryBase;
-import org.jboss.ws.core.jaxrpc.binding.DeserializerSupport;
-import org.jboss.ws.core.jaxrpc.binding.SerializationContext;
-import org.jboss.ws.core.jaxrpc.binding.SerializerFactoryBase;
-import org.jboss.ws.core.jaxrpc.binding.SerializerSupport;
-import org.jboss.ws.core.soap.MessageContextAssociation;
-import org.jboss.ws.core.soap.MessageFactoryImpl;
-import org.jboss.ws.core.soap.NameImpl;
-import org.jboss.ws.core.soap.SOAPEnvelopeImpl;
-import org.jboss.ws.core.soap.SOAPFactoryImpl;
+import org.jboss.ws.core.jaxrpc.binding.*;
+import org.jboss.ws.core.soap.*;
import org.jboss.ws.core.utils.DOMUtils;
-import org.jboss.ws.core.utils.DOMWriter;
import org.jboss.ws.metadata.umdm.FaultMetaData;
import org.jboss.ws.metadata.umdm.OperationMetaData;
import org.jboss.xb.binding.NamespaceRegistry;
import org.w3c.dom.Element;
+import javax.xml.namespace.QName;
+import javax.xml.rpc.JAXRPCException;
+import javax.xml.rpc.encoding.TypeMapping;
+import javax.xml.rpc.soap.SOAPFaultException;
+import javax.xml.soap.*;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
/**
* A Helper that translates between SOAPFaultException and SOAPFault.
*
@@ -139,7 +123,7 @@
deElement.addNamespaceDeclaration(prefix, nsURI);
}
- String xmlFragment = DOMWriter.printNode(deElement, false);
+ Source xmlFragment = new DOMSource(deElement);
DeserializerSupport des =
(DeserializerSupport)desFactory.getDeserializer();
Object userEx = des.deserialize(xmlName, xmlType, xmlFragment,
serContext);
if (userEx == null || (userEx instanceof Exception) == false)
@@ -260,10 +244,11 @@
try
{
SerializerSupport ser = (SerializerSupport)serFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, faultCause,
serContext, null);
+ Result result = ser.serialize(xmlName, xmlType, faultCause, serContext,
null);
+ XMLFragment xmlFragment = new XMLFragment(result);
SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
- Element domElement = DOMUtils.parse(xmlFragment);
+ Element domElement = DOMUtils.parse(xmlFragment.toStringFragment());
SOAPElement soapElement = soapFactory.createElement(domElement);
detail = soapFault.addDetail();
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Deserializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Deserializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Deserializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -26,6 +26,7 @@
import java.io.IOException;
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
import org.jboss.logging.Logger;
import org.jboss.ws.WSException;
@@ -45,13 +46,17 @@
{
// provide logging
private static final Logger log = Logger.getLogger(Base64Deserializer.class);
-
- public Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
+
+ public Object deserialize(QName xmlName, QName xmlType, Source xmlFragment,
SerializationContext serContext) throws BindingException {
+ return deserialize(xmlName, xmlType, sourceToString(xmlFragment), serContext);
+ }
+
+ private Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
{
log.debug("deserialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
-
+
byte[] value = null;
-
+
String valueStr = unwrapValueStr(xmlFragment);
if(XOPContext.isXOPMessage())
{
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Serializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Serializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Serializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -24,6 +24,8 @@
// $Id$
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.Result;
import org.jboss.logging.Logger;
import org.jboss.ws.core.utils.JavaUtils;
@@ -46,7 +48,7 @@
// provide logging
private static final Logger log = Logger.getLogger(Base64Serializer.class);
- public String serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
+ public Result serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
{
log.debug("serialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
@@ -68,6 +70,6 @@
String valueStr = SimpleTypeBindings.marshalBase64((byte[])value);
xmlFragment = wrapValueStr(xmlName, valueStr, nsRegistry, null, attributes,
true);
}
- return xmlFragment;
+ return stringToResult(xmlFragment);
}
}
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarDeserializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarDeserializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarDeserializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -26,6 +26,7 @@
import java.util.Calendar;
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
import org.jboss.logging.Logger;
import org.jboss.xb.binding.SimpleTypeBindings;
@@ -40,7 +41,11 @@
// provide logging
private static final Logger log = Logger.getLogger(CalendarDeserializer.class);
- public Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
+ public Object deserialize(QName xmlName, QName xmlType, Source xmlFragment,
SerializationContext serContext) throws BindingException {
+ return deserialize(xmlName, xmlType, sourceToString(xmlFragment), serContext);
+ }
+
+ private Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
{
log.debug("deserialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarSerializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarSerializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarSerializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -26,6 +26,8 @@
import java.util.Calendar;
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.Result;
import org.jboss.logging.Logger;
import org.jboss.xb.binding.NamespaceRegistry;
@@ -42,7 +44,7 @@
// provide logging
private static final Logger log = Logger.getLogger(CalendarSerializer.class);
- public String serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
+ public Result serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
{
log.debug("serialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
@@ -50,6 +52,7 @@
NamespaceRegistry nsRegistry = serContext.getNamespaceRegistry();
String xmlFragment = wrapValueStr(xmlName, valueStr, nsRegistry, null, attributes,
true);
- return xmlFragment;
+ return stringToResult(xmlFragment);
}
+
}
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateDeserializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateDeserializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateDeserializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -27,6 +27,7 @@
import java.util.Date;
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
import org.jboss.logging.Logger;
import org.jboss.xb.binding.SimpleTypeBindings;
@@ -40,7 +41,11 @@
// provide logging
private static final Logger log = Logger.getLogger(DateDeserializer.class);
- public Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
+ public Object deserialize(QName xmlName, QName xmlType, Source xmlFragment,
SerializationContext serContext) throws BindingException {
+ return deserialize(xmlName, xmlType, sourceToString(xmlFragment), serContext);
+ }
+
+ private Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
{
log.debug("deserialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateSerializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateSerializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateSerializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -28,6 +28,8 @@
import java.util.GregorianCalendar;
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.Result;
import org.jboss.logging.Logger;
import org.jboss.xb.binding.NamespaceRegistry;
@@ -46,7 +48,7 @@
// provide logging
private static final Logger log = Logger.getLogger(DateSerializer.class);
- public String serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
+ public Result serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
{
log.debug("serialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
if (value != null)
@@ -60,6 +62,6 @@
NamespaceRegistry nsRegistry = serContext.getNamespaceRegistry();
String xmlFragment = wrapValueStr(xmlName, valueStr, nsRegistry, null, attributes,
true);
- return xmlFragment;
+ return stringToResult(xmlFragment);
}
}
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DeserializerSupport.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DeserializerSupport.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DeserializerSupport.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -25,10 +25,17 @@
import javax.xml.namespace.QName;
import javax.xml.rpc.encoding.Deserializer;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.stream.StreamResult;
import org.jboss.util.NotImplementedException;
import org.jboss.ws.core.utils.XMLPredefinedEntityReferenceResolver;
+import org.jboss.ws.WSException;
+import java.io.ByteArrayOutputStream;
+
/** The base class for all Deserializers.
*
* @author Thomas.Diesler(a)jboss.org
@@ -44,8 +51,30 @@
* @param xmlFragment The XML fragment to deserialize
* @param serContext The serialization context
*/
- public abstract Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException;
+ public abstract Object deserialize(QName xmlName, QName xmlType, Source xmlFragment,
SerializationContext serContext) throws BindingException;
+ protected static String sourceToString(Source source)
+ {
+ String xmlFragment = null;
+
+ try {
+ TransformerFactory tf = TransformerFactory.newInstance();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+ StreamResult streamResult = new StreamResult(baos);
+ tf.newTransformer().transform(source, streamResult);
+ xmlFragment = new String(baos.toByteArray());
+ if (xmlFragment.startsWith("<?xml"))
+ {
+ int index = xmlFragment.indexOf(">");
+ xmlFragment = xmlFragment.substring(index + 1);
+ }
+ } catch (TransformerException e) {
+ WSException.rethrow(e);
+ }
+
+ return xmlFragment;
+ }
+
/** Unwrap the value string from the XML fragment
*
* @return The value string or null if the startTag contains a xsi:nil='true'
attribute
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementDeserializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementDeserializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementDeserializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -24,6 +24,7 @@
// $Id$
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
import org.jboss.logging.Logger;
import org.jboss.ws.core.utils.DOMUtils;
@@ -39,14 +40,19 @@
{
// provide logging
private static final Logger log = Logger.getLogger(ElementDeserializer.class);
-
+
+ public Object deserialize(QName xmlName, QName xmlType, Source xmlFragment,
SerializationContext serContext) throws BindingException {
+ return deserialize(xmlName, xmlType, sourceToString(xmlFragment), serContext);
+ }
+
/** Deserialize the given simple xmlString
*/
- public Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
+ private Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
{
log.debug("deserialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
try
{
+ // TODO: Better way for DOM to source conversion
Element domElement = DOMUtils.parse(xmlFragment);
return domElement;
}
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementSerializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementSerializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementSerializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -24,6 +24,8 @@
// $Id$
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.Result;
import org.jboss.logging.Logger;
import org.jboss.ws.core.utils.DOMWriter;
@@ -47,7 +49,7 @@
* @param serContext
* @return the string representation od the value
*/
- public String serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes)
+ public Result serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes)
throws BindingException
{
log.debug("serialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
@@ -57,6 +59,6 @@
throw new IllegalArgumentException("Value is not a Element: " +
value.getClass().getName());
String xmlFragment = DOMWriter.printNode((Element)value, false);
- return xmlFragment;
+ return stringToResult(xmlFragment);
}
}
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexDeserializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexDeserializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexDeserializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -24,6 +24,7 @@
// $Id$
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
import org.jboss.logging.Logger;
import org.jboss.xb.binding.SimpleTypeBindings;
@@ -40,7 +41,11 @@
// provide logging
private static final Logger log = Logger.getLogger(HexDeserializer.class);
- public Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
+ public Object deserialize(QName xmlName, QName xmlType, Source xmlFragment,
SerializationContext serContext) throws BindingException {
+ return deserialize(xmlName, xmlType, sourceToString(xmlFragment), serContext);
+ }
+
+ private Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
{
log.debug("deserialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexSerializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexSerializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexSerializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -24,6 +24,8 @@
// $Id$
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.Result;
import org.jboss.logging.Logger;
import org.jboss.ws.core.utils.JavaUtils;
@@ -43,7 +45,7 @@
// provide logging
private static final Logger log = Logger.getLogger(HexSerializer.class);
- public String serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
+ public Result serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
{
log.debug("serialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
@@ -52,6 +54,6 @@
NamespaceRegistry nsRegistry = serContext.getNamespaceRegistry();
String xmlFragment = wrapValueStr(xmlName, valueStr, nsRegistry, null, attributes,
true);
- return xmlFragment;
+ return stringToResult(xmlFragment);
}
}
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBDeserializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBDeserializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBDeserializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -26,6 +26,7 @@
import java.io.ByteArrayInputStream;
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
import org.apache.xerces.xs.XSModel;
import org.jboss.logging.Logger;
@@ -33,6 +34,7 @@
import org.jboss.ws.core.jaxrpc.binding.jbossxb.JBossXBConstants;
import org.jboss.ws.core.jaxrpc.binding.jbossxb.JBossXBUnmarshaller;
import org.jboss.ws.core.jaxrpc.binding.jbossxb.JBossXBUnmarshallerImpl;
+import org.jboss.ws.core.soap.XMLFragment;
import org.jboss.ws.metadata.jaxrpcmapping.JavaWsdlMapping;
/**
@@ -54,6 +56,10 @@
unmarshaller = new JBossXBUnmarshallerImpl();
}
+ public Object deserialize(QName xmlName, QName xmlType, Source source,
SerializationContext serContext) throws BindingException {
+ return deserialize(xmlName, xmlType, sourceToString(source), serContext);
+ }
+
/**
* For unmarshalling the WS layer passes to the JAXB layer
*
@@ -68,7 +74,7 @@
* The result is an object instance or null.
* In case of an unmarshalling problem a descriptive exception is thrown.
*/
- public Object deserialize(QName xmlName, QName xmlType, String val,
SerializationContext serContext) throws BindingException
+ private Object deserialize(QName xmlName, QName xmlType, String val,
SerializationContext serContext) throws BindingException
{
log.debug("deserialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBSerializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBSerializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBSerializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -26,6 +26,8 @@
import java.io.StringWriter;
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.Result;
import org.apache.xerces.xs.XSModel;
import org.jboss.logging.Logger;
@@ -71,7 +73,7 @@
* The result is a self contained (i.e. contains all namespace definitions) XML
document without the XML declaration.
* In case of an marshalling problem a descriptive exception is thrown.
*/
- public String serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
+ public Result serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
{
log.debug("serialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
@@ -101,7 +103,7 @@
String xmlFragment = strwr.toString();
log.debug("serialized: " + xmlFragment);
- return xmlFragment;
+ return stringToResult(xmlFragment);
}
catch (RuntimeException rte)
{
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/NullValueSerializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/NullValueSerializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/NullValueSerializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -24,6 +24,8 @@
// $Id$
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.Result;
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
@@ -53,13 +55,13 @@
* it is possible that the element definition does not allow
* null values. In that case an error should be generated.
*/
- public String serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
+ public Result serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
{
log.debug("serialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
NamespaceRegistry nsRegistry = serContext.getNamespaceRegistry();
nsRegistry.registerURI(Constants.NS_SCHEMA_XSI, Constants.PREFIX_XSI);
String xmlFragment = wrapValueStr(xmlName, null, nsRegistry, null, attributes,
true);
- return xmlFragment;
+ return stringToResult(xmlFragment);
}
}
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameDeserializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameDeserializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameDeserializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -26,6 +26,7 @@
import java.io.IOException;
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
import org.jboss.logging.Logger;
import org.jboss.ws.core.utils.DOMUtils;
@@ -44,7 +45,11 @@
// provide logging
private static final Logger log = Logger.getLogger(QNameDeserializer.class);
- public Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
+ public Object deserialize(QName xmlName, QName xmlType, Source xmlFragment,
SerializationContext serContext) throws BindingException {
+ return deserialize(xmlName, xmlType, sourceToString(xmlFragment), serContext);
+ }
+
+ private Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
{
log.debug("deserialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameSerializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameSerializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameSerializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -27,6 +27,8 @@
import java.util.Set;
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.Result;
import org.jboss.logging.Logger;
import org.jboss.xb.binding.NamespaceRegistry;
@@ -44,7 +46,7 @@
// provide logging
private static final Logger log = Logger.getLogger(QNameSerializer.class);
- public String serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
+ public Result serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
{
log.debug("serialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
@@ -66,6 +68,6 @@
String xmlFragment = wrapValueStr(xmlName, valueStr, nsRegistry,
additionalNamespaces, attributes, true);
- return xmlFragment;
+ return stringToResult(xmlFragment);
}
}
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArrayDeserializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArrayDeserializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArrayDeserializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -29,6 +29,8 @@
import java.util.StringTokenizer;
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
@@ -57,9 +59,13 @@
{
}
+ public Object deserialize(QName xmlName, QName xmlType, Source xmlFragment,
SerializationContext serContext) throws BindingException {
+ return deserialize(xmlName, xmlType, sourceToString(xmlFragment), serContext);
+ }
+
/**
*/
- public Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
+ private Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
{
log.debug("deserialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
try
@@ -137,7 +143,7 @@
if (it.hasNext())
{
Element childElement = (Element)it.next();
- String compXMLFragment = DOMWriter.printNode(childElement, false);
+ Source compXMLFragment = new DOMSource(childElement);
compValue = compDeserializer.deserialize(compXmlName, compXmlType,
compXMLFragment, serContext);
compValue = JavaUtils.getWrapperValueArray(compValue);
}
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArraySerializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArraySerializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArraySerializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -23,16 +23,18 @@
// $Id$
-import javax.xml.namespace.QName;
-
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
import org.jboss.ws.WSException;
import org.jboss.ws.core.jaxrpc.TypeMappingImpl;
+import org.jboss.ws.core.soap.XMLFragment;
import org.jboss.ws.core.utils.JavaUtils;
import org.jboss.ws.metadata.umdm.ParameterMetaData;
import org.w3c.dom.NamedNodeMap;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Result;
+
/**
* A Serializer that can handle SOAP encoded arrays.
*
@@ -48,7 +50,7 @@
private NullValueSerializer nullSerializer;
private boolean isArrayComponentType;
private boolean xsiNamespaceInserted;
- private StringBuilder xmlFragment;
+ private StringBuilder buffer;
public SOAPArraySerializer() throws BindingException
{
@@ -57,7 +59,7 @@
/**
*/
- public String serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
+ public Result serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
{
log.debug("serialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + ",valueType=" + value.getClass().getName() + "]");
try
@@ -103,7 +105,7 @@
if (JavaUtils.isPrimitive(value.getClass()))
value = JavaUtils.getWrapperValueArray(value);
- xmlFragment = new StringBuilder("<" + Constants.PREFIX_SOAP11_ENC +
":Array ");
+ buffer = new StringBuilder("<" + Constants.PREFIX_SOAP11_ENC +
":Array ");
if (value instanceof Object[])
{
Object[] objArr = (Object[])value;
@@ -120,7 +122,7 @@
compXmlType = serContext.getNamespaceRegistry().registerQName(compXmlType);
String arrayType = Constants.PREFIX_SOAP11_ENC + ":arrayType='"
+ compXmlType.getPrefix() + ":" + compXmlType.getLocalPart() + "[" +
arrayDim + "]'";
String compns = " xmlns:" + compXmlType.getPrefix() +
"='" + compXmlType.getNamespaceURI() + "'";
- xmlFragment.append(arrayType + compns + ">");
+ buffer.append(arrayType + compns + ">");
serializeArrayComponents(compXmlName, compXmlType, serContext, objArr);
}
@@ -128,10 +130,10 @@
{
throw new WSException("Unsupported array type: " + javaType);
}
- xmlFragment.append("</" + Constants.PREFIX_SOAP11_ENC +
":Array>");
+ buffer.append("</" + Constants.PREFIX_SOAP11_ENC +
":Array>");
- log.debug("serialized: " + xmlFragment);
- return xmlFragment.toString();
+ log.debug("serialized: " + buffer);
+ return stringToResult(buffer.toString());
}
catch (RuntimeException e)
{
@@ -163,12 +165,13 @@
{
xsiNamespaceInserted = true;
int insIndex = ("<" + Constants.PREFIX_SOAP11_ENC +
":Array ").length();
- xmlFragment.insert(insIndex, "xmlns:" + Constants.PREFIX_XSI
+ "='" + Constants.NS_SCHEMA_XSI + "' ");
+ buffer.insert(insIndex, "xmlns:" + Constants.PREFIX_XSI +
"='" + Constants.NS_SCHEMA_XSI + "' ");
}
}
- String compFragment = ser.serialize(compXmlName, compXmlType, compValue,
serContext, null);
- xmlFragment.append(compFragment);
+ Result result = ser.serialize(compXmlName, compXmlType, compValue,
serContext, null);
+ XMLFragment fragment = new XMLFragment(result);
+ buffer.append(fragment.toStringFragment());
}
}
}
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementDeserializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementDeserializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementDeserializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -25,6 +25,7 @@
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPElement;
+import javax.xml.transform.Source;
import org.jboss.logging.Logger;
import org.jboss.ws.core.soap.SOAPFactoryImpl;
@@ -42,11 +43,16 @@
// provide logging
private static final Logger log = Logger.getLogger(SOAPElementDeserializer.class);
- public Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
+ public Object deserialize(QName xmlName, QName xmlType, Source xmlFragment,
SerializationContext serContext) throws BindingException {
+ return deserialize(xmlName, xmlType, sourceToString(xmlFragment), serContext);
+ }
+
+ private Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
{
log.debug("deserialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
try
{
+ // TODO: Better way for DOM to source conversion
Element domElement = DOMUtils.parse(xmlFragment);
SOAPElement soapElement = new SOAPFactoryImpl().createElement(domElement);
return soapElement;
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementSerializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementSerializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementSerializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -25,6 +25,7 @@
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPElement;
+import javax.xml.transform.Result;
import org.jboss.logging.Logger;
import org.jboss.ws.core.utils.DOMWriter;
@@ -47,7 +48,7 @@
* @param serContext
* @return the string representation od the value
*/
- public String serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
+ public Result serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
{
log.debug("serialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
if (value == null)
@@ -56,6 +57,6 @@
throw new IllegalArgumentException("Value is not a SOAPElement: " +
value.getClass().getName());
String xmlFragment = DOMWriter.printNode((SOAPElement)value, false);
- return xmlFragment;
+ return stringToResult(xmlFragment);
}
}
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SerializerSupport.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SerializerSupport.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SerializerSupport.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -24,12 +24,23 @@
// $Id$
import java.util.Set;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import javax.xml.namespace.QName;
import javax.xml.rpc.encoding.Serializer;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.Result;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.stream.StreamResult;
import org.jboss.util.NotImplementedException;
import org.jboss.ws.Constants;
+import org.jboss.ws.WSException;
+import org.jboss.ws.core.utils.DOMUtils;
import org.jboss.xb.binding.NamespaceRegistry;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -52,8 +63,19 @@
* @param attributes TODO
* @param attributes The attributes on this element
*/
- public abstract String serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException;
+ public abstract Result serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException;
+ protected Result stringToResult(String xmlFragment) {
+ Result result = null;
+ try {
+ result = new DOMResult( DOMUtils.parse(xmlFragment));
+ } catch (IOException e) {
+ WSException.rethrow(e);
+ }
+
+ return result;
+ }
+
/** 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)
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleDeserializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleDeserializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleDeserializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -24,6 +24,7 @@
// $Id$
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
import org.jboss.logging.Logger;
import org.jboss.xb.binding.SimpleTypeBindings;
@@ -39,7 +40,11 @@
// provide logging
private static final Logger log = Logger.getLogger(SimpleDeserializer.class);
- public Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
+ public Object deserialize(QName xmlName, QName xmlType, Source xmlFragment,
SerializationContext serContext) throws BindingException {
+ return deserialize(xmlName, xmlType, sourceToString(xmlFragment), serContext);
+ }
+
+ private Object deserialize(QName xmlName, QName xmlType, String xmlFragment,
SerializationContext serContext) throws BindingException
{
log.debug("deserialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleSerializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleSerializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleSerializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -24,6 +24,8 @@
// $Id$
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.Result;
import org.jboss.logging.Logger;
import org.jboss.util.NotImplementedException;
@@ -48,7 +50,7 @@
* @param serContext
* @return the string representation od the value
*/
- public String serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
+ public Result serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
{
log.debug("serialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
@@ -66,6 +68,6 @@
}
String xmlFragment = wrapValueStr(xmlName, valueStr, nsRegistry, null, attributes,
true);
- return xmlFragment;
+ return stringToResult(xmlFragment);
}
}
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBDeserializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBDeserializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBDeserializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -23,23 +23,21 @@
// $Id$
-import java.io.ByteArrayInputStream;
+import org.jboss.logging.Logger;
+import org.jboss.ws.core.jaxrpc.TypeMappingImpl;
+import org.jboss.ws.core.jaxrpc.binding.BindingException;
+import org.jboss.ws.core.jaxrpc.binding.ComplexTypeDeserializer;
+import org.jboss.ws.core.jaxrpc.binding.SerializationContext;
+import org.jboss.ws.extensions.xop.jaxws.AttachmentUnmarshallerImpl;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.namespace.QName;
-import javax.xml.transform.stream.StreamSource;
+import javax.xml.transform.Source;
import javax.xml.ws.WebServiceException;
-import org.jboss.logging.Logger;
-import org.jboss.ws.core.jaxrpc.TypeMappingImpl;
-import org.jboss.ws.core.jaxrpc.binding.BindingException;
-import org.jboss.ws.core.jaxrpc.binding.ComplexTypeDeserializer;
-import org.jboss.ws.core.jaxrpc.binding.SerializationContext;
-import org.jboss.ws.extensions.xop.jaxws.AttachmentUnmarshallerImpl;
-
/**
* A Deserializer that can handle complex types by delegating to JAXB.
*
@@ -55,8 +53,7 @@
{
}
- @Override
- public Object deserialize(QName xmlName, QName xmlType, String val,
SerializationContext serContext)
+ public Object deserialize(QName xmlName, QName xmlType, Source xmlFragment,
SerializationContext serContext) throws BindingException
{
log.debug("deserialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
@@ -73,9 +70,8 @@
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setAttachmentUnmarshaller( new AttachmentUnmarshallerImpl());
-
- ByteArrayInputStream ins = new
ByteArrayInputStream(val.getBytes("UTF-8"));
- JAXBElement jbe = unmarshaller.unmarshal(new StreamSource(ins), javaType);
+
+ JAXBElement jbe = unmarshaller.unmarshal(xmlFragment, javaType);
value = jbe.getValue();
log.debug("deserialized: " + (value != null ?
value.getClass().getName() : null));
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBSerializer.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBSerializer.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBSerializer.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -31,6 +31,9 @@
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;
import javax.xml.ws.WebServiceException;
+import javax.xml.transform.Source;
+import javax.xml.transform.Result;
+import javax.xml.transform.dom.DOMResult;
import org.jboss.logging.Logger;
import org.jboss.ws.core.jaxrpc.TypeMappingImpl;
@@ -57,11 +60,11 @@
}
@Override
- public String serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
+ public Result serialize(QName xmlName, QName xmlType, Object value,
SerializationContext serContext, NamedNodeMap attributes) throws BindingException
{
log.debug("serialize: [xmlName=" + xmlName + ",xmlType=" +
xmlType + "]");
- String xmlFragment = null;
+ DOMResult result = null;
try
{
// It needs to be a valid JAXB type
@@ -76,17 +79,17 @@
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
marshaller.setAttachmentMarshaller(new AttachmentMarshallerImpl());
- StringWriter strwr = new StringWriter();
- marshaller.marshal(new JAXBElement(xmlName, javaType, value), strwr);
- xmlFragment = strwr.toString();
+ result = new DOMResult();
+ marshaller.marshal(new JAXBElement(xmlName, javaType, value), result);
- log.debug("serialized: " + xmlFragment);
+ log.debug("serialized: " + result);
}
catch (Exception ex)
{
handleMarshallException(ex);
}
- return xmlFragment;
+
+ return result;
}
// 4.21 Conformance (Marshalling failure): If an error occurs when using the supplied
JAXBContext to marshall
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -14,42 +14,31 @@
*/
package org.jboss.ws.core.jaxws;
-import java.io.IOException;
-import java.util.Iterator;
-
-import javax.xml.namespace.QName;
-import javax.xml.rpc.encoding.TypeMapping;
-import javax.xml.soap.Detail;
-import javax.xml.soap.DetailEntry;
-import javax.xml.soap.MessageFactory;
-import javax.xml.soap.Name;
-import javax.xml.soap.SOAPBody;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPFault;
-import javax.xml.soap.SOAPMessage;
-import javax.xml.ws.WebServiceException;
-import javax.xml.ws.soap.SOAPFaultException;
-
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
import org.jboss.ws.core.CommonMessageContext;
import org.jboss.ws.core.jaxrpc.SOAPFaultHelperJAXRPC;
-import org.jboss.ws.core.jaxrpc.binding.BindingException;
-import org.jboss.ws.core.jaxrpc.binding.DeserializerFactoryBase;
-import org.jboss.ws.core.jaxrpc.binding.DeserializerSupport;
-import org.jboss.ws.core.jaxrpc.binding.SerializationContext;
-import org.jboss.ws.core.jaxrpc.binding.SerializerFactoryBase;
-import org.jboss.ws.core.jaxrpc.binding.SerializerSupport;
+import org.jboss.ws.core.jaxrpc.binding.*;
import org.jboss.ws.core.soap.MessageContextAssociation;
import org.jboss.ws.core.soap.NameImpl;
import org.jboss.ws.core.soap.SOAPFactoryImpl;
+import org.jboss.ws.core.soap.XMLFragment;
import org.jboss.ws.core.utils.DOMUtils;
-import org.jboss.ws.core.utils.DOMWriter;
import org.jboss.ws.metadata.umdm.FaultMetaData;
import org.jboss.ws.metadata.umdm.OperationMetaData;
import org.w3c.dom.Element;
+import javax.xml.namespace.QName;
+import javax.xml.rpc.encoding.TypeMapping;
+import javax.xml.soap.*;
+import javax.xml.transform.Source;
+import javax.xml.transform.Result;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.soap.SOAPFaultException;
+import java.io.IOException;
+import java.util.Iterator;
+
/**
* Helper methods to translate between SOAPFault and SOAPFaultException
* as well as between Exception and SOAPMessage containing a fault.
@@ -118,9 +107,9 @@
Class[] types =
opMetaData.getEndpointMetaData().getRegisteredTypes().toArray(new Class[0]);
serContext.setProperty(SerializationContext.CONTEXT_TYPES, types);
- String xmlFragment = DOMWriter.printNode(deElement, false);
+ Source source = new DOMSource(deElement);
DeserializerSupport des =
(DeserializerSupport)desFactory.getDeserializer();
- Object faultBean = des.deserialize(xmlName, xmlType, xmlFragment,
serContext);
+ Object faultBean = des.deserialize(xmlName, xmlType, source,
serContext);
Exception serviceEx = faultMetaData.toServiceException(faultBean,
soapFault.getFaultString());
faultEx.initCause(serviceEx);
@@ -315,10 +304,11 @@
try
{
SerializerSupport ser = serFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, faultObject, serContext,
null);
+ Result result = ser.serialize(xmlName, xmlType, faultObject, serContext, null);
+ XMLFragment fragment = new XMLFragment(result);
SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
- Element domElement = DOMUtils.parse(xmlFragment);
+ Element domElement = DOMUtils.parse(fragment.toStringFragment());
return soapFactory.createElement(domElement);
}
catch (BindingException e)
Added:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/DOMContent.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/DOMContent.java
(rev 0)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/DOMContent.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.core.soap;
+
+import org.jboss.logging.Logger;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+
+/**
+ * @author Heiko.Braun(a)jboss.org
+ * @version $Id:$
+ * @since 05.02.2007
+ */
+public class DOMContent extends SOAPContent {
+
+ private static Logger log = Logger.getLogger(ObjectContent.class);
+
+ private Source payload;
+
+ protected DOMContent(SOAPContentElement container) {
+ super(container);
+ }
+
+ State getState() {
+ return State.DOM_VALID;
+ }
+
+ SOAPContent transitionTo(State nextState) {
+
+ SOAPContent next = null;
+
+ if(State.XML_VALID == nextState)
+ {
+ log.debug("getXMLFragment from DOM");
+ DOMSource domSource = new DOMSource(container);
+ XMLFragment fragment = new XMLFragment(domSource);
+ log.debug("xmlFragment: " + fragment);
+
+ SOAPContent xmlValid = new XMLContent(container);
+ xmlValid.setXMLFragment(fragment);
+ next = xmlValid;
+ }
+ else if(State.OBJECT_VALID == nextState)
+ {
+ // transition to xml valid first
+ XMLFragment fragment = new XMLFragment(new DOMSource(container));
+ XMLContent tmpState = new XMLContent(container);
+ tmpState.setXMLFragment(fragment);
+
+ // and from XML valid to Object valid
+ next = tmpState.transitionTo(State.OBJECT_VALID);
+
+ }
+ else if(State.DOM_VALID == nextState)
+ {
+ next = this;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Illegal state requested: " +
nextState);
+ }
+
+ return next;
+ }
+
+ public Source getPayload() {
+ return new DOMSource(container);
+ }
+
+ public void setPayload(Source source) {
+ this.payload = source;
+ }
+
+ public XMLFragment getXMLFragment() {
+ throw new IllegalStateException("XMLFragment not available");
+ }
+
+ public void setXMLFragment(XMLFragment xmlFragment) {
+ throw new IllegalStateException("XMLFragment not available");
+ }
+
+ public Object getObjectValue() {
+ throw new IllegalStateException("Object value not available");
+ }
+
+ public void setObjectValue(Object objValue) {
+ throw new IllegalStateException("Object value not available");
+ }
+}
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -22,27 +22,19 @@
package org.jboss.ws.core.soap;
//$Id$
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Iterator;
-
-import javax.xml.namespace.QName;
-import javax.xml.soap.Detail;
-import javax.xml.soap.Name;
-import javax.xml.soap.SOAPBody;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPEnvelope;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPHeader;
-import javax.xml.soap.SOAPMessage;
-
import org.jboss.logging.Logger;
import org.jboss.ws.WSException;
import org.jboss.ws.core.jaxrpc.Style;
import org.jboss.ws.core.utils.DOMUtils;
-import org.jboss.ws.core.utils.DOMWriter;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.*;
+import javax.xml.transform.dom.DOMSource;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
/**
* A SOAPEnvelope builder for JAXRPC based on DOM
*
@@ -108,7 +100,7 @@
{
Element srcElement = (Element)it.next();
//registerNamespacesLocally(srcElement);
- String xmlFragment = DOMWriter.printNode(srcElement, false);
+ XMLFragment xmlFragment = new XMLFragment( new DOMSource(srcElement) );
Name name = new NameImpl(srcElement.getLocalName(), srcElement.getPrefix(),
srcElement.getNamespaceURI());
SOAPContentElement destElement = new SOAPHeaderElementImpl(name);
@@ -202,7 +194,7 @@
DOMUtils.copyAttributes(destElement, srcElement);
- String xmlFragment = DOMWriter.printNode(srcElement, false);
+ XMLFragment xmlFragment = new XMLFragment( new DOMSource(srcElement)
);
destElement.setXMLFragment(xmlFragment);
}
}
@@ -215,7 +207,7 @@
DOMUtils.copyAttributes(destElement, srcElement);
- String xmlFragment = DOMWriter.printNode(srcElement, false);
+ XMLFragment xmlFragment = new XMLFragment( new DOMSource(srcElement) );
destElement.setXMLFragment(xmlFragment);
}
else if (style == null)
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -85,7 +85,7 @@
while (it.hasNext())
{
Element srcElement = (Element)it.next();
- String xmlFragment = DOMWriter.printNode(srcElement, false);
+ XMLFragment xmlFragment = new XMLFragment( new DOMSource(srcElement) );
Name name = new NameImpl(srcElement.getLocalName(), srcElement.getPrefix(),
srcElement.getNamespaceURI());
SOAPContentElement destElement = new SOAPHeaderElementImpl(name);
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderStax.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderStax.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderStax.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.io.ByteArrayInputStream;
import javax.xml.namespace.QName;
import javax.xml.soap.Name;
@@ -37,6 +38,7 @@
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Element;
@@ -216,25 +218,30 @@
{
SOAPHeader soapHeader = soapEnv.getHeader();
SOAPContentElement lastHeaderElement =
(SOAPContentElement)soapHeader.getChildNodes().item(soapHeader.getChildNodes().getLength()
- 1);
-
- lastHeaderElement.setXMLFragment(fragmentBuffer.toString());
+ lastHeaderElement.setXMLFragment(bufferToFragment(fragmentBuffer));
}
else if (Part.BODY == currentPart)
{
SOAPBody soapBody = soapEnv.getBody();
SOAPContentElement lastBodyElement =
(SOAPContentElement)soapBody.getChildNodes().item(soapBody.getChildNodes().getLength() -
1);
- lastBodyElement.setXMLFragment(fragmentBuffer.toString());
+ lastBodyElement.setXMLFragment(bufferToFragment(fragmentBuffer));
}
else if (Part.FAULT == currentPart)
{
SOAPBody soapBody = soapEnv.getBody();
SOAPContentElement faultElement = (SOAPContentElement)soapBody.getFault();
- faultElement.setXMLFragment(fragmentBuffer.toString());
+ faultElement.setXMLFragment(bufferToFragment(fragmentBuffer));
}
resetFragmentBuffer();
}
+ // TODO: this is rubbish. Use Source internally instead...
+ private XMLFragment bufferToFragment(StringBuffer fragmentBuffer) {
+ StreamSource source = new StreamSource(new
ByteArrayInputStream(fragmentBuffer.toString().getBytes()));
+ return new XMLFragment(source);
+ }
+
private void processStartElement() throws SOAPException
{
Added:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/ObjectContent.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/ObjectContent.java
(rev 0)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/ObjectContent.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -0,0 +1,192 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.core.soap;
+
+import org.jboss.ws.core.CommonMessageContext;
+import org.jboss.ws.core.utils.JavaUtils;
+import org.jboss.ws.core.jaxrpc.binding.*;
+import org.jboss.ws.core.jaxrpc.TypeMappingImpl;
+import org.jboss.ws.WSException;
+import org.jboss.ws.metadata.umdm.ParameterMetaData;
+import org.jboss.logging.Logger;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Result;
+import javax.xml.namespace.QName;
+import java.lang.reflect.Method;
+
+/**
+ * @author Heiko.Braun(a)jboss.org
+ * @version $Id:$
+ * @since 05.02.2007
+ */
+public class ObjectContent extends SOAPContent {
+
+ private static Logger log = Logger.getLogger(ObjectContent.class);
+
+ // The java object content of this element.
+ private Object objectValue;
+
+ protected ObjectContent(SOAPContentElement container) {
+ super(container);
+ }
+
+ State getState() {
+ return State.OBJECT_VALID;
+ }
+
+ SOAPContent transitionTo(State nextState) {
+
+ SOAPContent next = null;
+
+ if(State.XML_VALID == nextState)
+ {
+ XMLFragment fragment = marshallObjectContents();
+ XMLContent xmlValid = new XMLContent(container);
+ xmlValid.setXMLFragment(fragment);
+ next = xmlValid;
+ }
+ else if(State.OBJECT_VALID == nextState)
+ {
+ next = this;
+ }
+ else if(State.DOM_VALID == nextState)
+ {
+ // first transition to XML valid
+ XMLFragment fragment = marshallObjectContents();
+ XMLContent tmp = new XMLContent(container);
+ tmp.setXMLFragment(fragment);
+
+ // finally from XML valid to DOM valid
+ next = tmp.transitionTo(State.DOM_VALID);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Illegal state requested: " +
nextState);
+ }
+
+ return next;
+ }
+
+ public Source getPayload() {
+ throw new IllegalStateException("Payload not available");
+ }
+
+ public void setPayload(Source source) {
+ throw new IllegalStateException("Payload not available");
+ }
+
+ public XMLFragment getXMLFragment() {
+
+ throw new IllegalStateException("XMLFragment not available");
+ }
+
+ public void setXMLFragment(XMLFragment xmlFragment) {
+ throw new IllegalStateException("XMLFragment not available");
+ }
+
+ public Object getObjectValue() {
+ return objectValue;
+ }
+
+ public void setObjectValue(Object objValue) {
+ this.objectValue = objValue;
+ }
+
+ private XMLFragment marshallObjectContents()
+ {
+ QName xmlType = container.getXmlType();
+ Class javaType = container.getJavaType();
+ QName xmlName = container.getElementQName();
+
+ log.debug("getXMLFragment from Object [xmlType=" + xmlType +
",javaType=" + javaType + "]");
+
+ CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
+ if (msgContext == null)
+ throw new WSException("MessageContext not available");
+
+ SerializationContext serContext = msgContext.getSerializationContext();
+ serContext.setProperty(ParameterMetaData.class.getName(),
container.getParamMetaData());
+
+ TypeMappingImpl typeMapping = serContext.getTypeMapping();
+ XMLFragment xmlFragment = null;
+ try
+ {
+ SerializerSupport ser;
+ if (objectValue != null)
+ {
+ SerializerFactoryBase serializerFactory = getSerializerFactory(typeMapping,
javaType, xmlType);
+ ser = (SerializerSupport)serializerFactory.getSerializer();
+ }
+ else
+ {
+ ser = new NullValueSerializer();
+ }
+
+ Result result = ser.serialize(xmlName, xmlType, getObjectValue(), serContext,
null);
+ xmlFragment = new XMLFragment(result);
+ log.debug("xmlFragment: " + xmlFragment);
+ }
+ catch (BindingException e)
+ {
+ throw new WSException(e);
+ }
+
+ return xmlFragment;
+ }
+
+ /**
+ * Get the serializer factory for a given javaType and xmlType
+ */
+ private SerializerFactoryBase getSerializerFactory(TypeMappingImpl typeMapping, Class
javaType, QName xmlType)
+ {
+ SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(javaType, xmlType);
+
+ // The type mapping might contain a mapping for the array wrapper bean
+ if (serializerFactory == null && javaType.isArray())
+ {
+ Class arrayWrapperType = typeMapping.getJavaType(xmlType);
+ if (arrayWrapperType != null)
+ {
+ try
+ {
+ Method toArrayMethod = arrayWrapperType.getMethod("toArray", new
Class[] {});
+ Class returnType = toArrayMethod.getReturnType();
+ if (JavaUtils.isAssignableFrom(javaType, returnType))
+ {
+ serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(arrayWrapperType, xmlType);
+ }
+ }
+ catch (NoSuchMethodException e)
+ {
+ // ignore
+ }
+ }
+ }
+
+ if (serializerFactory == null)
+ throw new WSException("Cannot obtain serializer factory for:
[xmlType=" + xmlType + ",javaType=" + javaType + "]");
+
+ return serializerFactory;
+ }
+
+}
Added:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContent.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContent.java
(rev 0)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContent.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.core.soap;
+
+/**
+ * @author Heiko.Braun(a)jboss.org
+ * @version $Id:$
+ * @since 05.02.2007
+ */
+public abstract class SOAPContent implements SOAPContentAccess {
+
+ public enum State {OBJECT_VALID, XML_VALID, DOM_VALID}
+
+ abstract SOAPContent transitionTo(State nextState);
+
+ abstract State getState();
+
+ protected SOAPContentElement container;
+
+ protected SOAPContent(SOAPContentElement container) {
+ this.container = container;
+ }
+
+}
Added:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentAccess.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentAccess.java
(rev 0)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentAccess.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -0,0 +1,23 @@
+package org.jboss.ws.core.soap;
+
+import javax.xml.transform.Source;
+
+/**
+ * @author Heiko.Braun(a)jboss.org
+ * @version $Id:$
+ * @since 05.02.2007
+ */
+public interface SOAPContentAccess {
+
+ Source getPayload();
+
+ void setPayload(Source source);
+
+ XMLFragment getXMLFragment();
+
+ void setXMLFragment(XMLFragment xmlFragment);
+
+ Object getObjectValue();
+
+ void setObjectValue(Object objValue);
+}
Modified:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentElement.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentElement.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentElement.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -23,112 +23,79 @@
// $Id$
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Writer;
-import java.lang.reflect.Array;
-import java.lang.reflect.Method;
-import java.util.Iterator;
-import java.util.List;
+import org.jboss.logging.Logger;
+import org.jboss.ws.core.CommonMessageContext;
+import org.jboss.ws.core.utils.DOMWriter;
+import org.jboss.ws.extensions.xop.XOPContext;
+import org.jboss.ws.metadata.umdm.ParameterMetaData;
+import org.w3c.dom.*;
-import javax.activation.DataHandler;
-import javax.activation.DataSource;
import javax.xml.namespace.QName;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.transform.Source;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Iterator;
-import org.jboss.logging.Logger;
-import org.jboss.ws.Constants;
-import org.jboss.ws.WSException;
-import org.jboss.ws.core.CommonMessageContext;
-import org.jboss.ws.core.jaxrpc.TypeMappingImpl;
-import org.jboss.ws.core.jaxrpc.binding.BindingException;
-import org.jboss.ws.core.jaxrpc.binding.DeserializerFactoryBase;
-import org.jboss.ws.core.jaxrpc.binding.DeserializerSupport;
-import org.jboss.ws.core.jaxrpc.binding.NullValueSerializer;
-import org.jboss.ws.core.jaxrpc.binding.SerializationContext;
-import org.jboss.ws.core.jaxrpc.binding.SerializerFactoryBase;
-import org.jboss.ws.core.jaxrpc.binding.SerializerSupport;
-import org.jboss.ws.core.soap.attachment.SwapableMemoryDataSource;
-import org.jboss.ws.core.utils.DOMUtils;
-import org.jboss.ws.core.utils.DOMWriter;
-import org.jboss.ws.core.utils.JavaUtils;
-import org.jboss.ws.core.utils.MimeUtils;
-import org.jboss.ws.extensions.xop.XOPContext;
-import org.jboss.ws.metadata.umdm.ParameterMetaData;
-import org.jboss.ws.metadata.umdm.UnifiedMetaData;
-import org.w3c.dom.Attr;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.TypeInfo;
-
/**
- * A SOAPElement that gives access to its content as XML fragment or Java object.
+ * A SOAPElement that gives access to its content as XML fragment or Java
object.<p>
*
- * The SOAPContentElement has three content representations, which may exist in
parallel.
+ * The SOAPContentElement has three content representations, which may not exist in
parallel.
* The getter and setter of the content properties perform the conversions.
- * It is the responsibility of this objects to keep the representations in sync.
- *
+ * <pre>
* +---------+ +-------------+ +-------------+
* | Object | <-----> | XMLFragment | <-----> | DOMTree |
* +---------+ +-------------+ +-------------+
+ * </pre>
+ * The idea is, that handlers can work with both the object and the dom view of this
SOAPElement.
+ * Note that transitions may be expensive.
*
- * The idea is, that jaxrpc handlers can work with both the object and the dom view of
this SOAPElement.
- * Note, that state transitions may be expensive.
+ * @see ObjectContent
+ * @see XMLContent
+ * @see DOMContent
*
* @author Thomas.Diesler(a)jboss.org
+ * @author Heiko.Braun(a)jboss.org
* @since 13-Dec-2004
+ *
*/
-public class SOAPContentElement extends SOAPElementImpl
-{
+public class SOAPContentElement extends SOAPElementImpl implements SOAPContentAccess {
+
// provide logging
private static Logger log = Logger.getLogger(SOAPContentElement.class);
- // The well formed XML content of this element.
- private String xmlFragment;
- // The java object content of this element.
- private Object objectValue;
- // True if the current DOM tree is valid
- private boolean isDOMValid;
- // True if the current content object is valid
- private boolean isObjectValid;
- // True while expanding to DOM
- private boolean expandingToDOM;
-
// The associated parameter
private ParameterMetaData paramMetaData;
+ // content soapContent
+ private SOAPContent soapContent;
+
+ // while transitioning DOM expansion needs to be locked
+ private boolean lockDOMExpansion = false;
+
/** Construct a SOAPContentElement
*/
public SOAPContentElement(Name name)
{
super(name);
- isDOMValid = true;
+ this.soapContent = new DOMContent(this);
}
public SOAPContentElement(QName qname)
{
super(qname);
- isDOMValid = true;
+ this.soapContent = new DOMContent(this);
}
public SOAPContentElement(SOAPElementImpl element)
{
super(element);
- isDOMValid = true;
+ this.soapContent = new DOMContent(this);
}
- public ParameterMetaData getParamMetaData()
+ ParameterMetaData getParamMetaData()
{
if (paramMetaData == null)
throw new IllegalStateException("Parameter meta data not available");
@@ -151,400 +118,102 @@
return getParamMetaData().getJavaType();
}
- public boolean isDOMValid()
+ private void transitionTo(SOAPContent.State nextState)
{
- return isDOMValid;
- }
+ if(nextState!=soapContent.getState())
+ {
+ log.debug("Transitioning from " + soapContent.getState() + " to
" + nextState);
+ lockDOMExpansion = true;
- public boolean isObjectValid()
- {
- return isObjectValid;
- }
+ soapContent = soapContent.transitionTo(nextState);
- public boolean isFragmentValid()
- {
- return xmlFragment != null;
+ lockDOMExpansion = false;
+ }
}
-
+
/** Get the payload as source.
*/
public Source getPayload()
{
// expand to DOM, so the source is repeatedly readable
- expandToDOM();
- return new DOMSource(this);
+ transitionTo(SOAPContent.State.DOM_VALID);
+ return soapContent.getPayload();
}
/** Set the payload as source
*/
public void setPayload(Source source)
{
- try
- {
- TransformerFactory tf = TransformerFactory.newInstance();
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
- tf.newTransformer().transform(source, new StreamResult(baos));
- String xmlFragment = new String(baos.toByteArray());
- if (xmlFragment.startsWith("<?xml"))
- {
- int index = xmlFragment.indexOf(">");
- xmlFragment = xmlFragment.substring(index + 1);
- }
- setXMLFragment(xmlFragment);
- }
- catch (TransformerException ex)
- {
- WSException.rethrow(ex);
- }
+ soapContent = new DOMContent(this);
+ soapContent.setPayload(source);
}
- public String getXMLFragment()
+ public XMLFragment getXMLFragment()
{
- // Serialize the valueContent
- if (xmlFragment == null && isObjectValid)
- {
- assertContentMapping();
-
- QName xmlType = getXmlType();
- Class javaType = getJavaType();
- QName xmlName = getElementQName();
-
- log.debug("getXMLFragment from Object [xmlType=" + xmlType +
",javaType=" + javaType + "]");
-
- CommonMessageContext msgContext =
MessageContextAssociation.peekMessageContext();
- if (msgContext == null)
- throw new WSException("MessageContext not available");
-
- SerializationContext serContext = msgContext.getSerializationContext();
- serContext.setProperty(ParameterMetaData.class.getName(), getParamMetaData());
-
- TypeMappingImpl typeMapping = serContext.getTypeMapping();
-
- try
- {
- SerializerSupport ser;
- if (objectValue != null)
- {
- SerializerFactoryBase serializerFactory =
getSerializerFactory(typeMapping, javaType, xmlType);
- ser = (SerializerSupport)serializerFactory.getSerializer();
- }
- else
- {
- ser = new NullValueSerializer();
- }
-
- String tmpFragment = ser.serialize(xmlName, xmlType, getObjectValue(),
serContext, null);
- log.debug("xmlFragment: " + tmpFragment);
-
- setXMLFragment(tmpFragment);
- }
- catch (BindingException e)
- {
- throw new WSException(e);
- }
- }
-
- // Generate the xmlFragment from the DOM tree
- else if (xmlFragment == null && isDOMValid)
- {
- log.debug("getXMLFragment from DOM");
- xmlFragment = DOMWriter.printNode(this, false);
- log.debug("xmlFragment: " + xmlFragment);
- invalidateDOMContent();
- }
-
- if (xmlFragment == null || xmlFragment.startsWith("<") == false)
- throw new WSException("Invalid XMLFragment: " + xmlFragment);
-
- return xmlFragment;
+ transitionTo(SOAPContent.State.XML_VALID);
+ return soapContent.getXMLFragment();
}
- public void setXMLFragment(String xmlFragment)
+ public void setXMLFragment(XMLFragment xmlFragment)
{
- log.debug("setXMLFragment: " + xmlFragment);
-
- if (xmlFragment == null || xmlFragment.startsWith("<") == false)
- throw new WSException("Invalid XMLFragment: " + xmlFragment);
-
- removeContentsAsIs();
- resetElementContent();
-
- this.xmlFragment = xmlFragment;
- invalidateDOMContent();
- invalidateObjectContent();
+ soapContent = new XMLContent(this);
+ soapContent.setXMLFragment(xmlFragment);
}
public Object getObjectValue()
{
- if (isObjectValid == false)
- {
- QName xmlType = getXmlType();
- Class javaType = getJavaType();
-
- log.debug("getObjectValue [xmlType=" + xmlType +
",javaType=" + javaType + "]");
- assertContentMapping();
-
- CommonMessageContext msgContext =
MessageContextAssociation.peekMessageContext();
- if (msgContext == null)
- throw new WSException("MessageContext not available");
-
- SerializationContext serContext = msgContext.getSerializationContext();
- ParameterMetaData pmd = getParamMetaData();
- serContext.setProperty(ParameterMetaData.class.getName(), pmd);
- List<Class> registeredTypes =
pmd.getOperationMetaData().getEndpointMetaData().getRegisteredTypes();
- serContext.setProperty(SerializationContext.CONTEXT_TYPES,
registeredTypes.toArray(new Class[0]));
-
- try
- {
- // Get the deserializer from the type mapping
- TypeMappingImpl typeMapping = serContext.getTypeMapping();
- DeserializerFactoryBase deserializerFactory =
getDeserializerFactory(typeMapping, javaType, xmlType);
- DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
-
- String strContent = getXMLFragment();
-
- Object obj = des.deserialize(getElementQName(), xmlType, strContent,
serContext);
- if (obj != null)
- {
- Class objType = obj.getClass();
- boolean isAssignable = JavaUtils.isAssignableFrom(javaType, objType);
- if (isAssignable == false && javaType.isArray())
- {
- try
- {
- Method toArrayMethod = objType.getMethod("toArray", new
Class[] {});
- Class returnType = toArrayMethod.getReturnType();
- if (JavaUtils.isAssignableFrom(javaType, returnType))
- {
- Method getValueMethod = objType.getMethod("getValue",
new Class[] {});
- Object value = getValueMethod.invoke(obj, new Object[] {});
- if (value != null)
- {
- // Do not invoke toArray if getValue returns null
- obj = toArrayMethod.invoke(obj, new Object[] {});
- }
- else
- {
- // if the fragment did not indicate a null return
- // by an xsi:nil we return an empty array
- Class componentType = javaType.getComponentType();
- obj = Array.newInstance(componentType, 0);
- }
- isAssignable = true;
- }
- }
- catch (Exception e)
- {
- // ignore
- }
- }
-
- if (isAssignable == false)
- {
- // handle XOP simple types, i.e. in RPC/LIT
- try
- {
- String contentType = MimeUtils.resolveMimeType(javaType);
- log.debug("Adopt DataHandler to " + javaType +",
contentType "+ contentType);
-
- DataSource ds = new
SwapableMemoryDataSource(((DataHandler)obj).getInputStream(), contentType);
- DataHandler dh = new DataHandler(ds);
- obj = dh.getContent();
-
- // 'application/octet-stream' will return a byte[] instead
fo the stream
- if(obj instanceof InputStream)
- {
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- dh.writeTo(bout);
- obj = bout.toByteArray();
- }
- }
- catch (IOException e)
- {
- throw new WSException("Failed to adopt XOP content type",
e);
- }
-
- if(!JavaUtils.isAssignableFrom(javaType, obj.getClass()))
- {
- throw new WSException("Java type '" + javaType +
"' is not assignable from: " + objType.getName());
- }
- }
- }
-
- this.objectValue = obj;
- this.isObjectValid = true;
- }
- catch (BindingException e)
- {
- throw new WSException(e);
- }
-
- log.debug("objectValue: " + (objectValue != null ?
objectValue.getClass().getName() : null));
- }
-
- return objectValue;
+ transitionTo(SOAPContent.State.OBJECT_VALID);
+ return soapContent.getObjectValue();
}
public void setObjectValue(Object objValue)
{
- log.debug("setObjectValue: " + objValue);
- removeContentsAsIs();
- resetElementContent();
- this.objectValue = objValue;
- this.isObjectValid = true;
+ soapContent = new ObjectContent(this);
+ soapContent.setObjectValue(objValue);
}
- private void removeContentsAsIs()
- {
- log.trace("removeContentsAsIs");
- boolean cachedFlag = isDOMValid;
- try
- {
- this.isDOMValid = true;
- super.removeContents();
- }
- finally
- {
- this.isDOMValid = cachedFlag;
- }
- }
-
- // Get the serializer factory for a given javaType and xmlType
- private SerializerFactoryBase getSerializerFactory(TypeMappingImpl typeMapping, Class
javaType, QName xmlType)
- {
- SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(javaType, xmlType);
-
- // The type mapping might contain a mapping for the array wrapper bean
- if (serializerFactory == null && javaType.isArray())
- {
- Class arrayWrapperType = typeMapping.getJavaType(xmlType);
- if (arrayWrapperType != null)
- {
- try
- {
- Method toArrayMethod = arrayWrapperType.getMethod("toArray", new
Class[] {});
- Class returnType = toArrayMethod.getReturnType();
- if (JavaUtils.isAssignableFrom(javaType, returnType))
- {
- serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(arrayWrapperType, xmlType);
- }
- }
- catch (NoSuchMethodException e)
- {
- // ignore
- }
- }
- }
-
- if (serializerFactory == null)
- throw new WSException("Cannot obtain serializer factory for:
[xmlType=" + xmlType + ",javaType=" + javaType + "]");
-
- return serializerFactory;
- }
-
- // Get the deserializer factory for a given javaType and xmlType
- private DeserializerFactoryBase getDeserializerFactory(TypeMappingImpl typeMapping,
Class javaType, QName xmlType)
- {
- DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(javaType, xmlType);
-
- // The type mapping might contain a mapping for the array wrapper bean
- if (deserializerFactory == null && javaType.isArray())
- {
- Class arrayWrapperType = typeMapping.getJavaType(xmlType);
- if (arrayWrapperType != null)
- {
- try
- {
- Method toArrayMethod = arrayWrapperType.getMethod("toArray", new
Class[] {});
- Class returnType = toArrayMethod.getReturnType();
- if (JavaUtils.isAssignableFrom(javaType, returnType))
- {
- deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(arrayWrapperType, xmlType);
- }
- }
- catch (NoSuchMethodException e)
- {
- // ignore
- }
- }
- }
-
- if (deserializerFactory == null)
- throw new WSException("Cannot obtain deserializer factory for:
[xmlType=" + xmlType + ",javaType=" + javaType + "]");
-
- return deserializerFactory;
- }
-
- /** Assert the notNull state of the xmlType and javaType
- */
- private void assertContentMapping()
- {
- if (getJavaType() == null)
- throw new WSException("javaType cannot be null");
- if (getXmlType() == null)
- throw new WSException("xmlType cannot be null");
- }
-
// SOAPElement interface
********************************************************************************************
public SOAPElement addChildElement(SOAPElement child) throws SOAPException
{
log.trace("addChildElement: " + child);
expandToDOM();
- SOAPElement soapElement = super.addChildElement(child);
- invalidateObjectContent();
- invalidateXMLContent();
- return soapElement;
+ return super.addChildElement(child);
}
public SOAPElement addChildElement(String localName, String prefix) throws
SOAPException
{
log.trace("addChildElement: [localName=" + localName +
",prefix=" + prefix + "]");
expandToDOM();
- SOAPElement soapElement = super.addChildElement(localName, prefix);
- invalidateObjectContent();
- invalidateXMLContent();
- return soapElement;
+ return super.addChildElement(localName, prefix);
}
public SOAPElement addChildElement(String localName, String prefix, String uri) throws
SOAPException
{
log.trace("addChildElement: [localName=" + localName +
",prefix=" + prefix + ",uri=" + uri + "]");
expandToDOM();
- SOAPElement soapElement = super.addChildElement(localName, prefix, uri);
- invalidateObjectContent();
- invalidateXMLContent();
- return soapElement;
+ return super.addChildElement(localName, prefix, uri);
}
public SOAPElement addChildElement(Name name) throws SOAPException
{
log.trace("addChildElement: [name=" + name + "]");
expandToDOM();
- SOAPElement soapElement = super.addChildElement(name);
- invalidateObjectContent();
- invalidateXMLContent();
- return soapElement;
+ return super.addChildElement(name);
}
public SOAPElement addChildElement(String name) throws SOAPException
{
log.trace("addChildElement: [name=" + name + "]");
expandToDOM();
- SOAPElement soapElement = super.addChildElement(name);
- invalidateObjectContent();
- invalidateXMLContent();
- return soapElement;
+ return super.addChildElement(name);
}
public SOAPElement addTextNode(String value) throws SOAPException
{
log.trace("addTextNode: [value=" + value + "]");
expandToDOM();
- SOAPElement soapElement = super.addTextNode(value);
- invalidateObjectContent();
- invalidateXMLContent();
- return soapElement;
+ return super.addTextNode(value);
}
public Iterator getChildElements()
@@ -566,8 +235,6 @@
log.trace("removeContents");
expandToDOM();
super.removeContents();
- invalidateObjectContent();
- invalidateXMLContent();
}
public Iterator getAllAttributes()
@@ -768,10 +435,7 @@
{
log.trace("appendChild: " + newChild);
expandToDOM();
- Node node = super.appendChild(newChild);
- invalidateObjectContent();
- invalidateXMLContent();
- return node;
+ return super.appendChild(newChild);
}
public Node cloneNode(boolean deep)
@@ -820,29 +484,26 @@
{
log.trace("removeChild: " + oldChild);
expandToDOM();
- Node node = super.removeChild(oldChild);
- invalidateObjectContent();
- invalidateXMLContent();
- return node;
+ return super.removeChild(oldChild);
}
public Node replaceChild(Node newChild, Node oldChild) throws DOMException
{
log.trace("replaceChild: [new=" + newChild + ",old=" + oldChild
+ "]");
expandToDOM();
- Node node = super.replaceChild(newChild, oldChild);
- invalidateObjectContent();
- invalidateXMLContent();
- return node;
+ return super.replaceChild(newChild, oldChild);
}
+ private void expandToDOM() {
+ if(!lockDOMExpansion)
+ transitionTo(SOAPContent.State.DOM_VALID);
+ }
+
public void setValue(String value)
{
log.trace("setValue: " + value);
expandToDOM();
super.setValue(value);
- invalidateObjectContent();
- invalidateXMLContent();
}
public NamedNodeMap getAttributes()
@@ -857,190 +518,19 @@
// END Node interface
***********************************************************************************************
- /** Expand the content, generating appropriate child nodes
- */
- private void expandToDOM()
- {
- // SOAPContentElements should only be expanded when handlers do require it.
- if (isDOMValid == false && expandingToDOM == false)
- {
- log.trace("BEGIN: expandToDOM " + getElementName());
- expandingToDOM = true;
-
- // DOM expansion should only happen when a handler accesses the DOM API.
- CommonMessageContext msgContext =
MessageContextAssociation.peekMessageContext();
- if (msgContext != null && !UnifiedMetaData.isFinalRelease())
- {
- Boolean allowExpand =
(Boolean)msgContext.getProperty(CommonMessageContext.ALLOW_EXPAND_TO_DOM);
- if (Boolean.TRUE.equals(allowExpand) == false)
- throw new WSException("Expanding content element to DOM");
- }
-
- try
- {
- if (xmlFragment == null && isObjectValid)
- xmlFragment = getXMLFragment();
-
- if (xmlFragment == null && isObjectValid == false)
- throw new IllegalStateException("Neither DOM, nor XML, nor Object
valid");
-
- if (xmlFragment != null)
- {
- String wrappedXMLFragment =
insertNamespaceDeclarations("<wrapper>" + xmlFragment +
"</wrapper>");
- Element contentRoot = DOMUtils.parse(wrappedXMLFragment);
- contentRoot = DOMUtils.getFirstChildElement(contentRoot);
-
- String rootLocalName = contentRoot.getLocalName();
- String rootPrefix = contentRoot.getPrefix();
- String rootNS = contentRoot.getNamespaceURI();
- Name contentRootName = new NameImpl(rootLocalName, rootPrefix, rootNS);
-
- // Make sure the content root element name matches this element name
- Name name = getElementName();
- if (contentRootName.equals(name) == false)
- throw new WSException("Content root name does not match element
name: " + contentRootName + " != " + name);
-
- // Copy attributes
- DOMUtils.copyAttributes(this, contentRoot);
-
- SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
-
- NodeList nlist = contentRoot.getChildNodes();
- for (int i = 0; i < nlist.getLength(); i++)
- {
- Node child = nlist.item(i);
- short childType = child.getNodeType();
- if (childType == Node.ELEMENT_NODE)
- {
- SOAPElement soapElement =
soapFactory.createElement((Element)child);
- super.addChildElement(soapElement);
- if (Constants.NAME_XOP_INCLUDE.equals(name) || isXOPParameter())
- XOPContext.inlineXOPData(soapElement);
- }
- else if (childType == Node.TEXT_NODE)
- {
- String nodeValue = child.getNodeValue();
- super.addTextNode(nodeValue);
- }
- else if (childType == Node.CDATA_SECTION_NODE)
- {
- String nodeValue = child.getNodeValue();
- super.addTextNode(nodeValue);
- }
- else
- {
- log.trace("Ignore child type: " + childType);
- }
- }
- }
-
- isDOMValid = true;
- }
- catch (RuntimeException e)
- {
- invalidateDOMContent();
- throw e;
- }
- catch (Exception e)
- {
- invalidateDOMContent();
- throw new WSException(e);
- }
- finally
- {
- expandingToDOM = false;
- log.trace("END: expandToDOM " + getElementName());
- }
-
- invalidateXMLContent();
- invalidateObjectContent();
- }
- }
-
- public String insertNamespaceDeclarations(String xmlfragment)
- {
- StringBuilder xmlBuffer = new StringBuilder(xmlfragment);
-
- int endIndex = xmlfragment.indexOf(">");
- int insIndex = endIndex;
- if (xmlfragment.charAt(insIndex - 1) == '/')
- insIndex = insIndex - 1;
-
- SOAPElement soapElement = this;
- while (soapElement != null)
- {
- Iterator it = soapElement.getNamespacePrefixes();
- while (it.hasNext())
- {
- String prefix = (String)it.next();
- String nsURI = soapElement.getNamespaceURI(prefix);
- String nsDecl = " xmlns:" + prefix + "='" + nsURI +
"'";
-
- // Make sure there is not a duplicate on just the wrapper tag
- int nsIndex = xmlBuffer.indexOf("xmlns:" + prefix);
- if (nsIndex < 0 || nsIndex > endIndex)
- {
- xmlBuffer.insert(insIndex, nsDecl);
- endIndex += nsDecl.length();
- }
- }
- soapElement = soapElement.getParentElement();
- }
-
- log.trace("insertNamespaceDeclarations: " + xmlBuffer);
- return xmlBuffer.toString();
- }
-
- private void invalidateDOMContent()
- {
- if (expandingToDOM == false)
- {
- log.trace("invalidateDOMContent");
- this.isDOMValid = false;
- }
- }
-
- private void invalidateObjectContent()
- {
- if (expandingToDOM == false)
- {
- log.trace("invalidateObjectContent");
- this.isObjectValid = false;
- this.objectValue = null;
- }
- }
-
- private void invalidateXMLContent()
- {
- if (expandingToDOM == false)
- {
- log.trace("invalidateXMLContent");
- this.xmlFragment = null;
- }
- }
-
- private void resetElementContent()
- {
- if (expandingToDOM == false)
- {
- log.trace("resetElementContent");
- invalidateDOMContent();
- invalidateObjectContent();
- invalidateXMLContent();
- }
- }
-
public void writeElement(Writer writer) throws IOException
{
handleMTOMTransitions();
- if (isDOMValid)
+ if (soapContent instanceof DOMContent)
{
new DOMWriter(writer).print(this);
}
else
{
- writer.write(getXMLFragment());
+ transitionTo(SOAPContent.State.XML_VALID);
+ soapContent.getXMLFragment().writeTo(writer);
+
}
}
@@ -1059,9 +549,10 @@
public void handleMTOMTransitions()
{
// MTOM processing is only required on XOP parameters
- if( isXOPParameter() == false)
- return;
+ if(!isXOPParameter()) return;
+ boolean domContentState = (soapContent instanceof DOMContent);
+
if ( !XOPContext.isMTOMEnabled() )
{
// If MTOM is disabled, we force dom expansion on XOP parameters.
@@ -1073,7 +564,7 @@
msgContext.setProperty(CommonMessageContext.ALLOW_EXPAND_TO_DOM, Boolean.TRUE);
expandToDOM();
}
- else if ( isDOMValid && XOPContext.isMTOMEnabled() )
+ else if ( domContentState && XOPContext.isMTOMEnabled() )
{
// When the DOM representation is valid,
// but MTOM is enabled we need to convert the inlined
@@ -1084,7 +575,7 @@
}
}
- private boolean isXOPParameter()
+ boolean isXOPParameter()
{
return paramMetaData != null && paramMetaData.isXOP();
}
Added:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLContent.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLContent.java
(rev 0)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLContent.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -0,0 +1,322 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.core.soap;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.Constants;
+import org.jboss.ws.WSException;
+import org.jboss.ws.core.CommonMessageContext;
+import org.jboss.ws.core.jaxrpc.TypeMappingImpl;
+import org.jboss.ws.core.jaxrpc.binding.BindingException;
+import org.jboss.ws.core.jaxrpc.binding.DeserializerFactoryBase;
+import org.jboss.ws.core.jaxrpc.binding.DeserializerSupport;
+import org.jboss.ws.core.jaxrpc.binding.SerializationContext;
+import org.jboss.ws.core.soap.attachment.SwapableMemoryDataSource;
+import org.jboss.ws.core.utils.DOMUtils;
+import org.jboss.ws.core.utils.JavaUtils;
+import org.jboss.ws.core.utils.MimeUtils;
+import org.jboss.ws.extensions.xop.XOPContext;
+import org.jboss.ws.metadata.umdm.ParameterMetaData;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.xml.namespace.QName;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.transform.Source;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+import java.util.List;
+
+/**
+ * @author Heiko.Braun(a)jboss.org
+ * @version $Id:$
+ * @since 05.02.2007
+ */
+class XMLContent extends SOAPContent {
+
+ private static final Logger log = Logger.getLogger(XMLContent.class);
+
+ // The well formed XML content of this element.
+ private XMLFragment xmlFragment;
+
+ protected XMLContent(SOAPContentElement container) {
+ super(container);
+ }
+
+ State getState() {
+ return State.XML_VALID;
+ }
+
+ SOAPContent transitionTo(State nextState) {
+
+ SOAPContent next;
+
+ if(State.XML_VALID == nextState)
+ {
+ next = this;
+ }
+ else if(State.OBJECT_VALID == nextState)
+ {
+ Object obj = unmarshallObjectContents();
+ SOAPContent objectValid = new ObjectContent(container);
+ objectValid.setObjectValue(obj);
+ next = objectValid;
+ }
+ else if(State.DOM_VALID == nextState)
+ {
+ expandContainerChildren();
+ next = new DOMContent(container);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Illegal state requested: " +
nextState);
+ }
+
+ return next;
+ }
+
+ private Object unmarshallObjectContents() {
+
+ Object obj;
+ QName xmlType = container.getXmlType();
+ Class javaType = container.getJavaType();
+
+ log.debug("getObjectValue [xmlType=" + xmlType + ",javaType=" +
javaType + "]");
+
+ CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
+ if (msgContext == null)
+ throw new WSException("MessageContext not available");
+
+ SerializationContext serContext = msgContext.getSerializationContext();
+ ParameterMetaData pmd = container.getParamMetaData();
+ serContext.setProperty(ParameterMetaData.class.getName(), pmd);
+ List<Class> registeredTypes =
pmd.getOperationMetaData().getEndpointMetaData().getRegisteredTypes();
+ serContext.setProperty(SerializationContext.CONTEXT_TYPES,
registeredTypes.toArray(new Class[0]));
+
+ try
+ {
+ // Get the deserializer from the type mapping
+ TypeMappingImpl typeMapping = serContext.getTypeMapping();
+ DeserializerFactoryBase deserializerFactory =
getDeserializerFactory(typeMapping, javaType, xmlType);
+ DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
+
+ obj = des.deserialize(container.getElementQName(), xmlType,
xmlFragment.getSource(), serContext);
+ if (obj != null)
+ {
+ Class objType = obj.getClass();
+ boolean isAssignable = JavaUtils.isAssignableFrom(javaType, objType);
+ if (!isAssignable && javaType.isArray())
+ {
+ try
+ {
+ Method toArrayMethod = objType.getMethod("toArray");
+ Class returnType = toArrayMethod.getReturnType();
+ if (JavaUtils.isAssignableFrom(javaType, returnType))
+ {
+ Method getValueMethod = objType.getMethod("getValue");
+ Object value = getValueMethod.invoke(obj);
+ if (value != null)
+ {
+ // Do not invoke toArray if getValue returns null
+ obj = toArrayMethod.invoke(obj);
+ }
+ else
+ {
+ // if the fragment did not indicate a null return
+ // by an xsi:nil we return an empty array
+ Class componentType = javaType.getComponentType();
+ obj = Array.newInstance(componentType, 0);
+ }
+ isAssignable = true;
+ }
+ }
+ catch (Exception e)
+ {
+ // ignore
+ }
+ }
+
+ if (!isAssignable)
+ {
+ // handle XOP simple types, i.e. in RPC/LIT
+ try
+ {
+ String contentType = MimeUtils.resolveMimeType(javaType);
+ log.debug("Adopt DataHandler to " + javaType +",
contentType "+ contentType);
+
+ DataSource ds = new
SwapableMemoryDataSource(((DataHandler)obj).getInputStream(), contentType);
+ DataHandler dh = new DataHandler(ds);
+ obj = dh.getContent();
+
+ // 'application/octet-stream' will return a byte[] instead fo
the stream
+ if(obj instanceof InputStream)
+ {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ dh.writeTo(bout);
+ obj = bout.toByteArray();
+ }
+ }
+ catch (IOException e)
+ {
+ throw new WSException("Failed to adopt XOP content type",
e);
+ }
+
+ if(!JavaUtils.isAssignableFrom(javaType, obj.getClass()))
+ {
+ throw new WSException("Java type '" + javaType +
"' is not assignable from: " + objType.getName());
+ }
+ }
+ }
+ }
+ catch (BindingException e)
+ {
+ throw new WSException(e);
+ }
+
+ log.debug("objectValue: " + (obj != null ? obj.getClass().getName() :
null));
+
+ return obj;
+ }
+
+// Get the deserializer factory for a given javaType and xmlType
+ private static DeserializerFactoryBase getDeserializerFactory(TypeMappingImpl
typeMapping, Class javaType, QName xmlType)
+ {
+ DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(javaType, xmlType);
+
+ // The type mapping might contain a mapping for the array wrapper bean
+ if (deserializerFactory == null && javaType.isArray())
+ {
+ Class arrayWrapperType = typeMapping.getJavaType(xmlType);
+ if (arrayWrapperType != null)
+ {
+ try
+ {
+ Method toArrayMethod = arrayWrapperType.getMethod("toArray");
+ Class returnType = toArrayMethod.getReturnType();
+ if (JavaUtils.isAssignableFrom(javaType, returnType))
+ {
+ deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(arrayWrapperType, xmlType);
+ }
+ }
+ catch (NoSuchMethodException e)
+ {
+ // ignore
+ }
+ }
+ }
+
+ if (deserializerFactory == null)
+ throw new WSException("Cannot obtain deserializer factory for:
[xmlType=" + xmlType + ",javaType=" + javaType + "]");
+
+ return deserializerFactory;
+ }
+
+ /**
+ * Turn the xml fragment into a DOM repersentation and append
+ * all children to the container.
+ */
+ private void expandContainerChildren() {
+
+ Element contentRoot = xmlFragment.toElement();
+
+ String rootLocalName = contentRoot.getLocalName();
+ String rootPrefix = contentRoot.getPrefix();
+ String rootNS = contentRoot.getNamespaceURI();
+ Name contentRootName = new NameImpl(rootLocalName, rootPrefix, rootNS);
+
+ // Make sure the content root element name matches this element name
+ Name name = container.getElementName();
+ if (!contentRootName.equals(name))
+ throw new WSException("Content root name does not match element name:
" + contentRootName + " != " + name);
+
+ // Copy attributes
+ DOMUtils.copyAttributes(container, contentRoot);
+
+ SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
+
+ try {
+ NodeList nlist = contentRoot.getChildNodes();
+ for (int i = 0; i < nlist.getLength(); i++)
+ {
+ Node child = nlist.item(i);
+ short childType = child.getNodeType();
+ if (childType == Node.ELEMENT_NODE)
+ {
+ SOAPElement soapElement = soapFactory.createElement((Element)child);
+ container.addChildElement(soapElement);
+ if (Constants.NAME_XOP_INCLUDE.equals(name) ||
container.isXOPParameter())
+ XOPContext.inlineXOPData(soapElement);
+ }
+ else if (childType == Node.TEXT_NODE)
+ {
+ String nodeValue = child.getNodeValue();
+ container.addTextNode(nodeValue);
+ }
+ else if (childType == Node.CDATA_SECTION_NODE)
+ {
+ String nodeValue = child.getNodeValue();
+ container.addTextNode(nodeValue);
+ }
+ else
+ {
+ log.trace("Ignore child type: " + childType);
+ }
+ }
+ } catch (SOAPException e) {
+ throw new WSException("Failed to transition to DOM", e);
+ }
+ }
+
+ public Source getPayload() {
+ throw new IllegalStateException("Payload not available");
+ }
+
+ public void setPayload(Source source) {
+ throw new IllegalStateException("Payload not available");
+ }
+
+ public XMLFragment getXMLFragment() {
+ return this.xmlFragment;
+ }
+
+ public void setXMLFragment(XMLFragment xmlFragment) {
+
+ this.xmlFragment = xmlFragment;
+ }
+
+ public Object getObjectValue() {
+ throw new IllegalStateException("Object value not available");
+ }
+
+ public void setObjectValue(Object objValue) {
+ throw new IllegalStateException("Object value not available");
+ }
+
+}
Added:
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLFragment.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLFragment.java
(rev 0)
+++
branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLFragment.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -0,0 +1,194 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.core.soap;
+
+import org.jboss.ws.WSException;
+import org.jboss.ws.core.utils.DOMUtils;
+import org.jboss.ws.core.utils.DOMWriter;
+import org.w3c.dom.Element;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.*;
+
+/**
+ * @author Heiko.Braun(a)jboss.org
+ * @version $Id:$
+ * @since 05.02.2007
+ */
+public class XMLFragment {
+
+ private Source source;
+ private Result result;
+
+ public XMLFragment(Source source) {
+ this.source = source;
+ }
+
+ public XMLFragment(Result result) {
+ this.result = result;
+ }
+
+ public Source getSource() {
+ if(null == source)
+ throw new IllegalStateException("Source not available");
+ return source;
+ }
+
+ public Result getResult() {
+ if(null == source)
+ throw new IllegalStateException("Result not available");
+ return result;
+ }
+
+ // TODO: replace with less invasive conversion
+ public String toStringFragment()
+ {
+ if(this.source != null)
+ return sourceToStringFragement(this.source);
+ else
+ return resultToStringFragment(this.result);
+ }
+
+ public Element toElement()
+ {
+ Element n = null;
+ try {
+ n = DOMUtils.parse( toStringFragment() );
+ } catch (IOException e) {
+ WSException.rethrow(e);
+ }
+
+ return n;
+ }
+
+ /**
+ * Factory method to create XMLFragment from strings.
+ * @param fragment
+ * @return new XMLFragment
+ */
+ public static XMLFragment fromStringFragment(String fragment)
+ {
+ Source source = new StreamSource(new ByteArrayInputStream(fragment.getBytes()));
+ return new XMLFragment(source);
+ }
+
+ private static String resultToStringFragment(Result result) {
+
+ if(result instanceof DOMResult)
+ {
+ return DOMWriter.printNode( ((DOMResult)result).getNode(), false);
+ }
+
+ throw new IllegalArgumentException("Unable to process
javax.xml.transform.Result implementation :" + result);
+
+ }
+
+ private static String sourceToStringFragement(Source source) {
+ String xmlFragment = null;
+
+ try {
+ TransformerFactory tf = TransformerFactory.newInstance();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+ tf.newTransformer().transform(source, new StreamResult(baos));
+ xmlFragment = new String(baos.toByteArray());
+ if (xmlFragment.startsWith("<?xml"))
+ {
+ int index = xmlFragment.indexOf(">");
+ xmlFragment = xmlFragment.substring(index + 1);
+ }
+ } catch (TransformerException e) {
+ WSException.rethrow(e);
+ }
+
+ return xmlFragment;
+ }
+
+ public void writeTo(Writer writer) throws IOException
+ {
+ if(result != null )
+ {
+ writeResult(writer);
+ }
+ else
+ {
+ writeSource(writer);
+ }
+ }
+
+ private void writeSource(Writer writer) throws IOException{
+ if(source instanceof DOMSource)
+ {
+ DOMSource domSource = (DOMSource)source;
+ DOMWriter dw = new DOMWriter(writer).setPrettyprint(false);
+ dw.print(domSource.getNode());
+ }
+ else if(source instanceof StreamSource)
+ {
+ StreamSource streamSource = (StreamSource)source;
+ copyStream(streamSource.getInputStream(), writer);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unable to process
javax.xml.transform.Source implementation :" + result);
+ }
+ }
+
+ private static void copyStream(InputStream ins, Writer writer) throws IOException
+ {
+ byte[] bytes = new byte[1024];
+ int r = ins.read(bytes);
+ while (r > 0)
+ {
+ writer.write(new String(bytes), 0, r);
+ r = ins.read(bytes);
+ }
+ }
+
+ private void writeResult(Writer writer) {
+ if(result instanceof DOMResult)
+ {
+ DOMResult domResult = (DOMResult)result;
+ DOMWriter dw = new DOMWriter(writer).setPrettyprint(false);
+ dw.print(domResult.getNode());
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unable to process
javax.xml.transform.Result implementation :" + result);
+ }
+ }
+
+ public void writeTo(OutputStream out) throws IOException
+ {
+ writeTo( new PrintWriter(out) );
+ }
+
+ public String toString() {
+ return toStringFragment();
+ }
+}
Modified:
branches/hbraun/1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/jbossxb/SerializerDeserializerTestCase.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/jbossxb/SerializerDeserializerTestCase.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/jbossxb/SerializerDeserializerTestCase.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -26,9 +26,13 @@
import java.net.URI;
import java.util.Calendar;
import java.util.GregorianCalendar;
+import java.io.ByteArrayInputStream;
import javax.xml.namespace.QName;
import javax.xml.rpc.encoding.TypeMappingRegistry;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
import org.jboss.test.ws.JBossWSTest;
import org.jboss.ws.Constants;
@@ -40,6 +44,7 @@
import org.jboss.ws.core.jaxrpc.binding.SerializationContext;
import org.jboss.ws.core.jaxrpc.binding.SerializerFactoryBase;
import org.jboss.ws.core.jaxrpc.binding.SerializerSupport;
+import org.jboss.ws.core.soap.XMLFragment;
import org.jboss.xb.binding.NamespaceRegistry;
/**
@@ -73,12 +78,13 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(String.class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(String.class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- String out = (String)des.deserialize(xmlName, xmlType, xmlFragment, serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ String out = (String)des.deserialize(xmlName, xmlType, source, serContext);
assertEquals(value, out);
}
@@ -90,12 +96,13 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(Calendar.class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(Calendar.class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- Calendar out = (Calendar)des.deserialize(xmlName, xmlType, xmlFragment,
serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ Calendar out = (Calendar)des.deserialize(xmlName, xmlType, source, serContext);
assertEquals(value.getTime(), out.getTime());
assertEquals(value.getTimeZone().getRawOffset(),
out.getTimeZone().getRawOffset());
@@ -108,12 +115,13 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(BigInteger.class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(BigInteger.class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- BigInteger out = (BigInteger)des.deserialize(xmlName, xmlType, xmlFragment,
serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ BigInteger out = (BigInteger)des.deserialize(xmlName, xmlType, source,
serContext);
assertEquals(value, out);
}
@@ -125,12 +133,13 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(BigDecimal.class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(BigDecimal.class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- BigDecimal out = (BigDecimal)des.deserialize(xmlName, xmlType, xmlFragment,
serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ BigDecimal out = (BigDecimal)des.deserialize(xmlName, xmlType, source,
serContext);
assertEquals(value, out);
}
@@ -142,8 +151,8 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(QName.class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
// serialization registers the prefix
NamespaceRegistry nsRegistry = serContext.getNamespaceRegistry();
@@ -152,7 +161,8 @@
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(QName.class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- QName out = (QName)des.deserialize(xmlName, xmlType, xmlFragment, serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ QName out = (QName)des.deserialize(xmlName, xmlType, source, serContext);
assertEquals(value, out);
}
@@ -164,12 +174,13 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(URI.class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(URI.class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- URI out = (URI)des.deserialize(xmlName, xmlType, xmlFragment, serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ URI out = (URI)des.deserialize(xmlName, xmlType, source, serContext);
assertEquals(value, out);
}
@@ -181,12 +192,13 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(byte[].class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(byte[].class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- byte[] out = (byte[])des.deserialize(xmlName, xmlType, xmlFragment, serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ byte[] out = (byte[])des.deserialize(xmlName, xmlType, source, serContext);
assertEquals(new String(value), new String(out));
}
@@ -198,12 +210,13 @@
SerializerFactoryBase serializerFactory =
(SerializerFactoryBase)typeMapping.getSerializer(byte[].class, xmlType);
SerializerSupport ser = (SerializerSupport)serializerFactory.getSerializer();
- String xmlFragment = ser.serialize(xmlName, xmlType, value, serContext, null);
- assertNotNull(xmlFragment);
+ Result result = ser.serialize(xmlName, xmlType, value, serContext, null);
+ assertNotNull(result);
DeserializerFactoryBase deserializerFactory =
(DeserializerFactoryBase)typeMapping.getDeserializer(byte[].class, xmlType);
DeserializerSupport des =
(DeserializerSupport)deserializerFactory.getDeserializer();
- byte[] out = (byte[])des.deserialize(xmlName, xmlType, xmlFragment, serContext);
+ Source source = new StreamSource(new ByteArrayInputStream( new
XMLFragment(result).toStringFragment().getBytes()));
+ byte[] out = (byte[])des.deserialize(xmlName, xmlType, source, serContext);
assertEquals(new String(value), new String(out));
}
Modified:
branches/hbraun/1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java 2007-02-05
21:03:29 UTC (rev 2283)
+++
branches/hbraun/1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -35,6 +35,7 @@
import org.jboss.test.ws.JBossWSTest;
import org.jboss.ws.core.soap.NameImpl;
import org.jboss.ws.core.soap.SOAPContentElement;
+import org.jboss.ws.core.soap.XMLFragment;
/**
* Test the SOAPContentElement
@@ -44,25 +45,25 @@
*/
public class SOAPContentElementTestCase extends JBossWSTest
{
-
+
/** Test that we can lazily create the SOAP tree
*/
public void testChildNodeAccess() throws Exception
{
Name name = new NameImpl("Order", "tns",
"http://someURI");
- String xmlFragment =
- "<tns:Order xmlns:tns='http://someURI'>" +
- "<OrderItem>Ferarri</OrderItem>" +
- "<OrderItem>Lamborgini</OrderItem>" +
- "<OrderItem>JBoss Support</OrderItem>" +
- "<Customer>" +
- "<Name>Thomas</Name>" +
- "</Customer>" +
+ String xmlFragment =
+ "<tns:Order xmlns:tns='http://someURI'>" +
+ "<OrderItem>Ferarri</OrderItem>" +
+ "<OrderItem>Lamborgini</OrderItem>" +
+ "<OrderItem>JBoss Support</OrderItem>" +
+ "<Customer>" +
+ "<Name>Thomas</Name>" +
+ "</Customer>" +
"</tns:Order>";
SOAPContentElement soapEl = new SOAPContentElement(name);
- soapEl.setXMLFragment(xmlFragment);
+ soapEl.setXMLFragment( XMLFragment.fromStringFragment(xmlFragment) );
assertEquals(name, soapEl.getElementName());
@@ -94,7 +95,7 @@
String xmlFragment = "<tns:Order xmlns:tns='http://someURI'>No
child element</tns:Order>";
SOAPContentElement soapEl = new SOAPContentElement(name);
- soapEl.setXMLFragment(xmlFragment);
+ soapEl.setXMLFragment( XMLFragment.fromStringFragment(xmlFragment) );
assertEquals(name, soapEl.getElementName());
assertEquals("No child element", soapEl.getValue());
@@ -108,7 +109,7 @@
String xmlFragment = "<tns:Order
xmlns:tns='http://someURI'/>";
SOAPContentElement soapEl = new SOAPContentElement(name);
- soapEl.setXMLFragment(xmlFragment);
+ soapEl.setXMLFragment( XMLFragment.fromStringFragment(xmlFragment) );
assertEquals(name, soapEl.getElementName());
assertFalse(soapEl.hasChildNodes());
@@ -123,7 +124,7 @@
String xmlFragment = "<tns:BadName xmlns:tns='http://someURI'>No
child element</tns:BadName>";
SOAPContentElement soapEl = new SOAPContentElement(name);
- soapEl.setXMLFragment(xmlFragment);
+ soapEl.setXMLFragment( XMLFragment.fromStringFragment(xmlFragment) );
try
{
@@ -146,7 +147,7 @@
SOAPContentElement soapEl = new SOAPContentElement(name);
soapEl.setAttribute("foo", "Kermit");
- soapEl.setXMLFragment(xmlFragment);
+ soapEl.setXMLFragment( XMLFragment.fromStringFragment(xmlFragment) );
assertEquals(name, soapEl.getElementName());
assertEquals("Kermit", soapEl.getAttributeValue(new
NameImpl("foo")));
@@ -163,9 +164,9 @@
"<ns1:hello
xmlns:ns1='http://handlerservice1.org/wsdl'>" +
"<String_1>world</String_1>" +
"</ns1:hello>" +
- "</env:Body>" +
+ "</env:Body>" +
"</env:Envelope>";
-
+
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapMessage = factory.createMessage(null, new
ByteArrayInputStream(envStr.getBytes()));
SOAPBody soapBody = soapMessage.getSOAPBody();
@@ -182,7 +183,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream();
soapMessage.writeTo(baos);
-
+
String expEnv = "<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:...
xmlns:ns1='http://handlerservice1.org/wsdl'><String_1>wo... header
was added</String_1></ns1:hello></env:Body></env:Envelope>";
assertEquals(expEnv, baos.toString());
}
Added:
branches/hbraun/1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/XMLFragmentTestCase.java
===================================================================
---
branches/hbraun/1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/XMLFragmentTestCase.java
(rev 0)
+++
branches/hbraun/1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/common/soap/XMLFragmentTestCase.java 2007-02-05
22:13:19 UTC (rev 2284)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.common.soap;
+
+import junit.framework.TestCase;
+import org.jboss.ws.core.soap.XMLFragment;
+import org.jboss.ws.core.utils.DOMUtils;
+import org.w3c.dom.Element;
+
+import javax.xml.transform.dom.DOMSource;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+
+/**
+ * @author Heiko.Braun(a)jboss.org
+ * @version $Id:$
+ * @since 05.02.2007
+ */
+public class XMLFragmentTestCase extends TestCase {
+
+ public static String XML_STRING =
"<parent><child/></parent>";
+
+ public void testDOMSourceFragment() throws Exception
+ {
+ Element srcElement = DOMUtils.parse(XML_STRING);
+ XMLFragment xmlFragment = new XMLFragment( new DOMSource(srcElement) );
+ testSourceAPI(xmlFragment);
+ }
+
+ private void testSourceAPI(XMLFragment xmlFragment) throws Exception
+ {
+ assertEquals(xmlFragment.toStringFragment(), XML_STRING);
+
+ Element reparsed = xmlFragment.toElement();
+ assertEquals("parent", reparsed.getNodeName());
+ assertEquals("child", reparsed.getFirstChild().getNodeName());
+
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ PrintWriter writer = new PrintWriter( bout);
+ xmlFragment.writeTo(writer);
+ assertEquals(XML_STRING, new String(bout.toByteArray()));
+ }
+}