geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1145074 [1/2] - in /geronimo/bundles/trunk/axis2: ./ src/main/java/org/apache/axis2/jaxws/message/ src/main/java/org/apache/axis2/jaxws/message/databinding/impl/ src/main/java/org/apache/axis2/jaxws/message/impl/
Date Mon, 11 Jul 2011 08:57:25 GMT
Author: xuhaihong
Date: Mon Jul 11 08:57:25 2011
New Revision: 1145074

URL: http://svn.apache.org/viewvc?rev=1145074&view=rev
Log:
Try the fix of AXIS2-5023 (Ambigious use of isElementData in the Block interface) from Geronimo side

Added:
    geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/Block.java   (with props)
    geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/
    geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.java   (with props)
    geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java   (with props)
    geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/OMBlockImpl.java   (with props)
    geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockImpl.java   (with props)
    geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java   (with props)
    geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.java   (with props)
    geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/impl/
    geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/impl/BlockImpl.java   (with props)
    geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java   (with props)
Modified:
    geronimo/bundles/trunk/axis2/pom.xml

Modified: geronimo/bundles/trunk/axis2/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/pom.xml?rev=1145074&r1=1145073&r2=1145074&view=diff
==============================================================================
--- geronimo/bundles/trunk/axis2/pom.xml (original)
+++ geronimo/bundles/trunk/axis2/pom.xml Mon Jul 11 08:57:25 2011
@@ -313,7 +313,19 @@
                            org/apache/axis2/transport/http/HTTPSender.class=target/classes/org/apache/axis2/transport/http/HTTPSender.class,
                            org/apache/axis2/client/OperationClient.class=target/classes/org/apache/axis2/client/OperationClient.class,
                            org/apache/axis2/jaxws/description/impl/PostRI216MethodRetrieverImpl.class=target/classes/org/apache/axis2/jaxws/description/impl/PostRI216MethodRetrieverImpl.class,
-                           org/apache/axis2/jaxws/client/dispatch/BaseDispatch.class=target/classes/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.class
+                           org/apache/axis2/jaxws/client/dispatch/BaseDispatch.class=target/classes/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.class,
+                           
+                           org/apache/axis2/jaxws/message/Block.class=target/classes/org/apache/axis2/jaxws/message/Block.class,
+                           org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.class=target/classes/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.class,
+                           org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.class=target/classes/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.class,
+                           org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl$1.class=target/classes/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl$1.class,
+                           org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockImpl.class=target/classes/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockImpl.class,
+                           org/apache/axis2/jaxws/message/databinding/impl/OMBlockImpl.class=target/classes/org/apache/axis2/jaxws/message/databinding/impl/OMBlockImpl.class,
+                           org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.class=target/classes/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.class,
+                           org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.class=target/classes/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.class,
+                           org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl$1.class=target/classes/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl$1.class,
+                           org/apache/axis2/jaxws/message/impl/BlockImpl.class=target/classes/org/apache/axis2/jaxws/message/impl/BlockImpl.class,
+                           org/apache/axis2/jaxws/message/impl/XMLSpineImpl.class=target/classes/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.class
                         </Include-Resource>
                         <SPI-Provider>true</SPI-Provider>
                     </instructions>

Added: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/Block.java
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/Block.java?rev=1145074&view=auto
==============================================================================
--- geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/Block.java (added)
+++ geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/Block.java Mon Jul 11 08:57:25 2011
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package org.apache.axis2.jaxws.message;
+
+import org.apache.axiom.om.OMDataSourceExt;
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.jaxws.message.factory.BlockFactory;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.ws.WebServiceException;
+
+/**
+ * Block A Block represents an xml element and associated sub-tree. The name of the element must be
+ * defined by a root element in a schema. All prefixes within the subtree must correspond to
+ * namespace declarations defined within the tree. Many specifications refer to this as a "embedded
+ * document" or "xml block".  I chose the term, block, for simplicity.
+ * <p/>
+ * The block can be exposed as: * BusinessObject * StAX object
+ * <p/>
+ * Note that the whole Message can also be thought of as a Block.  Thus a Message can be createFrom
+ * a Block and written as a Block.
+ * <p/>
+ * In addition, each of the accessors has a consume parameter.  If consume is true, the Block is no
+ * longer valid after the message is called. (i.e. the implementation does not need to cache the
+ * information)
+ */
+public interface Block extends OMDataSourceExt {
+
+    /**
+     * Get a reference to the Business Object represented by this Block
+     *
+     * @param consume true if this is the last request on the block.
+     * @return Object (JAXB, String etc.)
+     * @throws XMLStreamException
+     * @throws WebServiceException
+     */
+    public Object getBusinessObject(boolean consume) throws XMLStreamException, WebServiceException;
+
+    /**
+     * GetBusinesContext Some business objects have an associated context object (i.e. JAXBContext)
+     *
+     * @return Context Object or null
+     */
+    public Object getBusinessContext();
+
+    /**
+     * Get the XMLStreamReader represented by this Block
+     *
+     * @param consume true if this is the last request on the block.
+     * @return XMLStreamReader
+     * @throws XMLStreamException
+     */
+    public XMLStreamReader getXMLStreamReader(boolean consume)
+            throws XMLStreamException, WebServiceException;
+
+    /**
+     * Get the OMElement represented by this Block. This call always consumes the block because you are
+     * taking control of the underlying OM
+     *
+     * @return
+     * @throws XMLStreamException
+     * @throws WebServiceException
+     */
+    public OMElement getOMElement() throws XMLStreamException, WebServiceException;
+
+    /**
+     * Write out the Block
+     *
+     * @param writer  XMLStreamWriter
+     * @param consume true if this is the last request on the block.
+     * @throws XMLStreamException
+     * @trhows WebServiceException
+     */
+    public void outputTo(XMLStreamWriter writer, boolean consume)
+            throws XMLStreamException, WebServiceException;
+
+    /**
+     * isConsumed Return true if the block is consumed.  Once consumed, the information in the block
+     * is no longer available.
+     *
+     * @return true if the block is consumed (a method was called with consume=true)
+     */
+    public boolean isConsumed();
+
+    /**
+     * Get a traceString...the trace string dumps the contents of the Block without forcing an
+     * underlying ill-performant transformation of the message.
+     *
+     * @return String containing trace information
+     * @boolean indent String containing indent characters
+     */
+    public String traceString(String indent);
+
+    /**
+     * @return If QName is available without doing an expensive parse of the business object, then
+     *         return true Otherwise return false Note: This method should be used in situations where
+     *         it would be nice to know the qname (like logging or a special check) but we don't want
+     *         to cause an ill-performant parse.
+     */
+    public boolean isQNameAvailable();
+
+    /**
+     * Get the QName (namespace, localpart) of the Block.  Do not depend on prefix being set correctly.
+     * Asking for the QName can cause a performant hit.
+     *
+     * @return QName of the block
+     * @throw WebServiceException
+     * @see isQNameAvailable
+     */
+    public QName getQName() throws WebServiceException;
+
+    /**
+     * Get BlockFactory
+     *
+     * @return BlockFactory that created the Block
+     */
+    public BlockFactory getBlockFactory();
+
+    /**
+     * Get the Message associated with this block
+     *
+     * @return Message
+     */
+    public Message getParent();
+
+    /**
+     * Set the Message associated with this block (This method is intended to be called by the
+     * Message Implementation only)
+     *
+     * @param parent
+     */
+    public void setParent(Message parent);
+
+    /**
+     * @return true if data is always an element; false if possibly mixed content or multiple
+     *         elements
+     */
+    public boolean isElementData();
+    
+    /**
+     * @return true if data is always one or multiple elements
+     */
+    public boolean isXMLData();
+}

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/Block.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/Block.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/Block.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.java
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.java?rev=1145074&view=auto
==============================================================================
--- geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.java (added)
+++ geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.java Mon Jul 11 08:57:25 2011
@@ -0,0 +1,289 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package org.apache.axis2.jaxws.message.databinding.impl;
+
+import org.apache.axiom.attachments.impl.BufferUtils;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axis2.datasource.SourceDataSource;
+import org.apache.axis2.java.security.AccessController;
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.jaxws.message.databinding.DataSourceBlock;
+import org.apache.axis2.jaxws.message.factory.BlockFactory;
+import org.apache.axis2.jaxws.message.impl.BlockImpl;
+import org.apache.axis2.jaxws.message.util.Reader2Writer;
+import org.apache.axis2.jaxws.utility.ConvertUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.activation.DataSource;
+import javax.mail.util.ByteArrayDataSource;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.ws.WebServiceException;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * SourceBlock
+ * <p/>
+ * Block containing a business object that is a javax.activation.DataSource
+ * <p/>
+ */
+public class DataSourceBlockImpl extends BlockImpl implements DataSourceBlock {
+
+    private static final Log log = LogFactory.getLog(DataSourceBlockImpl.class);
+
+    /**
+     * Constructor called from factory
+     *
+     * @param busObject
+     * @param qName
+     * @param factory
+     */
+    DataSourceBlockImpl(DataSource busObject, QName qName, BlockFactory factory)
+            throws WebServiceException {
+        super(busObject, null, qName, factory);
+        // Check validity of DataSource
+        if (!(busObject instanceof DataSource)) {
+            throw ExceptionFactory.makeWebServiceException(
+                    Messages.getMessage("SourceNotSupported", busObject.getClass().getName()));
+        }
+    }
+
+
+    /**
+     * Constructor called from factory
+     *
+     * @param reader
+     * @param qName
+     * @param factory
+     */
+    public DataSourceBlockImpl(OMElement omElement, QName qName, BlockFactory factory) {
+        super(omElement, null, qName, factory);
+    }
+
+    protected Object _getBOFromReader(XMLStreamReader reader, Object busContext) throws XMLStreamException, WebServiceException {
+        Reader2Writer r2w = new Reader2Writer(reader);
+        try {
+            return new ByteArrayDataSource(r2w.getAsString(), "application/octet-stream");
+        } catch (IOException e) {
+            throw new XMLStreamException(e);
+        }
+
+    }
+
+    public OMElement getOMElement() throws XMLStreamException, WebServiceException {
+        OMFactory factory = OMAbstractFactory.getOMFactory();
+        OMNamespace ns = factory.createOMNamespace("", "");
+        return factory.createOMElement(this, "dummy", ns);
+    }
+
+    @Override
+    protected Object _getBOFromOM(OMElement omElement, Object busContext)
+        throws XMLStreamException, WebServiceException {
+        Object busObject;
+        
+        // Shortcut to get business object from existing data source
+        if (omElement instanceof OMSourcedElement) {
+            OMDataSource ds = ((OMSourcedElement) omElement).getDataSource();
+            if (ds instanceof SourceDataSource) {
+                return ((SourceDataSource) ds).getObject();
+            }
+        }
+        
+        // If the message is a fault, there are some special gymnastics that we have to do
+        // to get this working for all of the handler scenarios.  
+        boolean hasFault = false;
+        if ((parent != null && parent.isFault()) || 
+            omElement.getQName().getLocalPart().equals(SOAP11Constants.SOAPFAULT_LOCAL_NAME)) {
+            hasFault = true;
+        }
+        
+        // Transform reader into business object
+        if (!hasFault) {
+            busObject = ((OMSourcedElement)omElement).getDataSource();
+        }
+        else {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            omElement.serialize(baos);
+            busObject = new ByteArrayDataSource(baos.toByteArray(), "UTF-8");
+        }
+        return busObject;
+    }
+
+    @Override
+    protected XMLStreamReader _getReaderFromBO(Object busObj, Object busContext)
+            throws XMLStreamException, WebServiceException {
+        try {
+            if (busObj instanceof DataSource) {
+                XMLInputFactory f = StAXUtils.getXMLInputFactory();
+
+                XMLStreamReader reader = f.createXMLStreamReader(((DataSource)busObj).getInputStream());
+                StAXUtils.releaseXMLInputFactory(f);
+                return reader;
+            }
+            throw ExceptionFactory.makeWebServiceException(
+                    Messages.getMessage("SourceNotSupported", busObject.getClass().getName()));
+        } catch (Exception e) {
+            String className = (busObj == null) ? "none" : busObj.getClass().getName();
+            throw ExceptionFactory
+                    .makeWebServiceException(Messages.getMessage("SourceReadErr", className), e);
+        }
+    }
+    
+    public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
+        try {
+            BufferUtils.inputStream2OutputStream(((DataSource)busObject).getInputStream(), output);
+        } catch (IOException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+    
+    @Override
+    protected void _outputFromBO(Object busObject, Object busContext, XMLStreamWriter writer)
+            throws XMLStreamException, WebServiceException {
+        // There is no fast way to output the Source to a writer, so get the reader
+        // and pass use the default reader->writer.
+        if (log.isDebugEnabled()) {
+            log.debug("Start _outputFromBO");
+        }
+        XMLStreamReader reader = _getReaderFromBO(busObject, busContext);
+        if (log.isDebugEnabled()) {
+            log.debug("Obtained reader=" + reader);
+        }
+        _outputFromReader(reader, writer);
+        if (log.isDebugEnabled()) {
+            log.debug("End _outputReaderFromBO");
+        }
+        // REVIEW Should we call close() on the Source ?
+    }
+
+
+    @Override
+    protected Object _getBOFromBO(Object busObject, Object busContext, boolean consume) {
+        if (consume) {
+            return busObject;
+        } else {
+            // TODO Missing Impl
+            throw ExceptionFactory.makeWebServiceException(
+                    Messages.getMessage("SourceMissingSupport", busObject.getClass().getName()));
+        }
+    }
+
+    public boolean isElementData() {
+        return false;  // The source could be a text or element etc.
+    }
+    
+    public boolean isXMLData() {
+        return false;
+    }
+
+    /**
+     * Return the class for this name
+     * @return Class
+     */
+    private static Class forName(final String className) throws ClassNotFoundException {
+        // NOTE: This method must remain private because it uses AccessController
+        Class cl = null;
+        try {
+            cl = (Class)AccessController.doPrivileged(
+                    new PrivilegedExceptionAction() {
+                        public Object run() throws ClassNotFoundException {
+                            return Class.forName(className);
+                        }
+                    }
+            );
+        } catch (PrivilegedActionException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("Exception thrown from AccessController: " + e);
+            }
+            throw (ClassNotFoundException)e.getException();
+        }
+
+        return cl;
+    }
+    
+    
+    public void close() {
+        return; // Nothing to close
+    }
+
+    public InputStream getXMLInputStream(String encoding) throws UnsupportedEncodingException {
+        try {
+            byte[] bytes = (byte[]) 
+                ConvertUtils.convert(getBusinessObject(false), byte[].class);
+            return new ByteArrayInputStream(bytes);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+
+    public Object getObject() {
+        try {
+            return getBusinessObject(false);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+
+    public boolean isDestructiveRead() {
+        return true;
+    }
+
+    public boolean isDestructiveWrite() {
+        return true;
+    }
+
+
+    public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
+        if (log.isDebugEnabled()) {
+            log.debug("Start getXMLBytes");
+        }
+        byte[] bytes = null;
+        try {
+            bytes = (byte[]) 
+                ConvertUtils.convert(getBusinessObject(false), byte[].class);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+        if (log.isDebugEnabled()) {
+            log.debug("End getXMLBytes");
+        }
+        return bytes;
+    }
+}
\ No newline at end of file

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java?rev=1145074&view=auto
==============================================================================
--- geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java (added)
+++ geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java Mon Jul 11 08:57:25 2011
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package org.apache.axis2.jaxws.message.databinding.impl;
+
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMDataSourceExt;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.OMXMLStreamReader;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axis2.datasource.jaxb.JAXBDSContext;
+import org.apache.axis2.datasource.jaxb.JAXBDataSource;
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.message.Message;
+import org.apache.axis2.jaxws.message.databinding.JAXBBlock;
+import org.apache.axis2.jaxws.message.databinding.JAXBBlockContext;
+import org.apache.axis2.jaxws.message.factory.BlockFactory;
+import org.apache.axis2.jaxws.message.impl.BlockImpl;
+import org.apache.axis2.jaxws.message.util.XMLStreamWriterWithOS;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.ws.WebServiceException;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * JAXBBlockImpl <p/> A Block containing a JAXB business object (either a JAXBElement or an object
+ * with @XmlRootElement).
+ */
+public class JAXBBlockImpl extends BlockImpl implements JAXBBlock {
+
+    private static final Log log = LogFactory.getLog(JAXBBlockImpl.class);
+
+    private static final boolean DEBUG_ENABLED = log.isDebugEnabled();
+
+    /**
+     * Called by JAXBBlockFactory
+     * 
+     * @param busObject..The business object must be a JAXBElement or an object with an
+     * @XMLRootElement. This is assertion is validated in the JAXBFactory.
+     * @param busContext
+     * @param qName QName must be non-null
+     * @param factory
+     */
+    JAXBBlockImpl(Object busObject, JAXBBlockContext busContext, QName qName, 
+                  BlockFactory factory)
+            throws JAXBException {
+        super(busObject, busContext, qName, factory);
+    }
+
+    /**
+     * Called by JAXBBlockFactory
+     * 
+     * @param omelement
+     * @param busContext
+     * @param qName must be non-null
+     * @param factory
+     */
+    JAXBBlockImpl(OMElement omElement, JAXBBlockContext busContext, QName qName,
+            BlockFactory factory) {
+        super(omElement, busContext, qName, factory);
+    }
+
+    protected Object _getBOFromReader(XMLStreamReader reader, Object busContext)
+        throws XMLStreamException, WebServiceException {
+        // Get the JAXBBlockContext. All of the necessry information is recorded on it
+        JAXBBlockContext ctx = (JAXBBlockContext) busContext;
+        
+        try {
+            busObject = ctx.unmarshal(reader);
+        } catch (JAXBException je) {
+            if (DEBUG_ENABLED) {
+                try {
+                    log.debug("JAXBContext for unmarshal failure:" + 
+                              ctx.getJAXBContext(ctx.getClassLoader()));
+                } catch (Exception e) {
+                }
+            }
+            throw ExceptionFactory.makeWebServiceException(je);
+        }
+        return busObject;
+    }
+    
+    @Override
+    protected Object _getBOFromOM(OMElement omElement, Object busContext)
+        throws XMLStreamException, WebServiceException {
+        
+        // Shortcut to get business object from existing data source
+        if (omElement instanceof OMSourcedElement) {
+            OMDataSource ds = ((OMSourcedElement) omElement).getDataSource();
+            if (ds instanceof JAXBDataSource) {
+                // Update the business context to use the one provided
+                // by the datasource
+                try {
+                    JAXBDSContext dsContext = ((JAXBDataSource) ds).getContext();
+                    busContext = new JAXBBlockContext(dsContext.getJAXBContext());
+                } catch (JAXBException e) {
+                    throw ExceptionFactory.makeWebServiceException(e);
+                }
+                return ((JAXBDataSource) ds).getObject();
+            } else if (ds instanceof JAXBBlockImpl) {
+                // Update the business context to use the one provided by the
+                // by the datasource
+                JAXBBlockContext blockContext = (JAXBBlockContext) ((JAXBBlockImpl) ds).getBusinessContext();
+                busContext = blockContext;
+
+                return ((JAXBBlockImpl) ds).getObject();
+            }
+        }
+        return super._getBOFromOM(omElement, busContext);
+    }
+
+    /**
+     * @param busObj
+     * @param busContext
+     * @return
+     * @throws XMLStreamException
+     * @throws WebServiceException
+     */
+    private byte[] _getBytesFromBO(Object busObj, Object busContext, String encoding)
+        throws XMLStreamException, WebServiceException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+        // Exposes getOutputStream, which allows faster writes.
+        XMLStreamWriterWithOS writer = new XMLStreamWriterWithOS(baos, encoding);
+
+        // Write the business object to the writer
+        _outputFromBO(busObj, busContext, writer);
+
+        // Flush the writer
+        writer.flush();
+        writer.close();
+        return baos.toByteArray();
+    }
+
+
+    @Override
+    protected XMLStreamReader _getReaderFromBO(Object busObj, Object busContext)
+        throws XMLStreamException, WebServiceException {
+        ByteArrayInputStream baos =
+                new ByteArrayInputStream(_getBytesFromBO(busObj, busContext, "utf-8"));
+        return StAXUtils.createXMLStreamReader(baos, "utf-8");
+    }
+    
+    protected XMLStreamReader _getReaderFromOM(OMElement omElement) {
+        XMLStreamReader reader;
+        if (omElement.getBuilder() != null && !omElement.getBuilder().isCompleted()) {
+            reader = omElement.getXMLStreamReaderWithoutCaching();
+        } else {
+            reader = omElement.getXMLStreamReader();
+        }
+        if (reader instanceof OMXMLStreamReader) {
+            ((OMXMLStreamReader)reader).setInlineMTOM(false);  // Optimize attachment usage
+        }
+        return reader;
+    }
+
+    protected void _outputFromBO(Object busObject, Object busContext, XMLStreamWriter writer)
+        throws XMLStreamException, WebServiceException {
+        JAXBBlockContext ctx = (JAXBBlockContext) busContext;
+        
+        try {
+            ctx.marshal(busObject, writer);
+        } catch (JAXBException je) {
+            if (DEBUG_ENABLED) {
+                try {
+                    log.debug("JAXBContext for marshal failure:" + 
+                              ctx.getJAXBContext(ctx.getClassLoader()));
+                } catch (Exception e) {
+                }
+            }
+            throw ExceptionFactory.makeWebServiceException(je);
+        }
+    }
+
+    public boolean isElementData() {
+        return true;
+    }
+    
+    public boolean isXMLData() {
+        return true;
+    }
+    
+    public void close() {
+        return; // Nothing to close
+    }
+
+    public InputStream getXMLInputStream(String encoding) throws UnsupportedEncodingException {
+        try {
+            byte[] bytes= _getBytesFromBO(
+                                          getBusinessObject(false), 
+                                          busContext, 
+                                          encoding);
+            return new ByteArrayInputStream(bytes);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+
+    public Object getObject() {
+        try {
+            return getBusinessObject(false);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+
+    public boolean isDestructiveRead() {
+        return false;
+    }
+
+    public boolean isDestructiveWrite() {
+        return false;
+    }
+    
+    public OMDataSourceExt copy() throws OMException {
+        
+        if (DEBUG_ENABLED) {
+            log.debug("Making a copy of the JAXB object");
+        }
+        return new JAXBDataSource(this.getObject(), 
+                                  (JAXBDSContext) this.getBusinessContext());
+    }
+
+    public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
+        try {
+            return _getBytesFromBO(getBusinessObject(false), 
+                                   busContext, 
+                                   encoding);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+
+    public void setParent(Message message) {
+        if (busContext != null) {
+            ((JAXBBlockContext) busContext).setMessage(message);
+        }
+        super.setParent(message);
+    }
+
+    
+
+}

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/OMBlockImpl.java
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/OMBlockImpl.java?rev=1145074&view=auto
==============================================================================
--- geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/OMBlockImpl.java (added)
+++ geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/OMBlockImpl.java Mon Jul 11 08:57:25 2011
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package org.apache.axis2.jaxws.message.databinding.impl;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.message.databinding.OMBlock;
+import org.apache.axis2.jaxws.message.factory.BlockFactory;
+import org.apache.axis2.jaxws.message.impl.BlockImpl;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.ws.WebServiceException;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+/** OMBlockImpl Block with a business object that is an OMElement */
+public class OMBlockImpl extends BlockImpl implements OMBlock {
+
+
+    /**
+     * Called by OMBlockFactory
+     *
+     * @param busObject
+     * @param factory
+     */
+    OMBlockImpl(OMElement busObject, BlockFactory factory) {
+        super(busObject,
+              null,
+              busObject.getQName(),
+              factory);
+    }
+
+    @Override
+    protected Object _getBOFromReader(XMLStreamReader reader, Object busContext)
+            throws XMLStreamException, WebServiceException {
+        // Take a shortcut and return the OMElement
+        return this.getOMElement();
+    }
+
+    @Override
+    protected XMLStreamReader _getReaderFromBO(Object busObj, Object busContext)
+            throws XMLStreamException, WebServiceException {
+        OMElement om = (OMElement)busObj;
+        return om.getXMLStreamReader();
+    }
+    
+    @Override
+    protected Object _getBOFromOM(OMElement om, Object busContext)
+        throws XMLStreamException, WebServiceException {
+        return om;
+    }
+    
+    @Override
+    protected OMElement _getOMFromBO(Object busObject, Object busContext)
+        throws XMLStreamException, WebServiceException {
+        return (OMElement) busObject;
+    }
+
+    @Override
+    protected void _outputFromBO(Object busObject, Object busContext, XMLStreamWriter writer)
+            throws XMLStreamException, WebServiceException {
+        OMElement om = (OMElement)busObject;
+        om.serialize(writer);
+    }
+
+    public boolean isElementData() {
+        return true;
+    }
+    
+    public boolean isXMLData() {
+        return true;
+    }
+    
+    public void close() {
+        return; // Nothing to close
+    }
+
+    public InputStream getXMLInputStream(String encoding) throws UnsupportedEncodingException {
+        byte[] bytes = getXMLBytes(encoding);
+        return new ByteArrayInputStream(bytes);
+    }
+
+    public Object getObject() {
+        try {
+            return getBusinessObject(false);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+
+    public boolean isDestructiveRead() {
+        return false;
+    }
+
+    public boolean isDestructiveWrite() {
+        return false;
+    }
+
+    public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        OMOutputFormat format = new OMOutputFormat();
+        format.setCharSetEncoding(encoding);
+        try {
+            serialize(baos, format);
+            baos.flush();
+            return baos.toByteArray();
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        } catch (IOException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+}

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/OMBlockImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/OMBlockImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/OMBlockImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockImpl.java
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockImpl.java?rev=1145074&view=auto
==============================================================================
--- geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockImpl.java (added)
+++ geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockImpl.java Mon Jul 11 08:57:25 2011
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+/**
+ * 
+ */
+package org.apache.axis2.jaxws.message.databinding.impl;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.message.Message;
+import org.apache.axis2.jaxws.message.databinding.SOAPEnvelopeBlock;
+import org.apache.axis2.jaxws.message.factory.BlockFactory;
+import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.message.impl.BlockImpl;
+import org.apache.axis2.jaxws.message.util.SOAPElementReader;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.ws.WebServiceException;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * 
+ *
+ */
+public class SOAPEnvelopeBlockImpl extends BlockImpl implements SOAPEnvelopeBlock {
+
+    /**
+     * Called by SOAPEnvelopeBlockFactory
+     *
+     * @param busObject
+     * @param busContext
+     * @param qName
+     * @param factory
+     */
+    public SOAPEnvelopeBlockImpl(Object busObject, Object busContext,
+                                 QName qName, BlockFactory factory) {
+        super(busObject,
+              busContext,
+              (qName == null) ? getQName((SOAPEnvelope)busObject) : qName,
+              factory);
+    }
+
+    /**
+     * Called by SOAPEnvelopeBlockFactory
+     *
+     * @param omElement
+     * @param busContext
+     * @param qName
+     * @param factory
+     */
+    public SOAPEnvelopeBlockImpl(OMElement omElement, Object busContext,
+                                 QName qName, BlockFactory factory) {
+        super(omElement, busContext, qName, factory);
+    }
+
+    /* (non-Javadoc)
+      * @see org.apache.axis2.jaxws.message.impl.BlockImpl#_getBOFromReader(javax.xml.stream.XMLStreamReader, java.lang.Object)
+      */
+    @Override
+    protected Object _getBOFromReader(XMLStreamReader reader, Object busContext)
+            throws XMLStreamException, WebServiceException {
+        MessageFactory mf = (MessageFactory)FactoryRegistry.getFactory(MessageFactory.class);
+        Message message = mf.createFrom(reader, null);
+        SOAPEnvelope env = message.getAsSOAPEnvelope();
+        this.setQName(getQName(env));
+        return env;
+    }
+
+    /* (non-Javadoc)
+      * @see org.apache.axis2.jaxws.message.impl.BlockImpl#_getReaderFromBO(java.lang.Object, java.lang.Object)
+      */
+    @Override
+    protected XMLStreamReader _getReaderFromBO(Object busObj, Object busContext)
+            throws XMLStreamException, WebServiceException {
+        return new SOAPElementReader((SOAPElement)busObj);
+    }
+
+    /* (non-Javadoc)
+      * @see org.apache.axis2.jaxws.message.impl.BlockImpl#_outputFromBO(java.lang.Object, java.lang.Object, javax.xml.stream.XMLStreamWriter)
+      */
+    @Override
+    protected void _outputFromBO(Object busObject, Object busContext,
+                                 XMLStreamWriter writer)
+            throws XMLStreamException, WebServiceException {
+        XMLStreamReader reader = _getReaderFromBO(busObject, busContext);
+        _outputFromReader(reader, writer);
+    }
+
+    /**
+     * Get the QName of the envelope
+     *
+     * @param env
+     * @return QName
+     */
+    private static QName getQName(SOAPEnvelope env) {
+        return new QName(env.getNamespaceURI(), env.getLocalName(), env.getPrefix());
+    }
+
+    public boolean isElementData() {
+        return true;
+    }
+    
+    public boolean isXMLData() {
+        return true;
+    }
+    
+    public void close() {
+        return; // Nothing to close
+    }
+
+    public InputStream getXMLInputStream(String encoding) throws UnsupportedEncodingException {
+        byte[] bytes = getXMLBytes(encoding);
+        return new ByteArrayInputStream(bytes);
+    }
+
+    public Object getObject() {
+        try {
+            return getBusinessObject(false);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+
+    public boolean isDestructiveRead() {
+        return false;
+    }
+
+    public boolean isDestructiveWrite() {
+        return false;
+    }
+
+    public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        OMOutputFormat format = new OMOutputFormat();
+        format.setCharSetEncoding(encoding);
+        try {
+            serialize(baos, format);
+            baos.flush();
+            return baos.toByteArray();
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        } catch (IOException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+}

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SOAPEnvelopeBlockImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java?rev=1145074&view=auto
==============================================================================
--- geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java (added)
+++ geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java Mon Jul 11 08:57:25 2011
@@ -0,0 +1,378 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package org.apache.axis2.jaxws.message.databinding.impl;
+
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axis2.datasource.SourceDataSource;
+import org.apache.axis2.java.security.AccessController;
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.jaxws.message.databinding.SourceBlock;
+import org.apache.axis2.jaxws.message.factory.BlockFactory;
+import org.apache.axis2.jaxws.message.impl.BlockImpl;
+import org.apache.axis2.jaxws.message.util.Reader2Writer;
+import org.apache.axis2.jaxws.utility.ConvertUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.bind.util.JAXBSource;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.WebServiceException;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * SourceBlock
+ * <p/>
+ * Block containing a business object that is a javax.xml.transform.Source.
+ * <p/>
+ * The javax.xml.transform.Source is an interface.  The actual concrete class may be one of the
+ * following: - StreamSource - DOMSource - JAXBSource - SAXSource - StAXSource
+ * <p/>
+ * During processing of the block, the block is free to change the representation from one source
+ * to another.  (i.e. if you initially seed this with a SAXSource, but a later access may give you
+ * a StAXSource).
+ * <p/>
+ * A Source is consumed when read.  The block will make a copy of the source if a non-consumable
+ * request is made.
+ */
+public class SourceBlockImpl extends BlockImpl implements SourceBlock {
+
+    private static final Log log = LogFactory.getLog(SourceBlockImpl.class);
+    private static Class staxSource = null;
+
+    static {
+        try {
+            // Dynamically discover if StAXSource is available
+            staxSource = forName("javax.xml.transform.stax.StAXSource");
+        } catch (Exception e) {
+            if (log.isDebugEnabled()) {
+                log.debug("StAXSource is not present in the JDK.  " +
+                                "This is acceptable.  Processing continues");
+            }
+        }
+        try {
+            // Woodstox does not work with StAXSource
+            if(XMLInputFactory.newInstance().getClass().getName().indexOf("wstx")!=-1){
+                staxSource = null;
+            }
+        } catch (Exception e){
+        }
+    }
+
+    /**
+     * Constructor called from factory
+     *
+     * @param busObject
+     * @param qName
+     * @param factory
+     */
+    SourceBlockImpl(Source busObject, QName qName, BlockFactory factory)
+            throws WebServiceException {
+        super(busObject, null, qName, factory);
+
+        // Check validity of Source
+        if (busObject instanceof DOMSource ||
+                busObject instanceof SAXSource ||
+                busObject instanceof StreamSource ||
+                (busObject.getClass().equals(staxSource)) ||
+                busObject instanceof JAXBSource) {
+            // Okay, these are supported Source objects
+            if (log.isDebugEnabled()) {
+                log.debug("data object is a " + busObject.getClass().getName());
+            }
+        } else {
+            throw ExceptionFactory.makeWebServiceException(
+                    Messages.getMessage("SourceNotSupported", busObject.getClass().getName()));
+        }
+    }
+
+
+    /**
+     * Constructor called from factory
+     *
+     * @param reader
+     * @param qName
+     * @param factory
+     */
+    public SourceBlockImpl(OMElement omElement, QName qName, BlockFactory factory) {
+        super(omElement, null, qName, factory);
+    }
+
+    @Override
+    protected Object _getBOFromReader(XMLStreamReader reader, Object busContext)
+            throws XMLStreamException {
+
+        // Best solution is to use a StAXSource
+        // However StAXSource is not widely accepted.  
+        // For now, a StreamSource is always returned
+        /*
+        if (staxSource != null) {
+            try {
+                // TODO Constructor should be statically cached for performance
+                Constructor c =
+                        staxSource.getDeclaredConstructor(new Class[] { XMLStreamReader.class });
+                return c.newInstance(new Object[] { reader });
+            } catch (Exception e) {
+            }
+        }
+        */
+
+        // TODO StreamSource is not performant...work is needed here to make this faster
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String text = r2w.getAsString();
+        StringReader sr = new StringReader(text);
+        return new StreamSource(sr);
+
+    }
+    
+    @Override
+    protected Object _getBOFromOM(OMElement omElement, Object busContext)
+        throws XMLStreamException, WebServiceException {
+        Object busObject;
+        
+        // Shortcut to get business object from existing data source
+        if (omElement instanceof OMSourcedElement) {
+            OMDataSource ds = ((OMSourcedElement) omElement).getDataSource();
+            if (ds instanceof SourceDataSource) {
+                return ((SourceDataSource) ds).getObject();
+            }
+        }
+        
+        // If the message is a fault, there are some special gymnastics that we have to do
+        // to get this working for all of the handler scenarios.  
+        boolean hasFault = false;
+        if ((parent != null && parent.isFault()) || 
+            omElement.getQName().getLocalPart().equals(SOAP11Constants.SOAPFAULT_LOCAL_NAME)) {
+            hasFault = true;
+        }
+        
+        // Transform reader into business object
+        if (!hasFault) {
+            busObject = super._getBOFromOM(omElement, busContext);
+        }
+        else {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            omElement.serialize(baos);
+            
+            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+            busObject = new StreamSource(bais);
+        }
+        return busObject;
+    }
+
+    @Override
+    protected XMLStreamReader _getReaderFromBO(Object busObj, Object busContext)
+            throws XMLStreamException, WebServiceException {
+        try {
+            // TODO not sure if this is always the most performant way to do this.
+            /* The following code failed in some (CTS) environments. 
+	        if (busObj instanceof DOMSource) {
+	            // Let's use our own DOMReader for now...
+	            Element element = null;
+	            
+	            // Business Object msut be a Document or Element
+	            Node node = ((DOMSource)busObj).getNode();
+	            if(node instanceof Document){
+	                element = ((Document)node).getDocumentElement();
+	            }else{
+	                element = (Element) ((DOMSource)busObj).getNode();
+	            }
+	            
+	            // We had some problems with testers producing DOMSources w/o Namespaces.  
+	            // It's easy to catch this here.
+	            if (element.getLocalName() == null) {
+	                throw new XMLStreamException(ExceptionFactory.
+                           makeWebServiceException(Messages.getMessage("JAXBSourceNamespaceErr")));
+	            }
+	            
+	            return new DOMReader(element);
+	        } 
+            */
+
+            if (busObj instanceof StreamSource) {
+                XMLInputFactory f = StAXUtils.getXMLInputFactory();
+
+                XMLStreamReader reader = f.createXMLStreamReader((Source)busObj);
+                StAXUtils.releaseXMLInputFactory(f);
+                return reader;
+            }
+            //TODO: For GM we need to only use this approach when absolutely necessary.
+            // For example, we don't want to do this if this is a (1.6) StaxSource or if the 
+            // installed parser provides a better solution.
+            //TODO: Uncomment this code if woodstock parser handles 
+            // JAXBSource and SAXSource correctly.
+            //return inputFactory.createXMLStreamReader((Source) busObj);
+            return _slow_getReaderFromSource((Source)busObj);
+        } catch (Exception e) {
+            String className = (busObj == null) ? "none" : busObj.getClass().getName();
+            throw ExceptionFactory
+                    .makeWebServiceException(Messages.getMessage("SourceReadErr", className), e);
+        }
+    }
+
+    /** Creates an XMLStreamReader from a Source using a slow but proven algorithm. */
+    private XMLStreamReader _slow_getReaderFromSource(Source src) throws XMLStreamException {
+        if (log.isDebugEnabled()) {
+            log.debug("Start _slow_getReaderFromSource");
+        }
+        byte[] bytes = (byte[]) ConvertUtils.convert(src, byte[].class);
+        if (log.isDebugEnabled()) {
+            log.debug("Successfully converted to ByteArray");
+        }
+        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+        XMLStreamReader reader = StAXUtils.createXMLStreamReader(bais);
+        if (log.isDebugEnabled()) {
+            log.debug("End _slow_getReaderFromSource =" + reader);
+        }
+        return reader;
+    }
+
+    @Override
+    protected void _outputFromBO(Object busObject, Object busContext, XMLStreamWriter writer)
+            throws XMLStreamException, WebServiceException {
+        // There is no fast way to output the Source to a writer, so get the reader
+        // and pass use the default reader->writer.
+        if (log.isDebugEnabled()) {
+            log.debug("Start _outputFromBO");
+        }
+        XMLStreamReader reader = _getReaderFromBO(busObject, busContext);
+        if (log.isDebugEnabled()) {
+            log.debug("Obtained reader=" + reader);
+        }
+        _outputFromReader(reader, writer);
+        if (log.isDebugEnabled()) {
+            log.debug("End _outputReaderFromBO");
+        }
+        // REVIEW Should we call close() on the Source ?
+    }
+
+
+    @Override
+    protected Object _getBOFromBO(Object busObject, Object busContext, boolean consume) {
+        if (consume) {
+            return busObject;
+        } else {
+            // TODO Missing Impl
+            throw ExceptionFactory.makeWebServiceException(
+                    Messages.getMessage("SourceMissingSupport", busObject.getClass().getName()));
+        }
+    }
+
+
+    public boolean isElementData() {
+        return false;  // The source could be a text or element etc.
+    }
+
+    public boolean isXMLData() {
+        return true;
+    }
+    
+    /**
+     * Return the class for this name
+     * @return Class
+     */
+    private static Class forName(final String className) throws ClassNotFoundException {
+        // NOTE: This method must remain private because it uses AccessController
+        Class cl = null;
+        try {
+            cl = (Class)AccessController.doPrivileged(
+                    new PrivilegedExceptionAction() {
+                        public Object run() throws ClassNotFoundException {
+                            return Class.forName(className);
+                        }
+                    }
+            );
+        } catch (PrivilegedActionException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("Exception thrown from AccessController: " + e);
+            }
+            throw (ClassNotFoundException)e.getException();
+        }
+
+        return cl;
+    }
+    
+    
+    public void close() {
+        return; // Nothing to close
+    }
+
+    public InputStream getXMLInputStream(String encoding) throws UnsupportedEncodingException {
+        try {
+            byte[] bytes = (byte[]) 
+                ConvertUtils.convert(getBusinessObject(false), byte[].class);
+            return new ByteArrayInputStream(bytes);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+
+    public Object getObject() {
+        try {
+            return getBusinessObject(false);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+
+    public boolean isDestructiveRead() {
+        return true;
+    }
+
+    public boolean isDestructiveWrite() {
+        return true;
+    }
+
+
+    public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
+        if (log.isDebugEnabled()) {
+            log.debug("Start getXMLBytes");
+        }
+        byte[] bytes = null;
+        try {
+            bytes = (byte[]) 
+                ConvertUtils.convert(getBusinessObject(false), byte[].class);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+        if (log.isDebugEnabled()) {
+            log.debug("End getXMLBytes");
+        }
+        return bytes;
+    }
+}

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/SourceBlockImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.java
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.java?rev=1145074&view=auto
==============================================================================
--- geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.java (added)
+++ geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.java Mon Jul 11 08:57:25 2011
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package org.apache.axis2.jaxws.message.databinding.impl;
+
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMDataSourceExt;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axis2.datasource.XMLStringDataSource;
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.message.databinding.XMLStringBlock;
+import org.apache.axis2.jaxws.message.factory.BlockFactory;
+import org.apache.axis2.jaxws.message.impl.BlockImpl;
+import org.apache.axis2.jaxws.message.util.Reader2Writer;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.ws.WebServiceException;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * XMLStringBlock
+ * <p/>
+ * Block containing a business object that is a String of xml text
+ */
+public class XMLStringBlockImpl extends BlockImpl implements XMLStringBlock {
+
+    /**
+     * Constructor called from factory
+     *
+     * @param busObject
+     * @param qName
+     * @param factory
+     */
+    XMLStringBlockImpl(String busObject, QName qName, BlockFactory factory) {
+        super(busObject, null, qName, factory);
+    }
+
+
+    /**
+     * Constructor called from factory
+     *
+     * @param reader
+     * @param qName
+     * @param factory
+     */
+    public XMLStringBlockImpl(OMElement omElement, QName qName, BlockFactory factory) {
+        super(omElement, null, qName, factory);
+    }
+
+    protected Object _getBOFromReader(XMLStreamReader reader, Object busContext)
+            throws XMLStreamException {
+        // Create a Reader2Writer converter and get the output as a String
+        Reader2Writer r2w;
+        if ((busContext == null) && (omElement != null) && (omElement.isComplete())) {
+            r2w = new Reader2Writer(reader, false);
+        } else {
+            r2w = new Reader2Writer(reader);
+        }
+        return r2w.getAsString();
+    }
+    
+    @Override
+    protected Object _getBOFromOM(OMElement omElement, Object busContext)
+        throws XMLStreamException, WebServiceException {
+        
+        // Shortcut to get business object from existing data source
+        if (omElement instanceof OMSourcedElement) {
+            OMDataSource ds = ((OMSourcedElement) omElement).getDataSource();
+            if (ds instanceof XMLStringDataSource) {
+                return ((XMLStringDataSource) ds).getObject();
+            }
+        }
+        return super._getBOFromOM(omElement, busContext);
+    }
+
+    protected XMLStreamReader _getReaderFromBO(Object busObj, Object busContext)
+            throws XMLStreamException {
+        // Create an XMLStreamReader from the inputFactory using the String as the sources
+        String str = (String)busObj;
+        StringReader sr = new StringReader(str);
+        return StAXUtils.createXMLStreamReader(sr);
+    }
+
+    protected void _outputFromBO(Object busObject, Object busContext, XMLStreamWriter writer)
+            throws XMLStreamException {
+        // There is no fast way to output the String to a writer, so get the reader
+        // and pass use the default reader->writer.
+        XMLStreamReader reader = _getReaderFromBO(busObject, busContext);
+        _outputFromReader(reader, writer);
+    }
+
+
+    public boolean isElementData() {
+        return false;  // The text could be element or text or something else
+    }
+    
+    public boolean isXMLData() {
+        return true;
+    }
+    
+    public void close() {
+        return; // Nothing to close
+    }
+
+    public InputStream getXMLInputStream(String encoding) throws UnsupportedEncodingException {
+        try {
+            byte[] bytes = ((String) getBusinessObject(false)).getBytes(encoding);
+            return new ByteArrayInputStream(bytes);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+
+    public Object getObject() {
+        try {
+            return getBusinessObject(false);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+
+    public boolean isDestructiveRead() {
+        return false;
+    }
+
+    public boolean isDestructiveWrite() {
+        return false;
+    }
+    
+    public OMDataSourceExt copy() throws OMException {
+        return new XMLStringDataSource((String) getObject());
+    }
+
+
+    public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
+        try {
+            return ((String) getBusinessObject(false)).getBytes(encoding);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+}

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message