[jbossws-commits] JBossWS SVN: r2292 - in branches/jbossws-1.2.0/jbossws-core/src/main: java/org/jboss/ws/core/jaxrpc/binding and 5 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Wed Feb 7 05:20:03 EST 2007


Author: heiko.braun at jboss.com
Date: 2007-02-07 05:20:03 -0500 (Wed, 07 Feb 2007)
New Revision: 2292

Added:
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/BufferedStreamResult.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/DOMContent.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/ObjectContent.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContent.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentAccess.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLContent.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLFragment.java
Modified:
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/SOAPFaultHelperJAXRPC.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Deserializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Serializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarDeserializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarSerializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateDeserializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateSerializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DeserializerSupport.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementDeserializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementSerializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexDeserializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexSerializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBDeserializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBSerializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/NullValueSerializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameDeserializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameSerializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArrayDeserializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArraySerializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementDeserializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementSerializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SerializerSupport.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleDeserializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleSerializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBDeserializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBSerializer.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/ServiceEndpointDTO.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderStax.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentElement.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/utils/DOMUtils.java
   branches/jbossws-1.2.0/jbossws-core/src/main/resources/jbossws.war/index.html
Log:
Source and Result are used towards the binding layer. Cleaned up SOAPContentElement transitions. Introduced a BufferedStreamResult that can be used to represent XML_VALID state

Modified: branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/SOAPFaultHelperJAXRPC.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/SOAPFaultHelperJAXRPC.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/SOAPFaultHelperJAXRPC.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Deserializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Deserializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Deserializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Serializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Serializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/Base64Serializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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);
    }
 }

Copied: branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/BufferedStreamResult.java (from rev 2290, branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/BufferedStreamResult.java)
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/BufferedStreamResult.java	                        (rev 0)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/BufferedStreamResult.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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.ws.core.jaxrpc.binding;
+
+import javax.xml.transform.stream.StreamResult;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.io.Writer;
+
+/**
+ * @author Heiko.Braun at jboss.org
+ * @version $Id$
+ * @since 06.02.2007
+ */
+public class BufferedStreamResult extends StreamResult {
+
+   ByteArrayOutputStream bout = new ByteArrayOutputStream();
+
+   public BufferedStreamResult()
+   {
+      super();
+   }
+
+   public void setOutputStream(OutputStream outputStream)
+   {
+      throw new IllegalArgumentException("Operation not supported");
+   }
+
+   public OutputStream getOutputStream()
+   {
+      return bout;
+   }
+
+   public void setWriter(Writer writer)
+   {
+      throw new IllegalArgumentException("Operation not supported");
+   }
+
+   public Writer getWriter()
+   {
+     return null;
+   }
+}

Modified: branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarDeserializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarDeserializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarDeserializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarSerializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarSerializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/CalendarSerializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateDeserializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateDeserializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateDeserializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateSerializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateSerializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DateSerializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DeserializerSupport.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DeserializerSupport.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/DeserializerSupport.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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 at 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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementDeserializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementDeserializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementDeserializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementSerializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementSerializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/ElementSerializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexDeserializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexDeserializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexDeserializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexSerializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexSerializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/HexSerializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBDeserializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBDeserializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBDeserializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBSerializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBSerializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/JBossXBSerializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/NullValueSerializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/NullValueSerializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/NullValueSerializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameDeserializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameDeserializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameDeserializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameSerializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameSerializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/QNameSerializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArrayDeserializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArrayDeserializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArrayDeserializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArraySerializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArraySerializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPArraySerializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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,9 @@
          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 "+
+            "xmlns:"+Constants.PREFIX_SOAP11_ENC+"='http://schemas.xmlsoap.org/soap/encoding/' ");
+
          if (value instanceof Object[])
          {
             Object[] objArr = (Object[])value;
@@ -120,7 +124,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 +132,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 +167,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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementDeserializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementDeserializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementDeserializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementSerializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementSerializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SOAPElementSerializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SerializerSupport.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SerializerSupport.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SerializerSupport.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -23,17 +23,21 @@
 
 // $Id$
 
-import java.util.Set;
-
-import javax.xml.namespace.QName;
-import javax.xml.rpc.encoding.Serializer;
-
 import org.jboss.util.NotImplementedException;
 import org.jboss.ws.Constants;
+import org.jboss.ws.WSException;
+import org.jboss.ws.core.utils.IOUtils;
 import org.jboss.xb.binding.NamespaceRegistry;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 
+import javax.xml.namespace.QName;
+import javax.xml.rpc.encoding.Serializer;
+import javax.xml.transform.Result;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Set;
+
 /**
  * The base class for all Serializers.
  *
@@ -52,8 +56,21 @@
     * @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) {
+      BufferedStreamResult result = null;
+      try {
+         ByteArrayInputStream in = new ByteArrayInputStream(xmlFragment.getBytes());
+         result = new BufferedStreamResult();
+         IOUtils.copyStream(result.getOutputStream(), in);
+      } 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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleDeserializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleDeserializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleDeserializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleSerializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleSerializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxrpc/binding/SimpleSerializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBDeserializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBDeserializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBDeserializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBSerializer.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBSerializer.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/JAXBSerializer.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -24,6 +24,7 @@
 // $Id$
 
 import java.io.StringWriter;
+import java.io.ByteArrayOutputStream;
 import java.util.List;
 
 import javax.xml.bind.JAXBContext;
@@ -31,12 +32,17 @@
 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.stream.StreamResult;
+import javax.xml.transform.dom.DOMResult;
 
 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.ComplexTypeSerializer;
 import org.jboss.ws.core.jaxrpc.binding.SerializationContext;
+import org.jboss.ws.core.jaxrpc.binding.BufferedStreamResult;
 import org.jboss.ws.core.utils.JavaUtils;
 import org.jboss.ws.extensions.xop.jaxws.AttachmentMarshallerImpl;
 import org.w3c.dom.NamedNodeMap;
@@ -57,11 +63,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;
+      Result result = null;
       try
       {
          // It needs to be a valid JAXB type
@@ -76,17 +82,19 @@
          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();
+         // It's safe to pass a stream result, because the SCE will always be in XML_VALID state afterwards.
+         // This state can safely be written to an outstream. See XMLFragment and XMLContent as well.
+         result = new BufferedStreamResult();
+         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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/SOAPFaultHelperJAXWS.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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)

Modified: branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/ServiceEndpointDTO.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/ServiceEndpointDTO.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/ServiceEndpointDTO.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -25,7 +25,7 @@
 
 /**
  * @author Heiko.Braun at jboss.org
- * @version $Id:$
+ * @version $Id$
  * @since 02.02.2007
  */
 public class ServiceEndpointDTO {

Copied: branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/DOMContent.java (from rev 2290, branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/DOMContent.java)
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/DOMContent.java	                        (rev 0)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/DOMContent.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -0,0 +1,111 @@
+/*
+ * 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;
+
+/**
+ * Represents the DOM_VALID state of an {@link SOAPContentElement}.<br>
+ *
+ * @author Heiko.Braun at 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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderStax.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderStax.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderStax.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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
    {
 

Copied: branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/ObjectContent.java (from rev 2290, branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/ObjectContent.java)
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/ObjectContent.java	                        (rev 0)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/ObjectContent.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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.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;
+
+/**
+ * Represents the OBJECT_VALID state of an {@link SOAPContentElement}.<br>
+ *
+ * @author Heiko.Braun at 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;
+   }
+
+}

Copied: branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContent.java (from rev 2290, branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContent.java)
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContent.java	                        (rev 0)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContent.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+/**
+ * Represent SOAP message payload that can transition from
+ * one representation to the next.
+ *
+ * @see SOAPContentElement
+ * 
+ * @author Heiko.Braun at 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;
+   }
+
+}

Copied: branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentAccess.java (from rev 2290, branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentAccess.java)
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentAccess.java	                        (rev 0)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentAccess.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -0,0 +1,23 @@
+package org.jboss.ws.core.soap;
+
+import javax.xml.transform.Source;
+
+/**
+ * @author Heiko.Braun at 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/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentElement.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentElement.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentElement.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -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 at jboss.org
+ * @author Heiko.Braun at 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,104 @@
       return getParamMetaData().getJavaType();
    }
 
-   public boolean isDOMValid()
+   private void transitionTo(SOAPContent.State nextState)
    {
-      return isDOMValid;
-   }
+      if(nextState!=soapContent.getState())
+      {
+         log.debug("-----------------------------------");
+         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;
+         log.debug("-----------------------------------");
+      }
    }
-   
+
    /** 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 +237,6 @@
       log.trace("removeContents");
       expandToDOM();
       super.removeContents();
-      invalidateObjectContent();
-      invalidateXMLContent();
    }
 
    public Iterator getAllAttributes()
@@ -768,10 +437,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 +486,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 +520,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 +551,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 +566,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 +577,7 @@
       }
    }
 
-   private boolean isXOPParameter()
+   boolean isXOPParameter()
    {
       return paramMetaData != null && paramMetaData.isXOP();
    }

Copied: branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLContent.java (from rev 2290, branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLContent.java)
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLContent.java	                        (rev 0)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLContent.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -0,0 +1,325 @@
+/*
+ * 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;
+
+/**
+ * Represents the XML_VALID state of an {@link SOAPContentElement}.<br>
+ * Aggregates a {@link XMLFragment}.
+ *
+ * @author Heiko.Braun at 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");
+   }
+
+}

Copied: branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLFragment.java (from rev 2290, branches/hbraun/1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLFragment.java)
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLFragment.java	                        (rev 0)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/soap/XMLFragment.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -0,0 +1,258 @@
+/*
+ * 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.jaxrpc.binding.BufferedStreamResult;
+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.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamSource;
+import java.io.*;
+
+/**
+ * A XMLFragment represent either a XML {@link Source} or a {@link Result}.<br>
+ * The basic idea is that any {@link SOAPContentElement} XML_VALID state
+ * (either before unmarshalling or after marshalling) is represented through a single interface.<br>
+ *
+ * @see SOAPContentElement
+ * @see XMLContent
+ *
+ * @author Heiko.Braun at jboss.org
+ * @version $Id$
+ * @since 05.02.2007
+ */
+public class XMLFragment {
+
+   private Source source;
+   private Result result;
+
+   private boolean idempotent = true;
+
+   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;
+   }
+
+   public String toStringFragment()
+   {
+      if(!idempotent) throw new IllegalStateException("Trying to call a non-idempotent operation");
+
+      if(this.source != null)
+         return sourceToStringFragement(this.source);
+      else
+         return resultToStringFragment(this.result);
+   }
+
+   /**
+    * Note this method <b>is not expected to be idempotent</b>.
+    * It depends on the underlying source impl. that backs the implementation.
+    */
+   public Element toElement()
+   {
+      if(!idempotent) throw new IllegalStateException("Trying to call a non-idempotent operation");
+
+      Element resultingElement = null;
+
+      try
+      {
+         if(source != null)
+         {
+            resultingElement = DOMUtils.sourceToElement(source);
+
+            // Any Source besides DOMSource is expected not to be idempotent
+            if(! (source instanceof DOMSource) ) idempotent = false;
+
+         }
+         else
+         {
+            resultingElement = DOMUtils.parse( resultToStringFragment(result));
+
+            // Any Result besides DOMResult is expected not to be idempotent
+            if(! (result instanceof DOMResult) ) idempotent = false;
+         }
+      }
+      catch (IOException e)
+      {
+         WSException.rethrow("Failed to convert to org.w3c.dom.Element", e);
+      }
+
+      return resultingElement;
+   }
+
+   /**
+    * 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 String resultToStringFragment(Result result) {
+
+      if(result instanceof DOMResult)
+      {
+         return DOMWriter.printNode( ((DOMResult)result).getNode(), false);
+      }
+      else if (result instanceof BufferedStreamResult)
+      {
+         BufferedStreamResult br = (BufferedStreamResult)result;
+         byte[] bytes = ((ByteArrayOutputStream)br.getOutputStream()).toByteArray();
+         return new String(bytes);
+      }
+
+      throw new IllegalArgumentException("Unable to process javax.xml.transform.Result implementation: " + result);
+   }
+
+   private static String sourceToStringFragement(Source source) {
+
+      throw new IllegalArgumentException("Source should never be converted to String");
+
+      /*new RuntimeException("sourceToStringFragement").printStackTrace(System.out);
+
+      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);
+      }
+   }
+
+    /**
+    * Should only be called with <code>jbossws.SOAPMessage==TRACE</code>
+    */
+   private void writeSource(Writer writer) throws IOException {
+
+      //new RuntimeException("writeSource").printStackTrace(System.out);
+
+      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 if(result instanceof BufferedStreamResult)
+      {
+         BufferedStreamResult sr = (BufferedStreamResult)result;
+         ByteArrayOutputStream out = (ByteArrayOutputStream)sr.getOutputStream();
+         try
+         {
+            byte[] bytes = out.toByteArray();
+            writer.write(new String(bytes));
+         }
+         catch (IOException e)
+         {
+            throw new WSException("Failed to write XMLFragment to output stream", e);
+         }
+      }
+      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() {
+      String contents = source != null ? "source="+source : "result="+result;
+      return "XMLFragment {"+contents+", idempotent="+idempotent+"}";
+   }
+}

Modified: branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/utils/DOMUtils.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/utils/DOMUtils.java	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/utils/DOMUtils.java	2007-02-07 10:20:03 UTC (rev 2292)
@@ -23,9 +23,7 @@
 
 // $Id$
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -35,8 +33,15 @@
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.transform.stream.StreamResult;
 
 import org.jboss.logging.Logger;
+import org.jboss.ws.WSException;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -55,451 +60,518 @@
  */
 public final class DOMUtils
 {
-    private static Logger log = Logger.getLogger(DOMUtils.class);
+   private static Logger log = Logger.getLogger(DOMUtils.class);
 
-    // All elements created by the same thread are created by the same builder and belong to the same doc
-    private static ThreadLocal documentThreadLocal = new ThreadLocal();
-    private static ThreadLocal builderThreadLocal = new ThreadLocal() {
-        protected Object initialValue() {
-            try
-            {
-                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-                factory.setValidating(false);
-                factory.setNamespaceAware(true);
-                DocumentBuilder builder = factory.newDocumentBuilder();
-                builder.setEntityResolver(new JBossWSEntityResolver());
-                return builder;
-            }
-            catch (ParserConfigurationException e)
-            {
-                throw new RuntimeException("Failed to create DocumentBuilder", e);
-            }
-        }
-    };
+   // All elements created by the same thread are created by the same builder and belong to the same doc
+   private static ThreadLocal documentThreadLocal = new ThreadLocal();
+   private static ThreadLocal builderThreadLocal = new ThreadLocal() {
+      protected Object initialValue() {
+         try
+         {
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+            factory.setValidating(false);
+            factory.setNamespaceAware(true);
+            DocumentBuilder builder = factory.newDocumentBuilder();
+            builder.setEntityResolver(new JBossWSEntityResolver());
+            return builder;
+         }
+         catch (ParserConfigurationException e)
+         {
+            throw new RuntimeException("Failed to create DocumentBuilder", e);
+         }
+      }
+   };
 
-    // Hide the constructor
-    private DOMUtils()
-    {
-    }
+   // Hide the constructor
+   private DOMUtils()
+   {
+   }
 
-    /** Initialise the the DocumentBuilder
-     */
-    public static DocumentBuilder getDocumentBuilder()
-    {
-        DocumentBuilder builder = (DocumentBuilder)builderThreadLocal.get();
-        return builder;
-    }
+   /** Initialise the the DocumentBuilder
+    */
+   public static DocumentBuilder getDocumentBuilder()
+   {
+      DocumentBuilder builder = (DocumentBuilder)builderThreadLocal.get();
+      return builder;
+   }
 
-    /** Parse the given XML string and return the root Element
-     */
-    public static Element parse(String xmlString) throws IOException
-    {
-        try
-        {
-            return parse(new ByteArrayInputStream(xmlString.getBytes("UTF-8")));
-        }
-        catch (IOException e)
-        {
-            log.error("Cannot parse: " + xmlString);
-            throw e;
-        }
-    }
+   /** Parse the given XML string and return the root Element
+    */
+   public static Element parse(String xmlString) throws IOException
+   {
+      try
+      {
+         return parse(new ByteArrayInputStream(xmlString.getBytes("UTF-8")));
+      }
+      catch (IOException e)
+      {
+         log.error("Cannot parse: " + xmlString);
+         throw e;
+      }
+   }
 
-    /** Parse the given XML stream and return the root Element
-     */
-    public static Element parse(InputStream xmlStream) throws IOException
-    {
-        try
-        {
-            Document doc = getDocumentBuilder().parse(xmlStream);
-            Element root = doc.getDocumentElement();
-            return root;
-        }
-        catch (SAXException e)
-        {
-            throw new IOException(e.toString());
-        }
-    }
+   /** Parse the given XML stream and return the root Element
+    */
+   public static Element parse(InputStream xmlStream) throws IOException
+   {
+      try
+      {
+         Document doc = getDocumentBuilder().parse(xmlStream);
+         Element root = doc.getDocumentElement();
+         return root;
+      }
+      catch (SAXException e)
+      {
+         throw new IOException(e.toString());
+      }
+   }
 
-    /** Parse the given input source and return the root Element
-     */
-    public static Element parse(InputSource source) throws IOException
-    {
-        try
-        {
-            Document doc = getDocumentBuilder().parse(source);
-            Element root = doc.getDocumentElement();
-            return root;
-        }
-        catch (SAXException e)
-        {
-            throw new IOException(e.toString());
-        }
-    }
+   /** Parse the given input source and return the root Element
+    */
+   public static Element parse(InputSource source) throws IOException
+   {
+      try
+      {
+         Document doc = getDocumentBuilder().parse(source);
+         Element root = doc.getDocumentElement();
+         return root;
+      }
+      catch (SAXException e)
+      {
+         throw new IOException(e.toString());
+      }
+   }
 
-    /** Create an Element for a given name
-     */
-    public static Element createElement(String localPart)
-    {
-        Document doc = getOwnerDocument();
-        log.trace("createElement {}" + localPart);
-        return doc.createElement(localPart);
-    }
+   /** Create an Element for a given name
+    */
+   public static Element createElement(String localPart)
+   {
+      Document doc = getOwnerDocument();
+      log.trace("createElement {}" + localPart);
+      return doc.createElement(localPart);
+   }
 
-    /** Create an Element for a given name and prefix
-     */
-    public static Element createElement(String localPart, String prefix)
-    {
-        Document doc = getOwnerDocument();
-        log.trace("createElement {}" + prefix + ":" + localPart);
-        return doc.createElement(prefix + ":" + localPart);
-    }
+   /** Create an Element for a given name and prefix
+    */
+   public static Element createElement(String localPart, String prefix)
+   {
+      Document doc = getOwnerDocument();
+      log.trace("createElement {}" + prefix + ":" + localPart);
+      return doc.createElement(prefix + ":" + localPart);
+   }
 
-    /** Create an Element for a given name, prefix and uri
-     */
-    public static Element createElement(String localPart, String prefix, String uri)
-    {
-        Document doc = getOwnerDocument();
-        if (prefix == null || prefix.length() == 0)
-        {
-            log.trace("createElement {" + uri + "}" + localPart);
-            return doc.createElementNS(uri, localPart);
-        }
-        else
-        {
-            log.trace("createElement {" + uri + "}" + prefix + ":" + localPart);
-            return doc.createElementNS(uri, prefix + ":" + localPart);
-        }
-    }
+   /** Create an Element for a given name, prefix and uri
+    */
+   public static Element createElement(String localPart, String prefix, String uri)
+   {
+      Document doc = getOwnerDocument();
+      if (prefix == null || prefix.length() == 0)
+      {
+         log.trace("createElement {" + uri + "}" + localPart);
+         return doc.createElementNS(uri, localPart);
+      }
+      else
+      {
+         log.trace("createElement {" + uri + "}" + prefix + ":" + localPart);
+         return doc.createElementNS(uri, prefix + ":" + localPart);
+      }
+   }
 
-    /** Create an Element for a given QName
-     */
-    public static Element createElement(QName qname)
-    {
-        return createElement(qname.getLocalPart(), qname.getPrefix(), qname.getNamespaceURI());
-    }
+   /** Create an Element for a given QName
+    */
+   public static Element createElement(QName qname)
+   {
+      return createElement(qname.getLocalPart(), qname.getPrefix(), qname.getNamespaceURI());
+   }
 
-    /** Create a org.w3c.dom.Text node
-     */
-    public static Text createTextNode(String value)
-    {
-        Document doc = getOwnerDocument();
-        return doc.createTextNode(value);
-    }
+   /** Create a org.w3c.dom.Text node
+    */
+   public static Text createTextNode(String value)
+   {
+      Document doc = getOwnerDocument();
+      return doc.createTextNode(value);
+   }
 
-    /** Get the qname of the given node.
-     */
-    public static QName getElementQName(Element el)
-    {
-        String qualifiedName = el.getNodeName();
-        return resolveQName(el, qualifiedName);
-    }
+   /** Get the qname of the given node.
+    */
+   public static QName getElementQName(Element el)
+   {
+      String qualifiedName = el.getNodeName();
+      return resolveQName(el, qualifiedName);
+   }
 
-    /** Transform the giveen qualified name into a QName
-     */
-    public static QName resolveQName(Element el, String qualifiedName)
-    {
-        QName qname;
-        String prefix = "";
-        String namespaceURI = "";
-        String localPart = qualifiedName;
+   /** Transform the giveen qualified name into a QName
+    */
+   public static QName resolveQName(Element el, String qualifiedName)
+   {
+      QName qname;
+      String prefix = "";
+      String namespaceURI = "";
+      String localPart = qualifiedName;
 
-        int colIndex = qualifiedName.indexOf(":");
-        if (colIndex > 0)
-        {
-            prefix = qualifiedName.substring(0, colIndex);
-            localPart = qualifiedName.substring(colIndex + 1);
+      int colIndex = qualifiedName.indexOf(":");
+      if (colIndex > 0)
+      {
+         prefix = qualifiedName.substring(0, colIndex);
+         localPart = qualifiedName.substring(colIndex + 1);
 
-            if ("xmlns".equals(prefix))
+         if ("xmlns".equals(prefix))
+         {
+            namespaceURI = "URI:XML_PREDEFINED_NAMESPACE";
+         }
+         else
+         {
+            Element nsElement = el;
+            while (namespaceURI.equals("") && nsElement != null)
             {
-                namespaceURI = "URI:XML_PREDEFINED_NAMESPACE";
+               namespaceURI = nsElement.getAttribute("xmlns:" + prefix);
+               if (namespaceURI.equals(""))
+                  nsElement = getParentElement(nsElement);
             }
-            else
-            {
-                Element nsElement = el;
-                while (namespaceURI.equals("") && nsElement != null)
-                {
-                    namespaceURI = nsElement.getAttribute("xmlns:" + prefix);
-                    if (namespaceURI.equals(""))
-                        nsElement = getParentElement(nsElement);
-                }
-            }
+         }
 
-            if (namespaceURI.equals(""))
-                throw new IllegalArgumentException("Cannot find namespace uri for: " + qualifiedName);
-        }
+         if (namespaceURI.equals(""))
+            throw new IllegalArgumentException("Cannot find namespace uri for: " + qualifiedName);
+      }
 
-        qname = new QName(namespaceURI, localPart, prefix);
-        return qname;
-    }
+      qname = new QName(namespaceURI, localPart, prefix);
+      return qname;
+   }
 
-    /** Get the value from the given attribute
-     *
-     * @return null if the attribute value is empty or the attribute is not present
-     */
-    public static String getAttributeValue(Element el, String attrName)
-    {
-        return getAttributeValue(el, new QName(attrName));
-    }
+   /** Get the value from the given attribute
+    *
+    * @return null if the attribute value is empty or the attribute is not present
+    */
+   public static String getAttributeValue(Element el, String attrName)
+   {
+      return getAttributeValue(el, new QName(attrName));
+   }
 
-    /** Get the value from the given attribute
-     *
-     * @return null if the attribute value is empty or the attribute is not present
-     */
-    public static String getAttributeValue(Element el, QName attrName)
-    {
-        String attr = null;
-        if ("".equals(attrName.getNamespaceURI()))
-            attr = el.getAttribute(attrName.getLocalPart());
-        else attr = el.getAttributeNS(attrName.getNamespaceURI(), attrName.getLocalPart());
+   /** Get the value from the given attribute
+    *
+    * @return null if the attribute value is empty or the attribute is not present
+    */
+   public static String getAttributeValue(Element el, QName attrName)
+   {
+      String attr = null;
+      if ("".equals(attrName.getNamespaceURI()))
+         attr = el.getAttribute(attrName.getLocalPart());
+      else attr = el.getAttributeNS(attrName.getNamespaceURI(), attrName.getLocalPart());
 
-        if ("".equals(attr))
-            attr = null;
+      if ("".equals(attr))
+         attr = null;
 
-        return attr;
-    }
+      return attr;
+   }
 
-    /** Get the qname value from the given attribute
-     */
-    public static QName getAttributeValueAsQName(Element el, String attrName)
-    {
-        return getAttributeValueAsQName(el, new QName(attrName));
+   /** Get the qname value from the given attribute
+    */
+   public static QName getAttributeValueAsQName(Element el, String attrName)
+   {
+      return getAttributeValueAsQName(el, new QName(attrName));
 
-    }
+   }
 
-    /** Get the qname value from the given attribute
-     */
-    public static QName getAttributeValueAsQName(Element el, QName attrName)
-    {
-        QName qname = null;
+   /** Get the qname value from the given attribute
+    */
+   public static QName getAttributeValueAsQName(Element el, QName attrName)
+   {
+      QName qname = null;
 
-        String qualifiedName = getAttributeValue(el, attrName);
-        if (qualifiedName != null)
-        {
-            qname = resolveQName(el, qualifiedName);
-        }
+      String qualifiedName = getAttributeValue(el, attrName);
+      if (qualifiedName != null)
+      {
+         qname = resolveQName(el, qualifiedName);
+      }
 
-        return qname;
-    }
+      return qname;
+   }
 
-    /** Get the boolean value from the given attribute
-     */
-    public static boolean getAttributeValueAsBoolean(Element el, String attrName)
-    {
-        return getAttributeValueAsBoolean(el, new QName(attrName));
-    }
+   /** Get the boolean value from the given attribute
+    */
+   public static boolean getAttributeValueAsBoolean(Element el, String attrName)
+   {
+      return getAttributeValueAsBoolean(el, new QName(attrName));
+   }
 
-    /** Get the boolean value from the given attribute
-     */
-    public static boolean getAttributeValueAsBoolean(Element el, QName attrName)
-    {
-        String attrVal = getAttributeValue(el, attrName);
-        boolean ret = "true".equalsIgnoreCase(attrVal) || "1".equalsIgnoreCase(attrVal);
-        return ret;
-    }
+   /** Get the boolean value from the given attribute
+    */
+   public static boolean getAttributeValueAsBoolean(Element el, QName attrName)
+   {
+      String attrVal = getAttributeValue(el, attrName);
+      boolean ret = "true".equalsIgnoreCase(attrVal) || "1".equalsIgnoreCase(attrVal);
+      return ret;
+   }
 
-    /** Get the integer value from the given attribute
-     */
-    public static Integer getAttributeValueAsInteger(Element el, String attrName)
-    {
-        return getAttributeValueAsInteger(el, new QName(attrName));
-    }
+   /** Get the integer value from the given attribute
+    */
+   public static Integer getAttributeValueAsInteger(Element el, String attrName)
+   {
+      return getAttributeValueAsInteger(el, new QName(attrName));
+   }
 
-    /** Get the integer value from the given attribute
-     */
-    public static Integer getAttributeValueAsInteger(Element el, QName attrName)
-    {
-        String attrVal = getAttributeValue(el, attrName);
-        return (attrVal != null ? new Integer(attrVal) : null);
-    }
+   /** Get the integer value from the given attribute
+    */
+   public static Integer getAttributeValueAsInteger(Element el, QName attrName)
+   {
+      String attrVal = getAttributeValue(el, attrName);
+      return (attrVal != null ? new Integer(attrVal) : null);
+   }
 
-    /** Get the attributes as Map<QName, String>
-     */
-    public static Map getAttributes(Element el)
-    {
-        Map attmap = new HashMap();
-        NamedNodeMap attribs = el.getAttributes();
-        for (int i = 0; i < attribs.getLength(); i++)
-        {
-            Attr attr = (Attr)attribs.item(i);
-            String name = attr.getName();
-            QName qname = resolveQName(el, name);
-            String value = attr.getNodeValue();
-            attmap.put(qname, value);
-        }
-        return attmap;
-    }
+   /** Get the attributes as Map<QName, String>
+    */
+   public static Map getAttributes(Element el)
+   {
+      Map attmap = new HashMap();
+      NamedNodeMap attribs = el.getAttributes();
+      for (int i = 0; i < attribs.getLength(); i++)
+      {
+         Attr attr = (Attr)attribs.item(i);
+         String name = attr.getName();
+         QName qname = resolveQName(el, name);
+         String value = attr.getNodeValue();
+         attmap.put(qname, value);
+      }
+      return attmap;
+   }
 
-    /** Copy attributes between elements
-     */
-    public static void copyAttributes(Element destElement, Element srcElement)
-    {
-        NamedNodeMap attribs = srcElement.getAttributes();
-        for (int i = 0; i < attribs.getLength(); i++)
-        {
-            Attr attr = (Attr)attribs.item(i);
-            String uri = attr.getNamespaceURI();
-            String qname = attr.getName();
-            String value = attr.getNodeValue();
-            
-            // Prevent DOMException: NAMESPACE_ERR: An attempt is made to create or 
-            // change an object in a way which is incorrect with regard to namespaces.
-            if (uri == null && qname.startsWith("xmlns"))
+   /** Copy attributes between elements
+    */
+   public static void copyAttributes(Element destElement, Element srcElement)
+   {
+      NamedNodeMap attribs = srcElement.getAttributes();
+      for (int i = 0; i < attribs.getLength(); i++)
+      {
+         Attr attr = (Attr)attribs.item(i);
+         String uri = attr.getNamespaceURI();
+         String qname = attr.getName();
+         String value = attr.getNodeValue();
+
+         // Prevent DOMException: NAMESPACE_ERR: An attempt is made to create or
+         // change an object in a way which is incorrect with regard to namespaces.
+         if (uri == null && qname.startsWith("xmlns"))
+         {
+            log.trace("Ignore attribute: [uri=" + uri + ",qname=" + qname + ",value=" + value + "]");
+         }
+         else
+         {
+            destElement.setAttributeNS(uri, qname, value);
+         }
+      }
+   }
+
+   /** True if the node has child elements
+    */
+   public static boolean hasChildElements(Node node)
+   {
+      NodeList nlist = node.getChildNodes();
+      for (int i = 0; i < nlist.getLength(); i++)
+      {
+         Node child = nlist.item(i);
+         if (child.getNodeType() == Node.ELEMENT_NODE)
+            return true;
+      }
+      return false;
+   }
+
+   /** Gets child elements
+    */
+   public static Iterator getChildElements(Node node)
+   {
+      ArrayList list = new ArrayList();
+      NodeList nlist = node.getChildNodes();
+      for (int i = 0; i < nlist.getLength(); i++)
+      {
+         Node child = nlist.item(i);
+         if (child.getNodeType() == Node.ELEMENT_NODE)
+            list.add(child);
+      }
+      return list.iterator();
+   }
+
+   /** Get the concatenated text content, or null.
+    */
+   public static String getTextContent(Node node)
+   {
+      boolean hasTextContent = false;
+      StringBuffer buffer = new StringBuffer();
+      NodeList nlist = node.getChildNodes();
+      for (int i = 0; i < nlist.getLength(); i++)
+      {
+         Node child = nlist.item(i);
+         if (child.getNodeType() == Node.TEXT_NODE)
+         {
+            buffer.append(child.getNodeValue());
+            hasTextContent = true;
+         }
+      }
+      return (hasTextContent ? buffer.toString() : null);
+   }
+
+   /** Gets the first child element
+    */
+   public static Element getFirstChildElement(Node node)
+   {
+      return getFirstChildElementIntern(node, null);
+   }
+
+   /** Gets the first child element for a given local name without namespace
+    */
+   public static Element getFirstChildElement(Node node, String nodeName)
+   {
+      return getFirstChildElementIntern(node, new QName(nodeName));
+   }
+
+   /** Gets the first child element for a given qname
+    */
+   public static Element getFirstChildElement(Node node, QName nodeName)
+   {
+      return getFirstChildElementIntern(node, nodeName);
+   }
+
+   private static Element getFirstChildElementIntern(Node node, QName nodeName)
+   {
+      Element childElement = null;
+      Iterator it = getChildElementsIntern(node, nodeName);
+      if (it.hasNext())
+      {
+         childElement = (Element)it.next();
+      }
+      return childElement;
+   }
+
+   /** Gets the child elements for a given local name without namespace
+    */
+   public static Iterator getChildElements(Node node, String nodeName)
+   {
+      return getChildElementsIntern(node, new QName(nodeName));
+   }
+
+   /** Gets the child element for a given qname
+    */
+   public static Iterator getChildElements(Node node, QName nodeName)
+   {
+      return getChildElementsIntern(node, nodeName);
+   }
+
+   private static Iterator getChildElementsIntern(Node node, QName nodeName)
+   {
+      ArrayList list = new ArrayList();
+      NodeList nlist = node.getChildNodes();
+      for (int i = 0; i < nlist.getLength(); i++)
+      {
+         Node child = nlist.item(i);
+         if (child.getNodeType() == Node.ELEMENT_NODE)
+         {
+            if (nodeName == null)
             {
-               log.trace("Ignore attribute: [uri=" + uri + ",qname=" + qname + ",value=" + value + "]");
+               list.add(child);
             }
             else
             {
-               destElement.setAttributeNS(uri, qname, value);
+               QName qname;
+               if (nodeName.getNamespaceURI().length() > 0)
+               {
+                  qname = new QName(child.getNamespaceURI(), child.getLocalName());
+               }
+               else
+               {
+                  qname = new QName(child.getLocalName());
+               }
+               if (qname.equals(nodeName))
+               {
+                  list.add(child);
+               }
             }
-        }
-    }
+         }
+      }
+      return list.iterator();
+   }
 
-    /** True if the node has child elements
-     */
-    public static boolean hasChildElements(Node node)
-    {
-        NodeList nlist = node.getChildNodes();
-        for (int i = 0; i < nlist.getLength(); i++)
-        {
-            Node child = nlist.item(i);
-            if (child.getNodeType() == Node.ELEMENT_NODE)
-                return true;
-        }
-        return false;
-    }
+   /** Gets parent element or null if there is none
+    */
+   public static Element getParentElement(Node node)
+   {
+      Node parent = node.getParentNode();
+      return (parent instanceof Element ? (Element)parent : null);
+   }
 
-    /** Gets child elements
-     */
-    public static Iterator getChildElements(Node node)
-    {
-        ArrayList list = new ArrayList();
-        NodeList nlist = node.getChildNodes();
-        for (int i = 0; i < nlist.getLength(); i++)
-        {
-            Node child = nlist.item(i);
-            if (child.getNodeType() == Node.ELEMENT_NODE)
-                list.add(child);
-        }
-        return list.iterator();
-    }
+   /** Get the owner document that is associated with the current thread */
+   public static Document getOwnerDocument()
+   {
+      Document doc = (Document)documentThreadLocal.get();
+      if (doc == null)
+      {
+         doc = getDocumentBuilder().newDocument();
+         documentThreadLocal.set(doc);
+      }
+      return doc;
+   }
 
-    /** Get the concatenated text content, or null.
-     */
-    public static String getTextContent(Node node)
-    {
-        boolean hasTextContent = false;
-        StringBuffer buffer = new StringBuffer();
-        NodeList nlist = node.getChildNodes();
-        for (int i = 0; i < nlist.getLength(); i++)
-        {
-            Node child = nlist.item(i);
-            if (child.getNodeType() == Node.TEXT_NODE)
+   public static Element sourceToElement(Source source)
+   {
+      Element elementResult = null;
+
+      try {
+         if (source instanceof StreamSource)
+         {
+            StreamSource streamSource = (StreamSource)source;
+
+            InputStream ins = streamSource.getInputStream();
+            if (ins != null)
             {
-                buffer.append(child.getNodeValue());
-                hasTextContent = true;
+               elementResult = DOMUtils.parse(ins);
             }
-        }
-        return (hasTextContent ? buffer.toString() : null);
-    }
+            else
+            {
+               Reader reader = streamSource.getReader();
+               elementResult = DOMUtils.parse(new InputSource(reader));
+            }
 
-    /** Gets the first child element
-     */
-    public static Element getFirstChildElement(Node node)
-    {
-        return getFirstChildElementIntern(node, null);
-    }
+            // reset the excausted input stream
+            String xmlStr = DOMWriter.printNode(elementResult, false);
+            source = new StreamSource(new ByteArrayInputStream(xmlStr.getBytes()));
+         }
+         else if (source instanceof DOMSource)
+         {
+            DOMSource domSource = (DOMSource)source;
+            Node node = domSource.getNode();
+            if (node instanceof Element)
+            {
+               elementResult = (Element)node;
+            }
+            else if (node instanceof Document)
+            {
+               elementResult = ((Document)node).getDocumentElement();
+            }
+            else
+            {
+               throw new WSException("Unsupported Node type: " + node.getClass().getName());
+            }
+         }
+         else if (source instanceof SAXSource)
+         {
+            // The fact that JAXBSource derives from SAXSource is an implementation detail.
+            // Thus in general applications are strongly discouraged from accessing methods defined on SAXSource.
+            // The XMLReader object obtained by the getXMLReader method shall be used only for parsing the InputSource object returned by the getInputSource method.
 
-    /** Gets the first child element for a given local name without namespace
-     */
-    public static Element getFirstChildElement(Node node, String nodeName)
-    {
-        return getFirstChildElementIntern(node, new QName(nodeName));
-    }
+            TransformerFactory tf = TransformerFactory.newInstance();
+            ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+            tf.newTransformer().transform(source, new StreamResult(baos));
 
-    /** Gets the first child element for a given qname
-     */
-    public static Element getFirstChildElement(Node node, QName nodeName)
-    {
-        return getFirstChildElementIntern(node, nodeName);
-    }
+            elementResult = DOMUtils.parse(new ByteArrayInputStream(baos.toByteArray()));
+         }
+         else
+         {
+            throw new WSException("Source type not implemented: " + source.getClass().getName());
+         }
 
-    private static Element getFirstChildElementIntern(Node node, QName nodeName)
-    {
-        Element childElement = null;
-        Iterator it = getChildElementsIntern(node, nodeName);
-        if (it.hasNext())
-        {
-            childElement = (Element)it.next();
-        }
-        return childElement;
-    }
+      }
+      catch (Exception e)
+      {
+         WSException.rethrow(e);
+      }
 
-    /** Gets the child elements for a given local name without namespace
-     */
-    public static Iterator getChildElements(Node node, String nodeName)
-    {
-        return getChildElementsIntern(node, new QName(nodeName));
-    }
-
-    /** Gets the child element for a given qname
-     */
-    public static Iterator getChildElements(Node node, QName nodeName)
-    {
-        return getChildElementsIntern(node, nodeName);
-    }
-
-    private static Iterator getChildElementsIntern(Node node, QName nodeName)
-    {
-        ArrayList list = new ArrayList();
-        NodeList nlist = node.getChildNodes();
-        for (int i = 0; i < nlist.getLength(); i++)
-        {
-            Node child = nlist.item(i);
-            if (child.getNodeType() == Node.ELEMENT_NODE)
-            {
-                if (nodeName == null)
-                {
-                    list.add(child);
-                }
-                else
-                {
-                    QName qname;
-                    if (nodeName.getNamespaceURI().length() > 0)
-                    {
-                        qname = new QName(child.getNamespaceURI(), child.getLocalName());
-                    }
-                    else
-                    {
-                        qname = new QName(child.getLocalName());
-                    }
-                    if (qname.equals(nodeName))
-                    {
-                        list.add(child);
-                    }
-                }
-            }
-        }
-        return list.iterator();
-    }
-
-    /** Gets parent element or null if there is none
-     */
-    public static Element getParentElement(Node node)
-    {
-        Node parent = node.getParentNode();
-        return (parent instanceof Element ? (Element)parent : null);
-    }
-
-    /** Get the owner document that is associated with the current thread */
-    public static Document getOwnerDocument()
-    {
-        Document doc = (Document)documentThreadLocal.get();
-        if (doc == null)
-        {
-            doc = getDocumentBuilder().newDocument();
-            documentThreadLocal.set(doc);
-        }
-        return doc;
-    }
+      return elementResult;
+   }
 }

Modified: branches/jbossws-1.2.0/jbossws-core/src/main/resources/jbossws.war/index.html
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/resources/jbossws.war/index.html	2007-02-07 10:19:29 UTC (rev 2291)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/resources/jbossws.war/index.html	2007-02-07 10:20:03 UTC (rev 2292)
@@ -9,7 +9,7 @@
 
 <div class="pageSection">
 <h2>J2EE compatible web services</h2>
-After JBoss J2EE-1.4 certification in Jun/2004 we have decided to develop our own JAX-RPC 1.1 / JAX-WS compliant SOAP stack that fits better in the overall JBoss architecture and is generally more suiteable for the specific J2EE requirements for web services.
+JBossWS is a JAX-WS compliant web service stack developed to be part of JBoss' JavaEE5 offering.
 </div>
 
 <div class="pageSection">
@@ -60,4 +60,4 @@
 </div>
 
 </body>
-</html>
\ No newline at end of file
+</html>




More information about the jbossws-commits mailing list