[jboss-svn-commits] JBL Code SVN: r31341 - in labs/jbossesb/branches/JBESB_4_7_CP/product: lib/ext and 6 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Feb 1 11:54:25 EST 2010


Author: kevin.conner at jboss.com
Date: 2010-02-01 11:54:25 -0500 (Mon, 01 Feb 2010)
New Revision: 31341

Added:
   labs/jbossesb/branches/JBESB_4_7_CP/product/lib/ext/wstx-asl-3.2.8.jar
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/wstx/
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/wstx/ESBDOMWrappingReader.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/wstx/ESBDOMWrappingWriter.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/copy_source.xml
Modified:
   labs/jbossesb/branches/JBESB_4_7_CP/product/build-distr.xml
   labs/jbossesb/branches/JBESB_4_7_CP/product/ivy.xml
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/XMLHelper.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/BaseWebService.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/XMLHelperUnitTest.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/soa/esb/testutils/jbr/StaticRequestResponseHandler.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java
Log:
Move BaseWebService and SoapUIClientService to StAX: JBESB-3160

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/build-distr.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/build-distr.xml	2010-02-01 16:39:20 UTC (rev 31340)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/build-distr.xml	2010-02-01 16:54:25 UTC (rev 31341)
@@ -105,7 +105,7 @@
             <!-- XStream jars -->
             <fileset dir="${lib.dir}" includes="xstream-*.jar"/>
             <!-- woodstox for the StaxDriver -->
-            <fileset dir="${lib.dir}" includes="wstx-*.jar"/>
+            <fileset dir="${lib.ext.dir}" includes="wstx-*.jar"/>
         	<!-- MVEL -->
         	<fileset dir="${lib.dir}" includes="mvel*.jar"/>
             <!-- Quartz -->

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/ivy.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/ivy.xml	2010-02-01 16:39:20 UTC (rev 31340)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/ivy.xml	2010-02-01 16:54:25 UTC (rev 31341)
@@ -61,7 +61,9 @@
 
         <dependency org="xml-apis" name="xml-apis" rev="1.3.02"/>
         <dependency org="xmlbeans" name="xbean" rev="2.2.0"/>
-        <dependency org="com.thoughtworks.xstream" name="xstream" rev="1.2.2"/>
+        <dependency org="com.thoughtworks.xstream" name="xstream" rev="1.2.2">
+            <exclude org="org.codehaus.woodstox" module="wstx-asl"/>
+        </dependency>
         <dependency org="apache-bsf" name="bsf" rev="2.3.0"/>
         <dependency org="beanshell" name="bsh" rev="1.3.0"/>
 

Added: labs/jbossesb/branches/JBESB_4_7_CP/product/lib/ext/wstx-asl-3.2.8.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/branches/JBESB_4_7_CP/product/lib/ext/wstx-asl-3.2.8.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/XMLHelper.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/XMLHelper.java	2010-02-01 16:39:20 UTC (rev 31340)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/XMLHelper.java	2010-02-01 16:54:25 UTC (rev 31341)
@@ -33,15 +33,24 @@
 import java.net.URL;
 
 import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.events.XMLEvent;
+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 javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
@@ -50,12 +59,19 @@
 import org.apache.log4j.Logger;
 import org.jboss.internal.soa.esb.util.stax.ParsingSupport;
 import org.jboss.internal.soa.esb.util.stax.StreamHelper;
+import org.jboss.internal.soa.esb.util.wstx.ESBDOMWrappingReader;
+import org.jboss.internal.soa.esb.util.wstx.ESBDOMWrappingWriter;
 import org.jboss.soa.esb.util.ClassUtil;
 import org.jboss.util.StringPropertyReplacer;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
 import org.w3c.dom.ls.LSResourceResolver;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
+import com.ctc.wstx.stax.WstxInputFactory;
+import com.ctc.wstx.stax.WstxOutputFactory;
+
 /**
  * Helper class for manipulating XML documents.
  * 
@@ -68,13 +84,25 @@
     /**
      * The XML input factory.
      */
-    private static final XMLInputFactory XML_INPUT_FACTORY = getXMLInputFactory() ;
+    private static final XMLInputFactory XML_INPUT_FACTORY  ;
     /**
      * The XML output factory.
      */
-    private static final XMLOutputFactory XML_OUTPUT_FACTORY = XMLOutputFactory.newInstance() ;
-
+    private static final XMLOutputFactory XML_OUTPUT_FACTORY ;
     /**
+     * The Document builder factory.
+     */
+    private static final DocumentBuilderFactory DOCUMENT_BUILDER_FACTORY ;
+    /**
+     * The event writer creator for DOM documents.
+     */
+    private static final EventWriterCreator EVENT_WRITER_CREATOR ;
+    /**
+     * The event reader creator for DOM nodes.
+     */
+    private static final EventReaderCreator EVENT_READER_CREATOR ;
+    
+    /**
      * Get the XML stream reader.
      * @param reader The input reader.
      * @return The XML stream reader.
@@ -112,6 +140,67 @@
     }
 
     /**
+     * Get the XML stream reader.
+     * @param source The source.
+     * @return The XML stream reader.
+     * @throws XMLStreamException For errors obtaining an XML stream reader.
+     */
+    public static XMLStreamReader getXMLStreamReader(final Source source)
+        throws XMLStreamException
+    {
+        return XML_INPUT_FACTORY.createXMLStreamReader(source) ;
+    }
+
+    /**
+     * Get the XML event reader.
+     * @param reader The input reader.
+     * @return The XML event reader.
+     * @throws XMLStreamException For errors obtaining an XML event reader.
+     */
+    public static XMLEventReader getXMLEventReader(final Reader reader)
+        throws XMLStreamException
+    {
+        return XML_INPUT_FACTORY.createXMLEventReader(reader) ;
+    }
+
+    /**
+     * Get the XML event reader.
+     * @param is The input stream.
+     * @return The XML event reader.
+     * @throws XMLStreamException For errors obtaining an XML event reader.
+     */
+    public static XMLEventReader getXMLEventReader(final InputStream is)
+        throws XMLStreamException
+    {
+        return XML_INPUT_FACTORY.createXMLEventReader(is) ;
+    }
+
+    /**
+     * Get the XML event reader.
+     * @param is The input stream.
+     * @param encoding The input stream encoding.
+     * @return The XML event reader.
+     * @throws XMLStreamException For errors obtaining an XML event reader.
+     */
+    public static XMLEventReader getXMLEventReader(final InputStream is, final String encoding)
+        throws XMLStreamException
+    {
+        return XML_INPUT_FACTORY.createXMLEventReader(is, encoding) ;
+    }
+
+    /**
+     * Get the XML event reader.
+     * @param source The source.
+     * @return The XML event reader.
+     * @throws XMLStreamException For errors obtaining an XML event reader.
+     */
+    public static XMLEventReader getXMLEventReader(final Source source)
+        throws XMLStreamException
+    {
+        return XML_INPUT_FACTORY.createXMLEventReader(source) ;
+    }
+
+    /**
      * Get the XML stream writer.
      * @param writer The output writer.
      * @return The XML stream writer.
@@ -147,8 +236,111 @@
     {
         return XML_OUTPUT_FACTORY.createXMLStreamWriter(os, encoding) ;
     }
+
+    /**
+     * Get the XML stream writer.
+     * @param result The output result.
+     * @return The XML stream writer.
+     * @throws XMLStreamException For errors obtaining an XML stream writer.
+     */
+    public static XMLStreamWriter getXMLStreamWriter(final Result result)
+        throws XMLStreamException
+    {
+        return XML_OUTPUT_FACTORY.createXMLStreamWriter(result) ;
+    }
+
+    /**
+     * Get the XML event writer.
+     * @param writer The output writer.
+     * @return The XML event writer.
+     * @throws XMLStreamException For errors obtaining an XML event writer.
+     */
+    public static XMLEventWriter getXMLEventWriter(final Writer writer)
+        throws XMLStreamException
+    {
+        return XML_OUTPUT_FACTORY.createXMLEventWriter(writer) ;
+    }
+
+    /**
+     * Get the XML event writer.
+     * @param os The output stream.
+     * @return The XML event writer.
+     * @throws XMLStreamException For errors obtaining an XML event writer.
+     */
+    public static XMLEventWriter getXMLEventWriter(final OutputStream os)
+        throws XMLStreamException
+    {
+        return XML_OUTPUT_FACTORY.createXMLEventWriter(os) ;
+    }
+
+    /**
+     * Get the XML event writer.
+     * @param os The output stream.
+     * @param encoding The output stream encoding.
+     * @return The XML event writer.
+     * @throws XMLStreamException For errors obtaining an XML event writer.
+     */
+    public static XMLEventWriter getXMLEventWriter(final OutputStream os, final String encoding)
+        throws XMLStreamException
+    {
+        return XML_OUTPUT_FACTORY.createXMLEventWriter(os, encoding) ;
+    }
+
+    /**
+     * Get the XML event writer.
+     * @param result The output result.
+     * @return The XML event writer.
+     * @throws XMLStreamException For errors obtaining an XML event writer.
+     */
+    public static XMLEventWriter getXMLEventWriter(final Result result)
+        throws XMLStreamException
+    {
+        return XML_OUTPUT_FACTORY.createXMLEventWriter(result) ;
+    }
     
     /**
+     * Copy an XML event stream.
+     * @param reader The event reader.
+     * @param writer The event writer.
+     * @throws XMLStreamException For errors writing to the XML event writer.
+     */
+    public static void copyXMLEventStream(final XMLEventReader reader, final XMLEventWriter writer)
+        throws XMLStreamException
+    {
+        copyXMLEventStream(reader, writer, false) ;
+    }
+    
+    /**
+     * Copy an XML event stream.
+     * @param reader The event reader.
+     * @param writer The event writer.
+     * @param omitDoc if true, ignore start/end document events.
+     * @throws XMLStreamException For errors writing to the XML event writer.
+     */
+    public static void copyXMLEventStream(final XMLEventReader reader, final XMLEventWriter writer, final boolean omitDoc)
+        throws XMLStreamException
+    {
+        if (omitDoc)
+        {
+            while(reader.hasNext())
+            {
+                final XMLEvent event = reader.nextEvent() ;
+                final int type = event.getEventType() ;
+                if ((type != XMLStreamConstants.START_DOCUMENT) &&
+                    (type != XMLStreamConstants.END_DOCUMENT))
+                {
+                    writer.add(event) ;
+                }
+            }
+        }
+        else
+        {
+            writer.add(reader) ;
+        }
+        writer.flush() ;
+    }
+    
+    /**
      * Replace system property values within the attribute values/text elements.
      * @param streamReader The XML stream reader.
      * @param streamWriter The XMl stream writer.
@@ -399,14 +591,65 @@
     }
 
     /**
-     * Create the XML input factory.
-     * @return The XML input factory.
+     * Create a document from the specified reader.
+     * @param reader The XMLEvent reader.
+     * @return The Document.
+     * @throws ParserConfigurationException For errors creating the document.
+     * @throws XMLStreamException For errors reading the event reader.
      */
-    private static XMLInputFactory getXMLInputFactory()
+    public static Document createDocument(XMLEventReader reader)
+        throws ParserConfigurationException, XMLStreamException
     {
+        final DocumentBuilder builder = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder() ;
+        final Document doc = builder.newDocument() ;
+        final XMLEventWriter writer = EVENT_WRITER_CREATOR.createXMLEventWriter(doc);
+        XMLHelper.copyXMLEventStream(reader, writer) ;
+        return doc;
+    }
+    
+    /**
+     * Read from a DOM node, output to a writer.
+     * @param node The DOM node.
+     * @param writer The specified writer.
+     * @param omitDoc if true, ignore start/end document events.
+     */
+    public static void readDomNode(final Node node, final XMLEventWriter writer, final boolean omitDoc)
+        throws XMLStreamException
+    {
+        final XMLEventReader reader = EVENT_READER_CREATOR.createXMLEventReader(node);
+        XMLHelper.copyXMLEventStream(reader, writer, omitDoc) ;
+    }
+
+    static
+    {
         final XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance() ;
         xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE) ;
-        return xmlInputFactory ;
+        XML_INPUT_FACTORY = xmlInputFactory ;
+
+        if ("com.ctc.wstx.stax.WstxInputFactory".equals(XML_INPUT_FACTORY.getClass().getName()))
+        {
+            EVENT_READER_CREATOR = new WstxEventReaderCreator(XML_INPUT_FACTORY) ;
+        }
+        else
+        {
+            EVENT_READER_CREATOR = new DefaultEventReaderCreator() ;
+        }
+
+        XML_OUTPUT_FACTORY = XMLOutputFactory.newInstance() ;
+        
+        if ("com.ctc.wstx.stax.WstxOutputFactory".equals(XML_OUTPUT_FACTORY.getClass().getName()))
+        {
+            EVENT_WRITER_CREATOR = new WstxEventWriterCreator(XML_OUTPUT_FACTORY) ;
+        }
+        else
+        {
+            EVENT_WRITER_CREATOR = new DefaultEventWriterCreator() ;
+        }
+
+        final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+        docBuilderFactory.setNamespaceAware(true);
+        DOCUMENT_BUILDER_FACTORY = docBuilderFactory ;
+        
     }
     
     /**
@@ -474,4 +717,134 @@
             StreamHelper.writeEndElement(out, elementName.getPrefix(), uri) ;
         }
     }
+    
+    /**
+     * Interface for the event writer creator.
+     * @author kevin
+     */
+    private interface EventWriterCreator
+    {
+        /**
+         * Create the event writer.
+         * @param doc The associated document.
+         * @return The XML event writer.
+         * @throws XMLStreamException for errors constructing the writer.
+         */
+        public XMLEventWriter createXMLEventWriter(final Document doc)
+            throws XMLStreamException ;
+    }
+    
+    /**
+     * Interface for the event reader creator.
+     * @author kevin
+     */
+    private interface EventReaderCreator
+    {
+        /**
+         * Create the event reader.
+         * @param node The associated node.
+         * @return The XML event reader.
+         * @throws XMLStreamException for errors constructing the reader.
+         */
+        public XMLEventReader createXMLEventReader(final Node node)
+            throws XMLStreamException ;
+    }
+    
+    /**
+     * The default event writer creator
+     * @author kevin
+     */
+    private static final class DefaultEventWriterCreator implements EventWriterCreator
+    {
+        /**
+         * Create the event writer.
+         * @param doc The associated document.
+         * @return The XML event writer.
+         * @throws XMLStreamException for errors constructing the writer.
+         */
+        public XMLEventWriter createXMLEventWriter(final Document doc)
+            throws XMLStreamException
+        {
+            return getXMLEventWriter(new DOMResult(doc)) ;
+        }
+    }
+    /**
+     * The wstx event writer creator
+     * @author kevin
+     */
+    private static final class WstxEventWriterCreator implements EventWriterCreator
+    {
+        private final WstxOutputFactory outputFactory ;
+        
+        /**
+         * Construct the 
+         * @param xmlOutputFactory
+         */
+        private WstxEventWriterCreator(final XMLOutputFactory xmlOutputFactory)
+        {
+            outputFactory = (WstxOutputFactory)xmlOutputFactory ;
+        }
+        
+        /**
+         * Create the event writer.
+         * @param doc The associated document.
+         * @return The XML event writer.
+         * @throws XMLStreamException for errors constructing the writer.
+         */
+        public XMLEventWriter createXMLEventWriter(final Document doc)
+            throws XMLStreamException
+        {
+            final XMLStreamWriter wstxWriter = ESBDOMWrappingWriter.createFrom(outputFactory.getConfig(), new DOMResult(doc)) ;
+            return outputFactory.createXMLEventWriter(wstxWriter) ;
+        }
+    }
+    
+    /**
+     * The default event reader creator
+     * @author kevin
+     */
+    private static final class DefaultEventReaderCreator implements EventReaderCreator
+    {
+        /**
+         * Create the event reader.
+         * @param node The associated node.
+         * @return The XML event reader.
+         * @throws XMLStreamException for errors constructing the reader.
+         */
+        public XMLEventReader createXMLEventReader(final Node node)
+            throws XMLStreamException
+        {
+            return getXMLEventReader(new DOMSource(node)) ;
+        }
+    }
+    /**
+     * The wstx event reader creator
+     * @author kevin
+     */
+    private static final class WstxEventReaderCreator implements EventReaderCreator
+    {
+        private final WstxInputFactory inputFactory ;
+        
+        /**
+         * Construct the 
+         * @param xmlOutputFactory
+         */
+        private WstxEventReaderCreator(final XMLInputFactory xmlInputFactory)
+        {
+            inputFactory = (WstxInputFactory)xmlInputFactory ;
+        }
+        
+        /**
+         * Create the event reader.
+         * @param node The associated node.
+         * @return The XML event reader.
+         * @throws XMLStreamException for errors constructing the reader.
+         */
+        public XMLEventReader createXMLEventReader(final Node node)
+            throws XMLStreamException
+        {
+            final XMLStreamReader wstxReader = ESBDOMWrappingReader.createFrom(inputFactory.getConfig(), new DOMSource(node)) ;
+            return inputFactory.createXMLEventReader(wstxReader) ;
+        }
+    }
 }

Added: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/wstx/ESBDOMWrappingReader.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/wstx/ESBDOMWrappingReader.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/wstx/ESBDOMWrappingReader.java	2010-02-01 16:54:25 UTC (rev 31341)
@@ -0,0 +1,1575 @@
+/* Woodstox XML processor
+ *
+ * Copyright (c) 2004- Tatu Saloranta, tatu.saloranta at iki.fi
+ *
+ * Licensed under the License specified in the file LICENSE which is
+ * included with the source code.
+ * You may not use this file except in compliance with the License.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Copied from the Woodstox 3.2.8 codebase to fix an issue with namespaces in a partial node.
+ */
+package org.jboss.internal.soa.esb.util.wstx;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.text.MessageFormat;
+import java.util.*;
+
+import javax.xml.transform.dom.DOMSource;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.*;
+
+import org.w3c.dom.*;
+
+import org.codehaus.stax2.AttributeInfo;
+import org.codehaus.stax2.DTDInfo;
+import org.codehaus.stax2.LocationInfo;
+import org.codehaus.stax2.XMLInputFactory2;
+import org.codehaus.stax2.XMLStreamLocation2;
+import org.codehaus.stax2.XMLStreamReader2;
+import org.codehaus.stax2.validation.DTDValidationSchema;
+import org.codehaus.stax2.validation.ValidationProblemHandler;
+import org.codehaus.stax2.validation.XMLValidationSchema;
+import org.codehaus.stax2.validation.XMLValidator;
+
+import com.ctc.wstx.api.ReaderConfig;
+import com.ctc.wstx.cfg.ErrorConsts;
+import com.ctc.wstx.exc.WstxParsingException;
+import com.ctc.wstx.io.WstxInputLocation;
+import com.ctc.wstx.util.EmptyIterator;
+import com.ctc.wstx.util.EmptyNamespaceContext;
+import com.ctc.wstx.util.SingletonIterator;
+import com.ctc.wstx.util.TextAccumulator;
+
+/**
+ * This is an adapter class that presents a DOM document as if it was
+ * a regular {@link XMLStreamReader}.
+ *<p>
+ * Note that the implementation is only to be used for use with
+ * <code>javax.xml.transform.dom.DOMSource</code>. It can however be
+ * used for both full documents, and single element root fragments,
+ * depending on what node is passed as the argument.
+ *<p>
+ * Some notes regarding missing/incomplete functionality:
+ * <ul>
+ *  <li>DOM does not seem to have access to information from the XML
+ *    declaration (although Document node can be viewed as representing
+ *    it). Consequently, all accessors return no information (version,
+ *    encoding, standalone).
+ *   </li>
+ *  <li>No location info is provided, since (you guessed it!) DOM
+ *    does not provide that info.
+ *   </li>
+ *  </ul>
+ */
+public class ESBDOMWrappingReader
+    implements XMLStreamReader2,
+               DTDInfo, LocationInfo, NamespaceContext,
+               XMLStreamConstants
+{
+    // // // Bit masks used for quick type comparisons
+
+    final private static int MASK_GET_TEXT = 
+        (1 << CHARACTERS) | (1 << CDATA) | (1 << SPACE)
+        | (1 << COMMENT) | (1 << DTD) | (1 << ENTITY_REFERENCE);
+
+    final private static int MASK_GET_ELEMENT_TEXT = 
+        (1 << CHARACTERS) | (1 << CDATA) | (1 << SPACE)
+        | (1 << ENTITY_REFERENCE);
+
+    // // // Configuration:
+
+    protected final ReaderConfig mConfig;
+
+    protected final String mSystemId;
+
+    protected final Node mRootNode;
+
+    protected final boolean mNsAware;
+
+    /**
+     * Whether stream reader is to coalesce adjacent textual
+     * (CHARACTERS, SPACE, CDATA) events (as per property
+     * {@link XMLInputFactory#IS_COALESCING}) or not
+     */
+    protected final boolean mCoalescing;
+
+    // // // State:
+
+    protected int mCurrEvent = START_DOCUMENT;
+
+    /**
+     * Current node is the DOM node that contains information
+     * regarding the current event.
+     */
+    protected Node mCurrNode;
+
+    protected int mDepth = 0;
+
+    /**
+     * In coalescing mode, we may need to combine textual content
+     * from multiple adjacent nodes. Since we shouldn't be modifying
+     * the underlying DOM tree, need to accumulate it into a temporary
+     * variable
+     */
+    protected String mCoalescedText;
+
+    /**
+     * Helper object used for combining segments of text as needed
+     */
+    protected TextAccumulator mTextBuffer = new TextAccumulator();
+
+    // // // Attribute/namespace declaration state
+
+    /* DOM, alas, does not distinguish between namespace declarations
+     * and attributes (due to its roots prior to XML namespaces?).
+     * Because of this, two lists need to be separated. Since this
+     * information is often not needed, it will be lazily generated.
+     */
+
+    /**
+     * Lazily instantiated List of all actual attributes for the
+     * current (start) element, NOT including namespace declarations.
+     * As such, elements are {@link org.w3c.dom.Attr} instances.
+     *<p>
+     */
+    protected List mAttrList = null;
+
+    /**
+     * Lazily instantiated String pairs of all namespace declarations for the
+     * current (start/end) element. String pair means that for each
+     * declarations there are two Strings in the list: first one is prefix
+     * (empty String for the default namespace declaration), and second
+     * URI it is bound to.
+     */
+    protected List mNsDeclList = null;
+    
+    /**
+     * Map of initial namespace to output on root element.
+     */
+    protected Map mNsInitialMap ;
+
+    /*
+    ////////////////////////////////////////////////////
+    // Construction
+    ////////////////////////////////////////////////////
+     */
+
+    /**
+     * @param cfg Configuration of this reader
+     * @param treeRoot Node that is the tree of the DOM document, or
+     *   fragment.
+     */
+    private ESBDOMWrappingReader(ReaderConfig cfg, Node treeRoot, String sysId)
+        throws XMLStreamException
+    {
+        if (treeRoot == null) {
+            throw new IllegalArgumentException("Can not pass null Node for constructing a DOM-based XMLStreamReader");
+        }
+
+        mConfig = cfg;
+        mNsAware = cfg.willSupportNamespaces();
+        mCoalescing = cfg.willCoalesceText();
+        mSystemId = sysId;
+        
+        /* Ok; we need a document node; or an element node; or a document
+         * fragment node.
+         */
+        switch (treeRoot.getNodeType()) {
+        case Node.DOCUMENT_NODE: // fine
+            /* Should try to find encoding, version and stand-alone
+             * settings... but is there a standard way of doing that?
+             */
+        case Node.ELEMENT_NODE: // can make sub-tree... ok
+            // But should we skip START/END_DOCUMENT? For now, let's not
+
+        case Node.DOCUMENT_FRAGMENT_NODE: // as with element...
+
+            // Above types are fine
+            break;
+
+        default: // other Nodes not usable
+            throw new XMLStreamException("Can not create an XMLStreamReader for a DOM node of type "+treeRoot.getClass());
+        }
+        mRootNode = mCurrNode = treeRoot;
+        if (mNsAware)
+        {
+            calculateInitialNamespaces() ;
+        }
+    }
+
+    private void calculateInitialNamespaces()
+    {
+        Node node = mCurrNode.getParentNode() ;
+        
+        if ((node != null) && (Node.ELEMENT_NODE == node.getNodeType()))
+        {
+            final Map nsMap = new HashMap() ;
+            do
+            {
+                final NamedNodeMap namedNodeMap = node.getAttributes() ;
+                final int numAttributes = namedNodeMap.getLength() ;
+                for (int count = 0 ; count < numAttributes ; count++)
+                {
+                    final Node attribute = namedNodeMap.item(count) ;
+                    String prefix = attribute.getPrefix() ;
+    
+                    final String localName = attribute.getLocalName() ;
+                    if (prefix == null || prefix.length() == 0)
+                    {
+                        if ("xmlns".equals(localName))
+                        {
+                            nsMap.put("", attribute.getNodeValue()) ;
+                        }
+                    }
+                    else if ("xmlns".equals(prefix))
+                    {
+                        nsMap.put(localName, attribute.getNodeValue()) ;
+                    }
+                }
+                
+                node = node.getParentNode() ;
+            } while ((node != null) && (Node.ELEMENT_NODE == node.getNodeType())) ;
+            
+            if (nsMap.size() > 0)
+            {
+                mNsInitialMap = nsMap ;
+            }
+        }
+    }
+
+    public static ESBDOMWrappingReader createFrom(ReaderConfig cfg, DOMSource src)
+        throws XMLStreamException
+    {
+        Node rootNode = src.getNode();
+        String systemId = src.getSystemId();
+        return new ESBDOMWrappingReader(cfg, rootNode, systemId);
+    }
+
+    /*
+    ////////////////////////////////////////////////////
+    // XMLStreamReader, document info
+    ////////////////////////////////////////////////////
+     */
+
+    /**
+     * As per Stax (1.0) specs, needs to return whatever xml declaration
+     * claimed encoding is, if any; or null if no xml declaration found.
+     */
+    public String getCharacterEncodingScheme() {
+        /* No standard way to figure it out from a DOM Document node;
+         * have to return null
+         */
+        return null;
+    }
+
+    /**
+     * As per Stax (1.0) specs, needs to return whatever parser determined
+     * the encoding was, if it was able to figure it out. If not (there are
+     * cases where this can not be found; specifically when being passed a
+     * {@link java.io.Reader}), it should return null.
+     */
+    public String getEncoding() {
+        /* We have no information regarding underlying stream/Reader, so
+         * best we can do is to see if we know xml declaration encoding.
+         */
+        return getCharacterEncodingScheme();
+    }
+
+    public String getVersion()
+    {
+        /* No standard way to figure it out from a DOM Document node;
+         * have to return null
+         */
+        return null;
+    }
+
+    public boolean isStandalone() {
+        /* No standard way to figure it out from a DOM Document node;
+         * have to return false
+         */
+        return false;
+    }
+
+    public boolean standaloneSet() {
+        /* No standard way to figure it out from a DOM Document node;
+         * have to return false
+         */
+        return false;
+    }
+
+    /*
+    ////////////////////////////////////////////////////
+    // Public API, configuration
+    ////////////////////////////////////////////////////
+     */
+
+    public Object getProperty(String name)
+    {
+        if (name.equals("javax.xml.stream.entities")) {
+            // !!! TBI
+            return Collections.EMPTY_LIST;
+        }
+        if (name.equals("javax.xml.stream.notations")) {
+            // !!! TBI
+            return Collections.EMPTY_LIST;
+        }
+        // [WSTX-162]: no way to cleanly enable name/nsURI interning
+        if (XMLInputFactory2.P_INTERN_NAMES.equals(name)
+            || XMLInputFactory2.P_INTERN_NS_URIS.equals(name)) {
+            return Boolean.FALSE;
+        }
+        return mConfig.getProperty(name);
+    }
+
+    /*
+    ////////////////////////////////////////////////////
+    // XMLStreamReader, current state
+    ////////////////////////////////////////////////////
+     */
+
+    // // // Attribute access:
+
+    public int getAttributeCount()
+    {
+        if (mCurrEvent != START_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_STELEM);
+        }
+        if (mAttrList == null) {
+            calcNsAndAttrLists(true);
+        }
+        return mAttrList.size();
+    }
+
+    public String getAttributeLocalName(int index)
+    {
+        if (mCurrEvent != START_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_STELEM);
+        }
+        if (mAttrList == null) {
+            calcNsAndAttrLists(true);
+        }
+        if (index >= mAttrList.size() || index < 0) {
+            handleIllegalAttrIndex(index);
+            return null;
+        }
+        Attr attr = (Attr) mAttrList.get(index);
+        return safeGetLocalName(attr);
+    }
+
+    public QName getAttributeName(int index)
+    {
+        if (mCurrEvent != START_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_STELEM);
+        }
+        if (mAttrList == null) {
+            calcNsAndAttrLists(true);
+        }
+        if (index >= mAttrList.size() || index < 0) {
+            handleIllegalAttrIndex(index);
+            return null;
+        }
+        Attr attr = (Attr) mAttrList.get(index);
+        return constructQName(attr.getNamespaceURI(), safeGetLocalName(attr),
+                              attr.getPrefix());
+    }
+
+    public String getAttributeNamespace(int index)
+    {
+        if (mCurrEvent != START_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_STELEM);
+        }
+        if (mAttrList == null) {
+            calcNsAndAttrLists(true);
+        }
+        if (index >= mAttrList.size() || index < 0) {
+            handleIllegalAttrIndex(index);
+            return null;
+        }
+        Attr attr = (Attr) mAttrList.get(index);
+        return attr.getNamespaceURI();
+    }
+
+    public String getAttributePrefix(int index)
+    {
+        if (mCurrEvent != START_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_STELEM);
+        }
+        if (mAttrList == null) {
+            calcNsAndAttrLists(true);
+        }
+        if (index >= mAttrList.size() || index < 0) {
+            handleIllegalAttrIndex(index);
+            return null;
+        }
+        Attr attr = (Attr) mAttrList.get(index);
+        return attr.getPrefix();
+    }
+
+    public String getAttributeType(int index)
+    {
+        if (mCurrEvent != START_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_STELEM);
+        }
+        if (mAttrList == null) {
+            calcNsAndAttrLists(true);
+        }
+        if (index >= mAttrList.size() || index < 0) {
+            handleIllegalAttrIndex(index);
+            return null;
+        }
+        //Attr attr = (Attr) mAttrList.get(index);
+        // First, a special case, ID... since it's potentially most useful
+        /* 26-Apr-2006, TSa: Turns out that following methods are
+         *    DOM Level3, and as such not available in JDK 1.4 and prior.
+         *    Thus, let's not yet use them (could use dynamic discovery
+         *    for graceful downgrade)
+         */
+        /*
+        if (attr.isId()) {
+            return "ID";
+        }
+        TypeInfo schemaType = attr.getSchemaTypeInfo();
+        return (schemaType == null) ? "CDATA" : schemaType.getTypeName();
+        */
+        return "CDATA";
+    }
+
+    public String getAttributeValue(int index)
+    {
+        if (mCurrEvent != START_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_STELEM);
+        }
+        if (mAttrList == null) {
+            calcNsAndAttrLists(true);
+        }
+        if (index >= mAttrList.size() || index < 0) {
+            handleIllegalAttrIndex(index);
+            return null;
+        }
+        Attr attr = (Attr) mAttrList.get(index);
+        return attr.getValue();
+    }
+
+    public String getAttributeValue(String nsURI, String localName)
+    {
+        if (mCurrEvent != START_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_STELEM);
+        }
+        Element elem = (Element) mCurrNode;
+        NamedNodeMap attrs = elem.getAttributes();
+        /* Hmmh. DOM javadocs claim "Per [XML Namespaces], applications
+         * must use the value null as the namespaceURI parameter for methods
+         * if they wish to have no namespace.".
+         * Not sure how true that is, but:
+         */
+        if (nsURI != null && nsURI.length() == 0) {
+            nsURI = null;
+        }
+        Attr attr = (Attr) attrs.getNamedItemNS(nsURI, localName);
+        return (attr == null) ? null : attr.getValue();
+    }
+
+    /**
+     * From StAX specs:
+     *<blockquote>
+     * Reads the content of a text-only element, an exception is thrown if
+     * this is not a text-only element.
+     * Regardless of value of javax.xml.stream.isCoalescing this method always
+     * returns coalesced content.
+     *<br/>Precondition: the current event is START_ELEMENT.
+     *<br/>Postcondition: the current event is the corresponding END_ELEMENT. 
+     *</blockquote>
+     */
+    public String getElementText()
+        throws XMLStreamException
+    {
+        if (mCurrEvent != START_ELEMENT) {
+            throwParseError(ErrorConsts.ERR_STATE_NOT_STELEM);
+        }
+
+        /**
+         * Need to loop to get rid of PIs, comments
+         */
+        while (true) {
+            int type = next();
+            if (type == END_ELEMENT) {
+                break;
+            }
+            if (type == COMMENT || type == PROCESSING_INSTRUCTION) {
+                continue;
+            }
+            if (((1 << type) & MASK_GET_ELEMENT_TEXT) == 0) {
+                throwParseError("Expected a text token, got "+ErrorConsts.tokenTypeDesc(type)+".");
+            }
+            mTextBuffer.addText(getText());
+        }
+        return mTextBuffer.getAndClear();
+    }
+
+    /**
+     * Returns type of the last event returned; or START_DOCUMENT before
+     * any events has been explicitly returned.
+     */
+    public int getEventType()
+    {
+        return mCurrEvent;
+    }
+    
+    public String getLocalName()
+    {
+        if (mCurrEvent == START_ELEMENT || mCurrEvent == END_ELEMENT) {
+            return safeGetLocalName(mCurrNode);
+        }
+        if (mCurrEvent == ENTITY_REFERENCE) {
+            return mCurrNode.getNodeName();
+        }
+        throw new IllegalStateException("Current state ("+ErrorConsts.tokenTypeDesc(mCurrEvent)+") not START_ELEMENT, END_ELEMENT or ENTITY_REFERENCE");
+    }
+
+    // // // getLocation() defined in StreamScanner
+
+    public QName getName()
+    {
+        if (mCurrEvent != START_ELEMENT && mCurrEvent != END_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_ELEM);
+        }
+        return constructQName(mCurrNode.getNamespaceURI(), safeGetLocalName(mCurrNode), mCurrNode.getPrefix());
+    }
+
+    // // // Namespace access
+
+    public NamespaceContext getNamespaceContext() {
+        return this;
+    }
+
+    public int getNamespaceCount() {
+        if (mCurrEvent != START_ELEMENT && mCurrEvent != END_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_ELEM);
+        }
+        if (mNsDeclList == null) {
+            if (!mNsAware) {
+                return 0;
+            }
+            calcNsAndAttrLists(mCurrEvent == START_ELEMENT);
+        }
+        return mNsDeclList.size() / 2;
+    }
+
+    /**
+     * Alas, DOM does not expose any of information necessary for
+     * determining actual declarations. Thus, have to indicate that
+     * there are no declarations.
+     */
+    public String getNamespacePrefix(int index) {
+        if (mCurrEvent != START_ELEMENT && mCurrEvent != END_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_ELEM);
+        }
+        if (mNsDeclList == null) {
+            if (!mNsAware) {
+                handleIllegalNsIndex(index);
+            }
+            calcNsAndAttrLists(mCurrEvent == START_ELEMENT);
+        }
+        if (index < 0 || (index + index) >= mNsDeclList.size()) {
+            handleIllegalNsIndex(index);
+        }
+        return (String) mNsDeclList.get(index + index);
+    }
+
+    public String getNamespaceURI() {
+        if (mCurrEvent != START_ELEMENT && mCurrEvent != END_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_ELEM);
+        }
+        return mCurrNode.getNamespaceURI();
+    }
+
+    public String getNamespaceURI(int index) {
+        if (mCurrEvent != START_ELEMENT && mCurrEvent != END_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_ELEM);
+        }
+        if (mNsDeclList == null) {
+            if (!mNsAware) {
+                handleIllegalNsIndex(index);
+            }
+            calcNsAndAttrLists(mCurrEvent == START_ELEMENT);
+        }
+        if (index < 0 || (index + index) >= mNsDeclList.size()) {
+            handleIllegalNsIndex(index);
+        }
+        return (String) mNsDeclList.get(index + index + 1);
+    }
+
+    // Note: implemented as part of NamespaceContext
+    //public String getNamespaceURI(String prefix)
+
+    public String getPIData() {
+        if (mCurrEvent != PROCESSING_INSTRUCTION) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_PI);
+        }
+        return mCurrNode.getNodeValue();
+    }
+
+    public String getPITarget() {
+        if (mCurrEvent != PROCESSING_INSTRUCTION) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_PI);
+        }
+        return mCurrNode.getNodeName();
+    }
+
+    public String getPrefix() {
+        if (mCurrEvent != START_ELEMENT && mCurrEvent != END_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_ELEM);
+        }
+        return mCurrNode.getPrefix();
+    }
+
+    public String getText()
+    {
+        if (mCoalescedText != null) {
+            return mCoalescedText;
+        }
+        if (((1 << mCurrEvent) & MASK_GET_TEXT) == 0) {
+            throwNotTextual(mCurrEvent);
+        }
+        return mCurrNode.getNodeValue();
+    }
+
+    public char[] getTextCharacters()
+    {
+        String text = getText();
+        return text.toCharArray();
+    }
+
+    public int getTextCharacters(int sourceStart, char[] target, int targetStart, int len)
+    {
+        if (((1 << mCurrEvent) & MASK_GET_TEXT) == 0) {
+            throwNotTextual(mCurrEvent);
+        }
+        String text = getText();
+        if (len > text.length()) {
+            len = text.length();
+        }
+        text.getChars(sourceStart, sourceStart+len, target, targetStart);
+        return len;
+    }
+
+    public int getTextLength()
+    {
+        if (((1 << mCurrEvent) & MASK_GET_TEXT) == 0) {
+            throwNotTextual(mCurrEvent);
+        }
+        return getText().length();
+    }
+
+    public int getTextStart()
+    {
+        if (((1 << mCurrEvent) & MASK_GET_TEXT) == 0) {
+            throwNotTextual(mCurrEvent);
+        }
+        return 0;
+    }
+
+    public boolean hasName() {
+        return (mCurrEvent == START_ELEMENT) || (mCurrEvent == END_ELEMENT);
+    }
+
+    public boolean hasNext() {
+        return (mCurrEvent != END_DOCUMENT);
+    }
+
+    public boolean hasText() {
+        return (((1 << mCurrEvent) & MASK_GET_TEXT) != 0);
+    }
+
+    public boolean isAttributeSpecified(int index)
+    {
+        if (mCurrEvent != START_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_STELEM);
+        }
+        Element elem = (Element) mCurrNode;
+        Attr attr = (Attr) elem.getAttributes().item(index);
+        if (attr == null) {
+            handleIllegalAttrIndex(index);
+            return false;
+        }
+        return attr.getSpecified();
+    }
+
+    public boolean isCharacters()
+    {
+        return (mCurrEvent == CHARACTERS);
+    }
+
+    public boolean isEndElement() {
+        return (mCurrEvent == END_ELEMENT);
+    }
+
+    public boolean isStartElement() {
+        return (mCurrEvent == START_ELEMENT);
+    }
+
+    /**
+     *<p>
+     * 05-Apr-2004, TSa: Could try to determine status when text is actually
+     *   read. That'd prevent double reads... but would it slow down that
+     *   one reading so that net effect would be negative?
+     */
+    public boolean isWhiteSpace()
+    {
+        if (mCurrEvent == CHARACTERS || mCurrEvent == CDATA) {
+            String text = getText();
+            for (int i = 0, len = text.length(); i < len; ++i) {
+                /* !!! If xml 1.1 was to be handled, should check for
+                 *   LSEP and NEL too
+                 */
+                if (text.charAt(i) > 0x0020) {
+                    return false;
+                }
+            }
+            return true;
+        }
+        return (mCurrEvent == SPACE);
+    }
+    
+    public void require(int type, String nsUri, String localName)
+        throws XMLStreamException
+    {
+        int curr = mCurrEvent;
+
+        /* There are some special cases; specifically, SPACE and CDATA
+         * are sometimes reported as CHARACTERS. Let's be lenient by
+         * allowing both 'real' and reported types, for now.
+         */
+        if (curr != type) {
+            if (curr == CDATA) {
+                curr = CHARACTERS;
+            } else if (curr == SPACE) {
+                curr = CHARACTERS;
+            }
+        }
+
+        if (type != curr) {
+            throwParseError("Expected type "+ErrorConsts.tokenTypeDesc(type)
+                            +", current type "
+                            +ErrorConsts.tokenTypeDesc(curr));
+        }
+
+        if (localName != null) {
+            if (curr != START_ELEMENT && curr != END_ELEMENT
+                && curr != ENTITY_REFERENCE) {
+                throwParseError("Expected non-null local name, but current token not a START_ELEMENT, END_ELEMENT or ENTITY_REFERENCE (was "+ErrorConsts.tokenTypeDesc(mCurrEvent)+")");
+            }
+            String n = getLocalName();
+            if (n != localName && !n.equals(localName)) {
+                throwParseError("Expected local name '"+localName+"'; current local name '"+n+"'.");
+            }
+        }
+        if (nsUri != null) {
+            if (curr != START_ELEMENT && curr != END_ELEMENT) {
+                throwParseError("Expected non-null NS URI, but current token not a START_ELEMENT or END_ELEMENT (was "+ErrorConsts.tokenTypeDesc(curr)+")");
+            }
+
+            String uri = getNamespaceURI();
+            // No namespace?
+            if (nsUri.length() == 0) {
+                if (uri != null && uri.length() > 0) {
+                    throwParseError("Expected empty namespace, instead have '"+uri+"'.");
+                }
+            } else {
+                if ((nsUri != uri) && !nsUri.equals(uri)) {
+                    throwParseError("Expected namespace '"+nsUri+"'; have '"
+                                    +uri+"'.");
+                }
+            }
+        }
+        // Ok, fine, all's good
+    }
+
+    /*
+    ////////////////////////////////////////////////////
+    // XMLStreamReader, iterating
+    ////////////////////////////////////////////////////
+     */
+
+    public int next()
+        throws XMLStreamException
+    {
+        mCoalescedText = null;
+
+        /* For most events, we just need to find the next sibling; and
+         * that failing, close the parent element. But there are couple
+         * of special cases, which are handled first:
+         */
+        switch (mCurrEvent) {
+
+        case START_DOCUMENT: // initial state
+            /* What to do here depends on what kind of node we started
+             * with...
+             */
+            switch (mCurrNode.getNodeType()) {
+            case Node.DOCUMENT_NODE:
+            case Node.DOCUMENT_FRAGMENT_NODE:
+                // For doc, fragment, need to find first child
+                mCurrNode = mCurrNode.getFirstChild();
+                break;
+
+            case Node.ELEMENT_NODE:
+                // For element, curr node is fine:
+                return (mCurrEvent = START_ELEMENT);
+
+            default:
+                throw new XMLStreamException("Internal error: unexpected DOM root node type "+mCurrNode.getNodeType()+" for node '"+mCurrNode+"'");
+            }
+            break;
+
+        case END_DOCUMENT: // end reached: should not call!
+            throw new java.util.NoSuchElementException("Can not call next() after receiving END_DOCUMENT");
+
+        case START_ELEMENT: // element returned, need to traverse children, if any
+            ++mDepth;
+            mAttrList = null; // so it will not get reused accidentally
+            {
+                Node firstChild = mCurrNode.getFirstChild();
+                if (firstChild == null) { // empty? need to return virtual END_ELEMENT
+                    /* Note: need not clear namespace declarations, because
+                     * it'll be the same as for the start elem!
+                     */
+                    return (mCurrEvent = END_ELEMENT);
+                }
+                mNsDeclList = null;
+
+                /* non-empty is easy: let's just swap curr node, and
+                 * fall through to regular handling
+                 */
+                mCurrNode = firstChild;
+                break;
+            }
+
+        case END_ELEMENT:
+
+            --mDepth;
+            // Need to clear these lists
+            mAttrList = null;
+            mNsDeclList = null;
+
+            /* One special case: if we hit the end of children of
+             * the root element (when tree constructed with Element,
+             * instead of Document or DocumentFragment). If so, it'll
+             * be END_DOCUMENT:
+             */
+            if (mCurrNode == mRootNode) {
+                return (mCurrEvent = END_DOCUMENT);
+            }
+            // Otherwise need to fall through to default handling:
+
+        default:
+            /* For anything else, we can and should just get the
+             * following sibling.
+             */
+            {
+                Node next = mCurrNode.getNextSibling();
+                // If sibling, let's just assign and fall through
+                if (next != null) {
+                    mCurrNode = next;
+                    break;
+                }
+                /* Otherwise, need to climb up the stack and either
+                 * return END_ELEMENT (if parent is element) or
+                 * END_DOCUMENT (if not; needs to be root, then)
+                 */
+                mCurrNode = mCurrNode.getParentNode();
+                int type = mCurrNode.getNodeType();
+                if (type == Node.ELEMENT_NODE) {
+                    return (mCurrEvent = END_ELEMENT);
+                }
+                // Let's do sanity check; should really be Doc/DocFragment
+                if (mCurrNode != mRootNode ||
+                    (type != Node.DOCUMENT_NODE && type != Node.DOCUMENT_FRAGMENT_NODE)) {
+                    throw new XMLStreamException("Internal error: non-element parent node ("+type+") that is not the initial root node");
+                }
+                return (mCurrEvent = END_DOCUMENT);
+            }
+        }
+
+        // Ok, need to determine current node type:
+        switch (mCurrNode.getNodeType()) {
+        case Node.CDATA_SECTION_NODE:
+            if (mCoalescing) {
+                coalesceText(CDATA);
+            } else {
+                mCurrEvent = CDATA;
+            }
+            break;
+        case Node.COMMENT_NODE:
+            mCurrEvent = COMMENT;
+            break;
+        case Node.DOCUMENT_TYPE_NODE:
+            mCurrEvent = DTD;
+            break;
+        case Node.ELEMENT_NODE:
+            mCurrEvent = START_ELEMENT;
+            break;
+        case Node.ENTITY_REFERENCE_NODE:
+            mCurrEvent = ENTITY_REFERENCE;
+            break;
+        case Node.PROCESSING_INSTRUCTION_NODE:
+            mCurrEvent = PROCESSING_INSTRUCTION;
+            break;
+        case Node.TEXT_NODE:
+            if (mCoalescing) {
+                coalesceText(CHARACTERS);
+            } else {
+                mCurrEvent = CHARACTERS;
+            }
+            break;
+
+            // Should not get other nodes (notation/entity decl., attr)
+        case Node.ATTRIBUTE_NODE:
+        case Node.ENTITY_NODE:
+        case Node.NOTATION_NODE:
+            throw new XMLStreamException("Internal error: unexpected DOM node type "+mCurrNode.getNodeType()+" (attr/entity/notation?), for node '"+mCurrNode+"'");
+
+        default:
+            throw new XMLStreamException("Internal error: unrecognized DOM node type "+mCurrNode.getNodeType()+", for node '"+mCurrNode+"'");
+        }
+
+        return mCurrEvent;
+    }
+
+    public int nextTag()
+        throws XMLStreamException
+    {
+        while (true) {
+            int next = next();
+
+            switch (next) {
+            case SPACE:
+            case COMMENT:
+            case PROCESSING_INSTRUCTION:
+                continue;
+            case CDATA:
+            case CHARACTERS:
+                if (isWhiteSpace()) {
+                    continue;
+                }
+                throwParseError("Received non-all-whitespace CHARACTERS or CDATA event in nextTag().");
+        break; // never gets here, but jikes complains without
+            case START_ELEMENT:
+            case END_ELEMENT:
+                return next;
+            }
+            throwParseError("Received event "+ErrorConsts.tokenTypeDesc(next)
+                            +", instead of START_ELEMENT or END_ELEMENT.");
+        }
+    }
+
+    /**
+     *<p>
+     * Note: as per StAX 1.0 specs, this method does NOT close the underlying
+     * input reader. That is, unless the new StAX2 property
+     * {@link org.codehaus.stax2.XMLInputFactory2#P_AUTO_CLOSE_INPUT} is
+     * set to true.
+     */
+    public void close()
+        throws XMLStreamException
+    {
+        // Since DOM tree has no real input source, nothing to do
+    }
+
+
+    /*
+    ////////////////////////////////////////////////////
+    // NamespaceContext
+    ////////////////////////////////////////////////////
+     */
+
+    public String getNamespaceURI(String prefix)
+    {
+        /* 26-Apr-2006, TSa: Alas, these methods are DOM Level 3,
+         *   i.e. require JDK 1.5 or higher
+         */
+        /*
+        if (prefix.length() == 0) { // def NS
+            return mCurrNode.lookupNamespaceURI(null);
+        }
+        return mCurrNode.lookupNamespaceURI(prefix);
+        */
+        return null;
+    }
+
+    public String getPrefix(String namespaceURI)
+    {
+        /* 26-Apr-2006, TSa: Alas, these methods are DOM Level 3,
+         *   i.e. require JDK 1.5 or higher
+         */
+        /*
+        String prefix = mCurrNode.lookupPrefix(namespaceURI);
+        if (prefix == null) { // maybe default NS?
+            String defURI = mCurrNode.lookupNamespaceURI(null);
+            if (defURI != null && defURI.equals(namespaceURI)) {
+                return "";
+            }
+        }
+        return prefix;
+        */
+        return null;
+    }
+
+    public Iterator getPrefixes(String namespaceURI) 
+    {
+        String prefix = getPrefix(namespaceURI);
+        if (prefix == null) {
+            return EmptyIterator.getInstance();
+        }
+        return new SingletonIterator(prefix);
+    }
+
+    /*
+    ////////////////////////////////////////////////////
+    // XMLStreamReader2 (StAX2) implementation
+    ////////////////////////////////////////////////////
+     */
+
+    // // // StAX2, per-reader configuration
+
+    public Object getFeature(String name)
+    {
+        // No readable features defined yet...
+        throw new IllegalArgumentException(MessageFormat.format(ErrorConsts.ERR_UNKNOWN_FEATURE, new Object[] { name })); 
+    }
+
+    public void setFeature(String name, Object value)
+    {
+        // Base-class has no settable features at this point.
+        throw new IllegalArgumentException(MessageFormat.format(ErrorConsts.ERR_UNKNOWN_FEATURE, new Object[] { name })); 
+    }
+
+    // NOTE: getProperty() defined in Stax 1.0 interface
+
+    public boolean isPropertySupported(String name) {
+        // !!! TBI: not all these properties are really supported
+        return mConfig.isPropertySupported(name);
+    }
+
+    /**
+     * @param name Name of the property to set
+     * @param value Value to set property to.
+     *
+     * @return True, if the specified property was <b>succesfully</b>
+     *    set to specified value; false if its value was not changed
+     */
+    public boolean setProperty(String name, Object value)
+    {
+        /* Note: can not call local method, since it'll return false for
+         * recognized but non-mutable properties
+         */
+        if (XMLInputFactory2.P_INTERN_NAMES.equals(name)
+            || XMLInputFactory2.P_INTERN_NS_URIS.equals(name)) {
+            /* [WTSX-162]: Name/Namespace URI interning seemingly enabled,
+             *   isn't. Alas, not easy to enable it, so let's force it to
+             *   always be disabled
+             */
+            if (!(value instanceof Boolean) || ((Boolean) value).booleanValue()) {
+                throw new IllegalArgumentException("DOM-based reader does not support interning of names or namespace URIs");
+            }
+            return true;
+        }
+        return mConfig.setProperty(name, value);
+    }
+
+    // // // StAX2, additional traversal methods
+
+    public void skipElement() throws XMLStreamException
+    {
+        if (mCurrEvent != START_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_STELEM);
+        }
+        int nesting = 1; // need one more end elements than start elements
+
+        while (true) {
+            int type = next();
+            if (type == START_ELEMENT) {
+                ++nesting;
+            } else if (type == END_ELEMENT) {
+                if (--nesting == 0) {
+                    break;
+                }
+            }
+        }
+    }
+
+    // // // StAX2, additional attribute access
+
+    public AttributeInfo getAttributeInfo() throws XMLStreamException
+    {
+        if (mCurrEvent != START_ELEMENT) {
+            throw new IllegalStateException(ErrorConsts.ERR_STATE_NOT_STELEM);
+        }
+        // !!! TBI
+        return null;
+    }
+
+    // // // StAX2, Additional DTD access
+
+    /**
+     * Since this class implements {@link DTDInfo}, method can just
+     * return <code>this</code>.
+     */
+    public DTDInfo getDTDInfo() throws XMLStreamException
+    {
+        /* Let's not allow it to be accessed during other events -- that
+         * way callers won't count on it being available afterwards.
+         */
+        if (mCurrEvent != DTD) {
+            return null;
+        }
+        return this;
+    }
+
+    // // // StAX2, Additional location information
+
+    /**
+     * Location information is always accessible, for this reader.
+     */
+    public final LocationInfo getLocationInfo() {
+        return this;
+    }
+
+    // // // StAX2, Pass-through text accessors
+
+
+    /**
+     * Method similar to {@link #getText()}, except
+     * that it just uses provided Writer to write all textual content.
+     * For further optimization, it may also be allowed to do true
+     * pass-through, thus possibly avoiding one temporary copy of the
+     * data.
+     *<p>
+     * TODO: try to optimize to allow completely streaming pass-through:
+     * currently will still read all data in memory buffers before
+     * outputting
+     * 
+     * @param w Writer to use for writing textual contents
+     * @param preserveContents If true, reader has to preserve contents
+     *   so that further calls to <code>getText</code> will return
+     *   proper conntets. If false, reader is allowed to skip creation
+     *   of such copies: this can improve performance, but it also means
+     *   that further calls to <code>getText</code> is not guaranteed to
+     *   return meaningful data.
+     *
+     * @return Number of characters written to the reader
+     */
+    public int getText(Writer w, boolean preserveContents)
+        throws IOException, XMLStreamException
+    {
+        if (((1 << mCurrEvent) & MASK_GET_TEXT) == 0) {
+            throwNotTextual(mCurrEvent);
+        }
+        String text = getText();
+        w.write(text);
+        return text.length();
+    }
+
+    // // // StAX 2, Other accessors
+
+    /**
+     * @return Number of open elements in the stack; 0 when parser is in
+     *  prolog/epilog, 1 inside root element and so on.
+     */
+    public int getDepth() {
+        return mDepth;
+    }
+
+    /**
+     * @return True, if cursor points to a start or end element that is
+     *    constructed from 'empty' element (ends with '/>');
+     *    false otherwise.
+     */
+    public boolean isEmptyElement() throws XMLStreamException
+    {
+        // No way to really figure it out via DOM is there?
+        return false;
+    }
+
+    public NamespaceContext getNonTransientNamespaceContext()
+    {
+        /* Since DOM does not expose enough functionality to figure
+         * out complete declaration stack, can not implement.
+         * Can either return null, or a dummy instance. For now, let's
+         * do latter:
+         */
+        return EmptyNamespaceContext.getInstance();
+    }
+
+    public String getPrefixedName()
+    {
+        switch (mCurrEvent) {
+        case START_ELEMENT:
+        case END_ELEMENT:
+            {
+                String prefix = getPrefix();
+                String ln = getLocalName();
+
+                if (prefix == null) {
+                    return ln;
+                }
+                StringBuffer sb = new StringBuffer(ln.length() + 1 + prefix.length());
+                sb.append(prefix);
+                sb.append(':');
+                sb.append(ln);
+                return sb.toString();
+            }
+        case ENTITY_REFERENCE:
+            return getLocalName();
+        case PROCESSING_INSTRUCTION:
+            return getPITarget();
+        case DTD:
+            return getDTDRootName();
+
+        }
+        throw new IllegalStateException("Current state ("+ErrorConsts.tokenTypeDesc(mCurrEvent)+") not START_ELEMENT, END_ELEMENT, ENTITY_REFERENCE, PROCESSING_INSTRUCTION or DTD");
+    }
+
+    public void closeCompletely() throws XMLStreamException
+    {
+        // Nothing special to do...
+    }
+
+    /*
+    ////////////////////////////////////////////////////
+    // DTDInfo implementation (StAX 2)
+    ////////////////////////////////////////////////////
+     */
+
+    public Object getProcessedDTD() {
+        return null;
+    }
+
+    public String getDTDRootName() {
+        if (mCurrEvent == DTD) {
+            return ((DocumentType) mCurrNode).getName();
+        }
+        return null;
+    }
+
+    public String getDTDPublicId() {
+        if (mCurrEvent == DTD) {
+            return ((DocumentType) mCurrNode).getPublicId();
+        }
+        return null;
+    }
+
+    public String getDTDSystemId() {
+        if (mCurrEvent == DTD) {
+            return ((DocumentType) mCurrNode).getSystemId();
+        }
+        return null;
+    }
+
+    /**
+     * @return Internal subset portion of the DOCTYPE declaration, if any;
+     *   empty String if none
+     */
+    public String getDTDInternalSubset() {
+        /* DOM (level 3) doesn't expose anything extra; would need to
+         * synthetize subset... which would only contain some of the
+         * entity and notation declarations.
+         */
+        return null;
+    }
+
+    // // StAX2, v2.0
+
+    public DTDValidationSchema getProcessedDTDSchema() {
+        return null;
+    }
+
+    /*
+    ////////////////////////////////////////////////////
+    // LocationInfo implementation (StAX 2)
+    ////////////////////////////////////////////////////
+     */
+
+    // // // First, the "raw" offset accessors:
+
+    public long getStartingByteOffset() {
+        // !!! TBI
+        return -1L;
+    }
+
+    public long getStartingCharOffset() {
+        // !!! TBI
+        return 0;
+    }
+
+    public long getEndingByteOffset() throws XMLStreamException
+    {
+        // !!! TBI
+        return -1;
+    }
+
+    public long getEndingCharOffset() throws XMLStreamException
+    {
+        // !!! TBI
+        return -1;
+    }
+
+    // // // and then the object-based access methods:
+
+    public final Location getLocation() {
+        return getStartLocation();
+    }
+
+    public XMLStreamLocation2 getStartLocation()
+    {
+        // !!! TBI
+        return null;
+    }
+
+    public XMLStreamLocation2 getCurrentLocation()
+    {
+        // !!! TBI
+        return null;
+    }
+
+    public final XMLStreamLocation2 getEndLocation()
+        throws XMLStreamException
+    {
+        // !!! TBI
+        return null;
+    }
+
+    /*
+    ////////////////////////////////////////////////////
+    // Stax2 validation
+    ////////////////////////////////////////////////////
+     */
+
+    public XMLValidator validateAgainst(XMLValidationSchema schema)
+        throws XMLStreamException
+    {
+        // Not implemented by the basic reader:
+        return null;
+    }
+
+    public XMLValidator stopValidatingAgainst(XMLValidationSchema schema)
+        throws XMLStreamException
+    {
+        // Not implemented by the basic reader:
+        return null;
+    }
+
+    public XMLValidator stopValidatingAgainst(XMLValidator validator)
+        throws XMLStreamException
+    {
+        // Not implemented by the basic reader:
+        return null;
+    }
+
+    public ValidationProblemHandler setValidationProblemHandler(ValidationProblemHandler h)
+    {
+        // Not implemented by the basic reader
+        return null;
+    }
+
+    /*
+    ////////////////////////////////////////////
+    // Internal methods, text gathering
+    ////////////////////////////////////////////
+     */
+
+    protected void coalesceText(int initialType)
+    {
+        mTextBuffer.addText(mCurrNode.getNodeValue());
+
+        Node n;
+        while ((n = mCurrNode.getNextSibling()) != null) {
+            int type = n.getNodeType();
+            if (type != Node.TEXT_NODE && type != Node.CDATA_SECTION_NODE) {
+                break;
+            }
+            mCurrNode = n;
+            mTextBuffer.addText(mCurrNode.getNodeValue());
+        }
+        mCoalescedText = mTextBuffer.getAndClear();
+
+        // Either way, type gets always set to be CHARACTERS
+        mCurrEvent = CHARACTERS;
+    }
+
+    /*
+    ////////////////////////////////////////////
+    // Internal methods
+    ////////////////////////////////////////////
+     */
+
+    private QName constructQName(String uri, String ln, String prefix)
+    {
+        // Stupid QName impls barf on nulls...
+        return new QName((uri == null) ? "" : uri, ln,
+                         (prefix == null) ? "" : prefix);
+    }
+
+    /**
+     * @param attrsToo Whether to include actual attributes too, or
+     *   just namespace declarations
+     */
+    private void calcNsAndAttrLists(boolean attrsToo)
+    {
+        NamedNodeMap attrsIn = mCurrNode.getAttributes();
+        int len = attrsIn.getLength();
+        final boolean processInitialNamespace = (mCurrNode == mRootNode) && (mNsInitialMap != null);
+        if (!processInitialNamespace)
+        {
+            // A common case: neither attrs nor ns decls, can use short-cut
+            if (len == 0) {
+                mAttrList = mNsDeclList = Collections.EMPTY_LIST;
+                return;
+            }
+        }
+
+        if (!mNsAware) {
+            mAttrList = new ArrayList(len);
+            for (int i = 0; i < len; ++i) {
+                mAttrList.add(attrsIn.item(i));
+            }
+            mNsDeclList = Collections.EMPTY_LIST;
+            return;
+        }
+
+        // most should be attributes... and possibly no ns decls:
+        ArrayList attrsOut = null;
+        ArrayList nsOut = null;
+
+        for (int i = 0; i < len; ++i) {
+            Node attr = attrsIn.item(i);
+            String prefix = attr.getPrefix();
+
+            // Prefix?
+            if (prefix == null || prefix.length() == 0) { // nope
+                // default ns decl?
+                if (!"xmlns".equals(attr.getLocalName())) { // nope
+                    if (attrsToo) {
+                        if (attrsOut == null) {
+                            attrsOut = new ArrayList(len - i);
+                        }
+                        attrsOut.add(attr);
+                    }
+                    continue;
+                }
+                prefix = "";
+            } else { // explicit ns decl?
+                if (!"xmlns".equals(prefix)) { // nope
+                    if (attrsToo) {
+                        if (attrsOut == null) {
+                            attrsOut = new ArrayList(len - i);
+                        }
+                        attrsOut.add(attr);
+                    }
+                    continue;
+                }
+                prefix = attr.getLocalName();
+            }
+            if (nsOut == null) {
+                nsOut = new ArrayList((len - i) * 2);
+            }
+            nsOut.add(prefix);
+            nsOut.add(attr.getNodeValue());
+            if (processInitialNamespace)
+            {
+                mNsInitialMap.remove(prefix) ;
+            }
+        }
+        if (processInitialNamespace && mNsInitialMap.size() > 0)
+        {
+            if (nsOut == null)
+            {
+                nsOut = new ArrayList(mNsInitialMap.size() * 2) ;
+            }
+            Set<Map.Entry> entries = mNsInitialMap.entrySet();
+            for(Map.Entry entry: entries)
+            {
+                nsOut.add(entry.getKey()) ;
+                nsOut.add(entry.getValue()) ;
+            }
+        }
+
+        mAttrList = (attrsOut == null) ? Collections.EMPTY_LIST : attrsOut;
+        mNsDeclList = (nsOut == null) ? Collections.EMPTY_LIST : nsOut;
+    }
+
+    /**
+     * Method that returns location of the last character returned by this
+     * reader; that is, location "one less" than the currently pointed to
+     * location.
+     */
+    protected WstxInputLocation getLastCharLocation()
+    {
+        // !!! TBI
+        return null;
+    }
+
+    private void throwNotTextual(int type)
+    {
+        throw new IllegalStateException("Not a textual event ("
+                                        +ErrorConsts.tokenTypeDesc(mCurrEvent)+")");
+    }
+
+    private void throwParseError(String msg)
+        throws WstxParsingException
+    {
+        throw new WstxParsingException(msg, getLastCharLocation());
+    }
+
+    /*
+    private void throwParseError(String format, Object arg)
+        throws WstxParsingException
+    {
+        String msg = MessageFormat.format(format, new Object[] { arg });
+        throw new WstxParsingException(msg, getLastCharLocation());
+    }
+    */
+
+    private void handleIllegalAttrIndex(int index)
+    {
+        Element elem = (Element) mCurrNode;
+        NamedNodeMap attrs = elem.getAttributes();
+        int len = attrs.getLength();
+        String msg = "Illegal attribute index "+index+"; element <"+elem.getNodeName()+"> has "+((len == 0) ? "no" : String.valueOf(len))+" attributes";
+        throw new IllegalArgumentException(msg);
+    }
+
+    private void handleIllegalNsIndex(int index)
+    {
+        String msg = "Illegal namespace declaration index "+index+" (has "+getNamespaceCount()+" ns declarations)";
+        throw new IllegalArgumentException(msg);
+    }
+
+    /**
+     * Due to differences in how namespace-aware and non-namespace modes
+     * work in DOM, different methods are needed. We may or may not be
+     * able to detect namespace-awareness mode of the source Nodes
+     * directly; but at any rate, should contain some logic for handling
+     * problem cases.
+     */
+    private String safeGetLocalName(Node n)
+    {
+        String ln = n.getLocalName();
+        if (ln == null) {
+            ln = n.getNodeName();
+        }
+        return ln;
+    }
+}
+


Property changes on: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/wstx/ESBDOMWrappingReader.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/wstx/ESBDOMWrappingWriter.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/wstx/ESBDOMWrappingWriter.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/wstx/ESBDOMWrappingWriter.java	2010-02-01 16:54:25 UTC (rev 31341)
@@ -0,0 +1,567 @@
+/* Woodstox XML processor
+ *
+ * Copyright (c) 2004- Tatu Saloranta, tatu.saloranta at iki.fi
+ *
+ * Licensed under the License specified in the file LICENSE which is
+ * included with the source code.
+ * You may not use this file except in compliance with the License.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Copied from the Woodstox 3.2.8 codebase to fix an issue with the comment generation.
+ */
+package org.jboss.internal.soa.esb.util.wstx;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.*;
+import javax.xml.stream.*;
+import javax.xml.transform.dom.DOMResult;
+
+import org.w3c.dom.*;
+
+import org.codehaus.stax2.XMLStreamLocation2;
+import org.codehaus.stax2.XMLStreamReader2;
+import org.codehaus.stax2.XMLStreamWriter2;
+import org.codehaus.stax2.validation.ValidationProblemHandler;
+import org.codehaus.stax2.validation.XMLValidationSchema;
+import org.codehaus.stax2.validation.XMLValidator;
+
+import com.ctc.wstx.api.WriterConfig;
+import com.ctc.wstx.api.WstxOutputProperties;
+import com.ctc.wstx.util.EmptyNamespaceContext;
+
+/**
+ * This is an adapter class that allows building a DOM tree using
+ * {@link XMLStreamWriter} interface.
+ *<p>
+ * Note that the implementation is only to be used for use with
+ * <code>javax.xml.transform.dom.DOMResult</code>.
+ *<p>
+ * Some notes regarding missing/incomplete functionality:
+ * <ul>
+ *  </ul>
+ *
+ * @author Tatu Saloranta
+ * @author Dan Diephouse
+ */
+public class ESBDOMWrappingWriter
+    implements XMLStreamWriter2
+{
+    /*
+    ////////////////////////////////////////////////////
+    // Configuration
+    ////////////////////////////////////////////////////
+     */
+
+    protected final WriterConfig mConfig;
+
+    protected final boolean mNsAware;
+
+    protected final boolean mNsRepairing;
+
+    /**
+     * This member variable is to keep information about encoding
+     * that seems to be used for the document (or fragment) to output,
+     * if known.
+     */
+    protected String mEncoding = null;
+
+    /**
+     * If we are being given info about existing bindings, it'll come
+     * as a NamespaceContet.
+     */
+    protected NamespaceContext mNsContext;
+
+    /*
+    ////////////////////////////////////////////////////
+    // State
+    ////////////////////////////////////////////////////
+     */
+
+    /**
+     * We need a reference to the document hosting nodes to
+     * be able to create new nodes
+     */
+    protected final Document mDocument;
+
+    /**
+     * This element is the current context element, under which
+     * all other nodes are added, until matching end element
+     * is output. Null outside of the main element tree.
+     */
+    protected Element mParentElem;
+
+    /**
+     * This element is non-null right after a call to
+     * either <code>writeStartElement</code> and
+     * <code>writeEmptyElement</code>, and can be used to
+     * add attributes and namespace declarations.
+     */
+    protected Element mOpenElement;
+
+    /*
+    ////////////////////////////////////////////////////
+    // Life-cycle
+    ////////////////////////////////////////////////////
+     */
+
+    private ESBDOMWrappingWriter(WriterConfig cfg, Node treeRoot)
+        throws XMLStreamException
+    {
+        if (treeRoot == null) {
+            throw new IllegalArgumentException("Can not pass null Node for constructing a DOM-based XMLStreamWriter");
+        }
+        mConfig = cfg;
+        mNsAware = cfg.willSupportNamespaces();
+        mNsRepairing = mNsAware && cfg.automaticNamespacesEnabled();
+
+        /* 15-Sep-2007, TSa: Repairing mode not yet supported, so better
+         *   signal that right away
+         */
+        if (mNsRepairing) {
+            throw new XMLStreamException("Repairing mode not (yet) supported with DOM-backed writer");
+        }
+
+        Element elem = null;
+        
+        /* Ok; we need a document node; or an element node; or a document
+         * fragment node.
+         */
+        switch (treeRoot.getNodeType()) {
+        case Node.DOCUMENT_NODE: // fine
+            mDocument = (Document) treeRoot;
+
+            /* Should try to find encoding, version and stand-alone
+             * settings... but is there a standard way of doing that?
+             */
+            break;
+
+        case Node.ELEMENT_NODE: // can make sub-tree... ok
+            mDocument = treeRoot.getOwnerDocument();
+            elem = (Element) treeRoot;
+            break;
+
+        case Node.DOCUMENT_FRAGMENT_NODE: // as with element...
+            mDocument = treeRoot.getOwnerDocument();
+            // Above types are fine
+            break;
+
+        default: // other Nodes not usable
+            throw new XMLStreamException("Can not create an XMLStreamWriter for a DOM node of type "+treeRoot.getClass());
+        }
+        if (mDocument == null) {
+            throw new XMLStreamException("Can not create an XMLStreamWriter for given node (of type "+treeRoot.getClass()+"): did not have owner document");
+        }
+        mParentElem = mOpenElement = elem;
+    }
+
+    public static ESBDOMWrappingWriter createFrom(WriterConfig cfg, DOMResult dst)
+        throws XMLStreamException
+    {
+        Node rootNode = dst.getNode();
+        return new ESBDOMWrappingWriter(cfg, rootNode);
+    }
+
+    /*
+    ////////////////////////////////////////////////////
+    // XMLStreamWriter API (Stax 1.0)
+    ////////////////////////////////////////////////////
+     */
+
+    public void close() {
+        // NOP
+    }
+    
+    public void flush() {
+        // NOP
+    }
+
+    public NamespaceContext getNamespaceContext()
+    {
+        if (!mNsAware) {
+            return EmptyNamespaceContext.getInstance();
+        }
+        // !!! TBI: 
+        return mNsContext;
+    }
+
+    public String getPrefix(String uri)
+    {
+        if (!mNsAware) {
+            return null;
+        }
+        // !!! TBI: 
+        return null;
+    }
+
+    public Object getProperty(String name) {
+        // !!! TBI
+        return null;
+    }
+
+    public void setDefaultNamespace(String uri) {
+        // !!! TBI
+    }
+
+    public void setNamespaceContext(NamespaceContext context) {
+        mNsContext = context;
+    }
+
+    public void setPrefix(String prefix, String uri) {
+        // !!! TBI
+    }
+
+    public void writeAttribute(String localName, String value)
+    {
+        outputAttribute(null, null, localName, value);
+    }
+
+    public void writeAttribute(String nsURI, String localName, String value) {
+        outputAttribute(nsURI, null, localName, value);
+    }
+
+    public void writeAttribute(String prefix, String nsURI, String localName, String value)
+    {
+        outputAttribute(nsURI, prefix, localName, value);
+    }
+
+    public void writeCData(String data) {
+        appendLeaf(mDocument.createCDATASection(data));
+    }
+
+    public void writeCharacters(char[] text, int start, int len)
+    {
+        writeCharacters(new String(text, start, len));
+    }
+    
+    public void writeCharacters(String text) {
+        appendLeaf(mDocument.createTextNode(text));
+    }
+
+    public void writeComment(String data) {
+        appendLeaf(mDocument.createComment(data));
+    }
+
+    public void writeDefaultNamespace(String nsURI)
+    {
+        writeNamespace(null, nsURI);
+    }
+
+    public void writeDTD(String dtd)
+    {
+        // Would have to parse, not worth trying...
+        reportUnsupported("writeDTD()");
+    }
+
+    public void writeEmptyElement(String localName) {
+        writeEmptyElement(null, localName);
+    }
+
+    public void writeEmptyElement(String nsURI, String localName)
+    {
+        /* Note: can not just call writeStartElement(), since this
+         * element will only become the open elem, but not a parent elem
+         */
+        createStartElem(nsURI, null, localName, true);
+    }
+
+    public void writeEmptyElement(String prefix, String localName, String nsURI)
+    {
+        createStartElem(nsURI, prefix, localName, true);
+    }
+
+    public void writeEndDocument()
+    {
+        mParentElem = mOpenElement = null;
+    }
+
+    public void writeEndElement()
+    {
+        // Simple, just need to traverse up... if we can
+        if (mParentElem == null) {
+            throw new IllegalStateException("No open start element to close");
+        }
+        mOpenElement = null; // just in case it was open
+        Node parent = mParentElem.getParentNode();
+        mParentElem = (parent == mDocument) ? null : (Element) parent;
+    }
+
+    public void writeEntityRef(String name) {
+        appendLeaf(mDocument.createEntityReference(name));
+    }
+
+    public void writeNamespace(String prefix, String nsURI)
+    {
+        boolean defNS = (prefix == null || prefix.length() == 0);
+
+        if (!mNsAware) {
+            if (defNS) {
+                outputAttribute(null, null, "xmlns", nsURI);
+            } else {
+                outputAttribute(null, "xmlns", prefix, nsURI);
+            }
+        } else {
+            // !!! TBI
+            /* For now, let's output it (in non-repairing ns-aware
+             * mode), but not keep track of bindings.
+             */
+            if (defNS) {
+                outputAttribute(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, null, "xmlns", nsURI);
+            } else {
+                outputAttribute(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns", prefix, nsURI);
+            }
+        }
+    }
+
+    public void writeProcessingInstruction(String target) {
+        writeProcessingInstruction(target, null);
+    }
+
+    public void writeProcessingInstruction(String target, String data) {
+        appendLeaf(mDocument.createProcessingInstruction(target, data));
+    }
+
+    public void writeSpace(char[] text, int start, int len) {
+        writeSpace(new String(text, start, len));
+    }
+
+    public void writeSpace(String text) {
+        /* This won't work all that well, given there's no way to
+         * prevent quoting/escaping. But let's do what we can, since
+         * the alternative (throwing an exception) doesn't seem
+         * especially tempting choice.
+         */
+        writeCharacters(text);
+    }
+
+    public void writeStartDocument()
+    {
+        writeStartDocument(WstxOutputProperties.DEFAULT_OUTPUT_ENCODING,
+                           WstxOutputProperties.DEFAULT_XML_VERSION);
+    }
+
+    public void writeStartDocument(String version)
+    {
+        writeStartDocument(null, version);
+    }
+
+    public void writeStartDocument(String encoding, String version)
+    {
+        // Is there anything here we can or should do? No?
+        mEncoding = encoding;
+    }
+
+    public void writeStartElement(String localName) {
+        writeStartElement(null, localName);
+    }
+
+    public void writeStartElement(String nsURI, String localName)
+    {
+        createStartElem(nsURI, null, localName, false);
+    }
+
+    public void writeStartElement(String prefix, String localName, String nsURI)
+    {
+        createStartElem(nsURI, prefix, localName, false);
+    }
+
+    /*
+    ////////////////////////////////////////////////////
+    // XMLStreamWriter2 API (Stax2 v2.0)
+    ////////////////////////////////////////////////////
+     */
+
+    public boolean isPropertySupported(String name)
+    {
+        // !!! TBI: not all these properties are really supported
+        return mConfig.isPropertySupported(name);
+    }
+
+    public boolean setProperty(String name, Object value)
+    {
+        /* Note: can not call local method, since it'll return false for
+         * recognized but non-mutable properties
+         */
+        return mConfig.setProperty(name, value);
+    }
+
+    public XMLValidator validateAgainst(XMLValidationSchema schema)
+        throws XMLStreamException
+    {
+        // !!! TBI
+        return null;
+    }
+
+    public XMLValidator stopValidatingAgainst(XMLValidationSchema schema)
+        throws XMLStreamException
+    {
+        // !!! TBI
+        return null;
+    }
+
+    public XMLValidator stopValidatingAgainst(XMLValidator validator)
+        throws XMLStreamException
+    {
+        // !!! TBI
+        return null;
+    }
+
+    public ValidationProblemHandler setValidationProblemHandler(ValidationProblemHandler h)
+    {
+        // Not implemented by the basic reader
+        return null;
+    }
+
+    public XMLStreamLocation2 getLocation() {
+        return null;
+    }
+
+    public String getEncoding() {
+        return mEncoding;
+    }
+
+    public void writeCData(char[] text, int start, int len)
+        throws XMLStreamException
+    {
+        writeCData(new String(text, start, len));
+    }
+
+    public void writeDTD(String rootName, String systemId, String publicId,
+                         String internalSubset)
+        throws XMLStreamException
+    {
+        /* Alas: although we can create a DocumentType object, there
+         * doesn't seem to be a way to attach it in DOM-2!
+         */
+        if (mParentElem != null) {
+            throw new IllegalStateException("Operation only allowed to the document before adding root element");
+        }
+        reportUnsupported("writeDTD()");
+    }
+
+    public void writeFullEndElement() throws XMLStreamException
+    {
+        // No difference with DOM
+        writeEndElement();
+    }
+
+    public void writeStartDocument(String version, String encoding,
+                                   boolean standAlone)
+        throws XMLStreamException
+    {
+        writeStartDocument(encoding, version);
+    }
+    
+    /*
+    ///////////////////////////////
+    // Stax2, pass-through methods
+    ///////////////////////////////
+    */
+
+    public void writeRaw(String text)
+        throws XMLStreamException
+    {
+        reportUnsupported("writeRaw()");
+    }
+
+    public void writeRaw(String text, int start, int offset)
+        throws XMLStreamException
+    {
+        reportUnsupported("writeRaw()");
+    }
+
+    public void writeRaw(char[] text, int offset, int length)
+        throws XMLStreamException
+    {
+        reportUnsupported("writeRaw()");
+    }
+
+    public void copyEventFromReader(XMLStreamReader2 r, boolean preserveEventData)
+        throws XMLStreamException
+    {
+        // !!! TBI
+    }
+
+    /*
+    ///////////////////////////////
+    // Internal methods
+    ///////////////////////////////
+    */
+
+    protected void appendLeaf(Node n)
+        throws IllegalStateException
+    {
+        if (mParentElem == null) { // to add to document
+            mDocument.appendChild(n);
+        } else {
+            // Will also close the open element, if any
+            mOpenElement = null;
+            mParentElem.appendChild(n);
+        }
+    }
+
+    protected void createStartElem(String nsURI, String prefix, String localName, boolean isEmpty)
+    {
+        Element elem;
+
+        if (mNsAware) {
+            if (mNsRepairing) {
+                /* Need to ensure proper bindings... ugh.
+                 * May change prefix
+                 */
+                // !!! TBI
+            }
+            if (prefix != null && prefix.length() > 0) {
+                localName = prefix + ":" + localName;
+            }
+            elem = mDocument.createElementNS(nsURI, localName);
+        } else { // non-ns, simple
+            if (prefix != null && prefix.length() > 0) {
+                localName = prefix + ":" + localName;
+            }
+            elem = mDocument.createElement(localName);
+        }
+
+        appendLeaf(elem);
+        mOpenElement = elem;
+        if (!isEmpty) {
+            mParentElem = elem;
+        }
+    }
+
+    protected void outputAttribute(String nsURI, String prefix, String localName, String value)
+    {
+        if (mOpenElement == null) {
+            throw new IllegalStateException("No currently open START_ELEMENT, cannot write attribute");
+        }
+
+        if (mNsAware) {
+            if (mNsRepairing) {
+                /* Need to ensure proper bindings... ugh.
+                 * May change prefix
+                 */
+                // !!! TBI
+            }
+            if (prefix != null && prefix.length() > 0) {
+                localName = prefix + ":" + localName;
+            }
+            mOpenElement.setAttributeNS(nsURI, localName, value);
+        } else { // non-ns, simple
+            if (prefix != null && prefix.length() > 0) {
+                localName = prefix + ":" + localName;
+            }
+            mOpenElement.setAttribute(localName, value);
+        }
+    }
+
+    private void reportUnsupported(String operName)
+    {
+        throw new UnsupportedOperationException(operName+" can not be used with DOM-backed writer");
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/wstx/ESBDOMWrappingWriter.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/BaseWebService.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/BaseWebService.java	2010-02-01 16:39:20 UTC (rev 31340)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/BaseWebService.java	2010-02-01 16:54:25 UTC (rev 31341)
@@ -22,7 +22,6 @@
 package org.jboss.internal.soa.esb.webservice;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.ArrayList;
@@ -32,6 +31,7 @@
 import java.util.Set;
 
 import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.soap.Detail;
 import javax.xml.soap.Node;
 import javax.xml.soap.SOAPBody;
@@ -39,6 +39,10 @@
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPFault;
 import javax.xml.soap.SOAPMessage;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.ws.Provider;
 import javax.xml.ws.WebServiceException;
@@ -48,11 +52,11 @@
 import javax.xml.ws.addressing.soap.SOAPAddressingProperties;
 
 import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.util.XMLHelper;
 import org.jboss.soa.esb.client.ServiceInvoker;
 import org.jboss.soa.esb.common.Environment;
 import org.jboss.soa.esb.common.ModulePropertyManager;
 import org.jboss.soa.esb.couriers.FaultMessageException;
-import org.jboss.soa.esb.dom.YADOMUtil;
 import org.jboss.soa.esb.listeners.message.MessageDeliverException;
 import org.jboss.soa.esb.message.Body;
 import org.jboss.soa.esb.message.Fault;
@@ -138,10 +142,10 @@
                     {
                         throw new SOAPException("Found multiple SOAPElements in SOAPBody") ;
                     }
-                    final ByteArrayOutputStream byteStream = new ByteArrayOutputStream() ;
-                    YADOMUtil.serialize(node, new StreamResult(byteStream), true);
-                    byteStream.close();
-                    requestProxy.setPayload(esbReq, byteStream.toString()) ;
+                    final StringWriter sw = new StringWriter() ;
+                    final XMLEventWriter writer = XMLHelper.getXMLEventWriter(new StreamResult(sw)) ;
+                    XMLHelper.readDomNode(node, writer, true) ;
+                    requestProxy.setPayload(esbReq, sw.toString()) ;
                     found = true ;
                 }
             }
@@ -173,9 +177,9 @@
                 }
                 final String soapRes = input.toString();
 
-                final Document respDoc = YADOMUtil.parseStream(new ByteArrayInputStream(soapRes.getBytes()),
-                        false, false, true);
-                response.getSOAPBody().addDocument(respDoc) ;
+                final Document root = parseAsDom(soapRes) ;
+                
+                response.getSOAPBody().addDocument(root) ;
             }
             if (soapIncomingProps == null)
             {
@@ -221,8 +225,7 @@
                             {
                                 try
                                 {
-                                    final Document detailDoc = YADOMUtil.parseStream(new ByteArrayInputStream(faultDetail.getBytes()),
-                                            false, false, true);
+                                    final Document detailDoc = parseAsDom(faultDetail) ;
                                     final Detail detail = fault.addDetail() ;
                                     detail.appendChild(detailDoc.getDocumentElement()) ;
                                 }
@@ -253,6 +256,12 @@
         }
     }
 
+    private static Document parseAsDom(String soapRes) throws ParserConfigurationException, XMLStreamException
+    {
+        final XMLEventReader reader = XMLHelper.getXMLEventReader(new ByteArrayInputStream(soapRes.getBytes())) ;
+        return XMLHelper.createDocument(reader) ;
+    }
+
     protected AuthenticationRequest extractSecurityDetails(SOAPMessage request, Message esbReq) throws SecurityServiceException
     {
         try

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/XMLHelperUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/XMLHelperUnitTest.java	2010-02-01 16:39:20 UTC (rev 31340)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/XMLHelperUnitTest.java	2010-02-01 16:54:25 UTC (rev 31341)
@@ -20,8 +20,11 @@
  */
 package org.jboss.internal.soa.esb.util;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.InputStream;
 import java.io.StringWriter;
@@ -29,13 +32,21 @@
 import java.net.URL;
 import java.util.Properties;
 
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.stream.StreamResult;
 import javax.xml.validation.Schema;
 
 import junit.framework.JUnit4TestAdapter;
 
 import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.dom.YADOMUtil;
+import org.jboss.soa.esb.util.ClassUtil;
 import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
 /**
@@ -103,6 +114,69 @@
         assertTrue(XMLHelper.validate(schema, xml));
     }
     
+    @Test
+    public void testCopyWithDeclaration()
+        throws Exception
+    {
+        final InputStream is = ClassUtil.getResourceAsStream("copy_source.xml", getClass()) ;
+        final XMLEventReader reader = XMLHelper.getXMLEventReader(is) ;
+        final StringWriter sw = new StringWriter() ;
+        final XMLEventWriter writer = XMLHelper.getXMLEventWriter(sw) ;
+        XMLHelper.copyXMLEventStream(reader, writer) ;
+        final String copy = sw.toString() ;
+        assertTrue("Copy does not contain declaration", copy.contains("<?xml")) ;
+    }
+    
+    @Test
+    public void testCopyWithoutDeclaration()
+        throws Exception
+    {
+        final InputStream is = ClassUtil.getResourceAsStream("copy_source.xml", getClass()) ;
+        final XMLEventReader reader = XMLHelper.getXMLEventReader(is) ;
+        final StringWriter sw = new StringWriter() ;
+        final XMLEventWriter writer = XMLHelper.getXMLEventWriter(sw) ;
+        XMLHelper.copyXMLEventStream(reader, writer, true) ;
+        final String copy = sw.toString() ;
+        assertFalse("Copy contains declaration", copy.contains("<?xml")) ;
+    }
+
+    @Test
+    public void testSubDocumentParsing()
+        throws Exception
+    {
+        final InputStream is = ClassUtil.getResourceAsStream("copy_source.xml", getClass()) ;
+        final Document doc = YADOMUtil.parseStream(is, false, false, true) ;
+        final org.w3c.dom.Element root = doc.getDocumentElement() ;
+        
+        org.w3c.dom.Element body = null ;
+
+        final NodeList list = root.getChildNodes() ;
+        final int numChildren = list.getLength() ;
+        for(int count = 0 ; count < numChildren ; count++)
+        {
+            final org.w3c.dom.Node node = list.item(count) ;
+            if (node instanceof Element)
+            {
+                final org.w3c.dom.Element child = (org.w3c.dom.Element)node ;
+                if ("Body".equals(child.getLocalName()))
+                {
+                    body = child ;
+                }
+            }
+        }
+        
+        assertNotNull("body element is null", body) ;
+        
+        final StringWriter sw = new StringWriter() ;
+        final XMLEventWriter writer = XMLHelper.getXMLEventWriter(new StreamResult(sw)) ;
+        XMLHelper.readDomNode(body, writer, true) ;
+        
+        final String bodyVal = sw.toString() ;
+        
+        final XMLEventReader reader = XMLHelper.getXMLEventReader(new ByteArrayInputStream(bodyVal.getBytes())) ;
+        final Document document = XMLHelper.createDocument(reader) ;
+        assertNotNull("document is null", document) ;
+    }
     public static junit.framework.Test suite()
     {
         return new JUnit4TestAdapter(XMLHelperUnitTest.class);

Added: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/copy_source.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/copy_source.xml	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/copy_source.xml	2010-02-01 16:54:25 UTC (rev 31341)
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:body="http://www.example.com/ns/body">
+  <env:Header/>
+  <env:Body xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
+    <body:content xmlns:body="http://www.example.com/ns/body">
+      Text
+      <body:element>data</body:element>
+    </body:content>
+  </env:Body>
+</env:Envelope>


Property changes on: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/util/copy_source.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/soa/esb/testutils/jbr/StaticRequestResponseHandler.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/soa/esb/testutils/jbr/StaticRequestResponseHandler.java	2010-02-01 16:39:20 UTC (rev 31340)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/soa/esb/testutils/jbr/StaticRequestResponseHandler.java	2010-02-01 16:54:25 UTC (rev 31341)
@@ -21,11 +21,11 @@
 
 import junit.framework.TestCase;
 import org.jboss.internal.soa.esb.util.StreamUtils;
+import org.jboss.internal.soa.esb.util.XMLHelper;
 import org.jboss.remoting.InvocationRequest;
 import org.jboss.remoting.ServerInvocationHandler;
 import org.jboss.remoting.ServerInvoker;
 import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.soa.esb.testutils.StringUtils;
 
 import javax.management.MBeanServer;
 import java.io.IOException;
@@ -59,7 +59,7 @@
     public Object invoke(InvocationRequest invocationRequest) throws Throwable {
         if(expectedRequest != null) {
             String payload = (String) invocationRequest.getParameter();
-            TestCase.assertTrue(StringUtils.equalsIgnoreLinebreaks(expectedRequest, payload, false));
+            TestCase.assertTrue(XMLHelper.compareXMLContent(expectedRequest, payload));
         }
         return response;
     }

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java	2010-02-01 16:39:20 UTC (rev 31340)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java	2010-02-01 16:54:25 UTC (rev 31341)
@@ -41,6 +41,9 @@
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
@@ -67,7 +70,6 @@
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 import com.eviware.soapui.SoapUI;
@@ -451,7 +453,7 @@
     }
 
     private String buildSOAPMessage(String soapMessageTemplate, Map params, String smooksResource, String soapNs) throws IOException, SAXException {
-        Document messageDoc = getDocBuilder().parse(new InputSource(new StringReader(soapMessageTemplate)));
+        Document messageDoc = getDocument(soapMessageTemplate) ;
 
         Element docRoot = messageDoc.getDocumentElement();
 
@@ -481,22 +483,37 @@
         
         try
         {
-	        final StreamResult streamResult = new StreamResult(new StringWriter());
-            YADOMUtil.serialize(messageDoc, streamResult, true);
-	        return streamResult.getWriter().toString();
+            final StringWriter sw = new StringWriter() ;
+            final XMLEventWriter writer = XMLHelper.getXMLEventWriter(sw) ;
+            XMLHelper.readDomNode(docRoot, writer, true) ;
+	        return sw.toString();
         }
-        catch (ConfigurationException e)
+        catch (final XMLStreamException xmlse)
         {
-            throw new IllegalStateException(e.getMessage(), e);
+            final IOException ioe = new IOException("Failed to serialize the output SOAP message") ;
+            ioe.initCause(xmlse) ;
+            throw ioe ;
         }
     }
 
+    private Document getDocument(String soapMessageTemplate) throws IOException {
+        try {
+            final XMLEventReader reader = XMLHelper.getXMLEventReader(new StringReader(soapMessageTemplate)) ;
+            return XMLHelper.createDocument(reader) ;
+        } catch (final Exception ex) {
+            final IOException ioe = new IOException("Failed to deserialize the SOAP message template") ;
+            ioe.initCause(ex) ;
+            throw ioe ;
+        }
+    }
+
     private void dumpSOAP(String message, Element docRoot) {
         System.out.println("------------------------------------------------------------------------------------------------------------------------------------------");
         System.out.println(message + "\n");
         try {
-            YADOMUtil.serialize(docRoot, new StreamResult(System.out));
-        } catch (ConfigurationException e) {
+            final XMLEventWriter writer = XMLHelper.getXMLEventWriter(new StreamResult(System.out)) ;
+            XMLHelper.readDomNode(docRoot, writer, false) ;
+        } catch (Exception e) {
             logger.error("Unable to dump SOAP.", e);
         }
         System.out.println("------------------------------------------------------------------------------------------------------------------------------------------");



More information about the jboss-svn-commits mailing list