You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sc...@apache.org on 2007/12/10 21:34:42 UTC

svn commit: r603038 [1/2] - in /webservices/axis2/trunk/java/modules: jaxws/src/org/apache/axis2/datasource/ jaxws/src/org/apache/axis2/datasource/jaxb/ jaxws/src/org/apache/axis2/jaxws/message/attachments/ jaxws/src/org/apache/axis2/jaxws/message/data...

Author: scheu
Date: Mon Dec 10 12:34:39 2007
New Revision: 603038

URL: http://svn.apache.org/viewvc?rev=603038&view=rev
Log:
AXIS2-3395
Contributor:Rich Scheuerle
Added org.apache.axis2.datasource.jaxb.JAXBDataSource.
The JAXBDataSource supports usage of JAXB outside of the JAX-WS layer.
This is the first step to decomposing the JAX-WS Message model.
To make this happen, bits of the JAXWS message model were refactored.

Added:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/SourceDataSource.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/XMLStringDataSource.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentMarshaller.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentUnmarshaller.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDataSource.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBXMLStreamWriterFilter.java
      - copied, changed from r599938, webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBXMLStreamWriterFilter.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/XSDListUtils.java
      - copied, changed from r599938, webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/XSDListUtils.java
Removed:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/XSDListUtils.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBXMLStreamWriterFilter.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentUnmarshaller.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBBlockContext.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/XMLStringBlockImpl.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/MessagePersistanceTests.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/ExceptionFactory.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/i18n/resource.properties

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/SourceDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/SourceDataSource.java?rev=603038&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/SourceDataSource.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/SourceDataSource.java Mon Dec 10 12:34:39 2007
@@ -0,0 +1,126 @@
+/*
+ * 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.datasource;
+
+
+import org.apache.axiom.om.OMDataSourceExt;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.ds.OMDataSourceExtBase;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * OMDataSource backed by a source
+ */
+public class SourceDataSource extends OMDataSourceExtBase {
+    private static final Log log = LogFactory.getLog(SourceDataSource.class);
+    Source data;
+
+    public SourceDataSource(Source data) {
+        super();
+        this.data = data;
+    }
+
+    public void close() {
+    }
+
+    public OMDataSourceExt copy() {
+        return null;
+    }
+
+    public Object getObject() {
+        return data;
+    }
+
+    public XMLStreamReader getReader() throws XMLStreamException {
+
+        try {
+            String encoding = "utf-8";
+            InputStream is = new ByteArrayInputStream(getXMLBytes(encoding));
+            return StAXUtils.createXMLStreamReader(is, encoding);
+        } catch (UnsupportedEncodingException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
+        if (log.isDebugEnabled()) {
+            log.debug("Start getXMLBytes");
+        }
+        byte[] bytes = null;
+        try {
+            bytes = (byte[]) null;
+
+            if (data instanceof StreamSource) {
+                InputStream is = ((StreamSource) data).getInputStream();
+                if (is != null) {
+                    bytes = getBytesFromStream(is);
+                }
+            } else {
+                ByteArrayOutputStream out = new ByteArrayOutputStream();
+                Result result = new StreamResult(out);
+                Transformer transformer = TransformerFactory.newInstance().newTransformer();
+                transformer.transform(data, result);
+                bytes = out.toByteArray();
+            }            
+        } catch (OMException e) {
+            throw e;
+        } catch (UnsupportedEncodingException e) {
+            throw e;
+        } catch (Throwable e) {
+            throw new OMException(e);
+        }
+        
+        if (log.isDebugEnabled()) {
+            log.debug("End getXMLBytes");
+        }
+        return bytes;
+    }
+
+    public boolean isDestructiveRead() {
+        return false;
+    }
+
+    public boolean isDestructiveWrite() {
+        return false;
+    }
+    
+    private static byte[] getBytesFromStream(InputStream is) throws IOException {
+        // TODO This code assumes that available is the length of the stream.
+        byte[] bytes = new byte[is.available()];
+        is.read(bytes);
+        return bytes;
+    }
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/XMLStringDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/XMLStringDataSource.java?rev=603038&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/XMLStringDataSource.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/XMLStringDataSource.java Mon Dec 10 12:34:39 2007
@@ -0,0 +1,78 @@
+/*
+ * 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.datasource;
+
+
+import org.apache.axiom.om.OMDataSourceExt;
+import org.apache.axiom.om.ds.OMDataSourceExtBase;
+import org.apache.axiom.om.util.StAXUtils;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * OMDataSource backed by a string containing xml data
+ */
+public class XMLStringDataSource extends OMDataSourceExtBase {
+    String data;
+
+    public XMLStringDataSource(String data) {
+        super();
+        this.data = data;
+    }
+
+    public void close() {
+    }
+
+    public OMDataSourceExt copy() {
+        return new XMLStringDataSource(data);
+    }
+
+    public Object getObject() {
+        return data;
+    }
+
+    public XMLStreamReader getReader() throws XMLStreamException {
+
+        try {
+            String encoding = "utf-8";
+            InputStream is = new ByteArrayInputStream(getXMLBytes(encoding));
+            return StAXUtils.createXMLStreamReader(is, encoding);
+        } catch (UnsupportedEncodingException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
+        return data.getBytes(encoding);
+    }
+
+    public boolean isDestructiveRead() {
+        return false;
+    }
+
+    public boolean isDestructiveWrite() {
+        return false;
+    }
+    
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentMarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentMarshaller.java?rev=603038&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentMarshaller.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentMarshaller.java Mon Dec 10 12:34:39 2007
@@ -0,0 +1,220 @@
+/*
+ * 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.datasource.jaxb;
+
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
+import org.apache.axiom.om.impl.llom.OMTextImpl;
+import org.apache.axis2.Constants.Configuration;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.activation.DataHandler;
+import javax.mail.MessagingException;
+import javax.mail.internet.InternetHeaders;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimePartDataSource;
+import javax.xml.bind.attachment.AttachmentMarshaller;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * An implementation of the JAXB AttachmentMarshaller that is used to handle binary data from JAXB
+ * and create populate the appropriate constructs on the MessageContext
+ */
+public class JAXBAttachmentMarshaller extends AttachmentMarshaller {
+
+    private static final Log log = LogFactory.getLog(JAXBAttachmentMarshaller.class);
+
+    private MessageContext msgContext;
+    private XMLStreamWriter writer;
+    private final String APPLICATION_OCTET = "application/octet-stream";
+    
+    /**
+     * Construct the JAXBAttachmentMarshaller that has access to the MessageContext
+     * @param msgContext
+     * @param writer
+     */
+    public JAXBAttachmentMarshaller(MessageContext msgContext, XMLStreamWriter writer) {
+        this.msgContext = msgContext;
+        this.writer = writer;
+    }
+
+    /**
+     * Override isXOPPackaget to calculate the isXOPPackage setting
+     */
+    public boolean isXOPPackage() {
+        boolean value = false;
+        
+        // For outbound messages, only trigger MTOM if
+        // the message is mtom enabled.
+        value = isMTOMEnabled();
+        
+        // If the writer is not an MTOM XMLStreamWriter then we don't have
+        // any place to store the attachment
+        if (!(writer instanceof MTOMXMLStreamWriter)) {
+            if (log.isDebugEnabled()) {
+                log.debug("The writer is not enabled for MTOM.  " +
+                                "MTOM values will not be optimized");
+            }
+            value = false;
+        }
+    
+        if (log.isDebugEnabled()){ 
+            log.debug("isXOPPackage returns " + value);
+        }
+        return value;
+
+    }
+
+    
+    /* (non-Javadoc)
+     * @see javax.xml.bind.attachment.AttachmentMarshaller#addMtomAttachment(byte[], int, int, java.lang.String, java.lang.String, java.lang.String)
+     */
+    public String addMtomAttachment(byte[] data, int offset, int length,
+                                    String mimeType, String namespace, String localPart) {
+
+        if (offset != 0 || length != data.length) {
+            int len = length - offset;
+            byte[] newData = new byte[len];
+            System.arraycopy(data, offset, newData, 0, len);
+            data = newData;
+        }
+        
+        if (mimeType == null || mimeType.length() == 0) {
+            mimeType = APPLICATION_OCTET;
+        }
+        
+        if (log.isDebugEnabled()){ 
+            log.debug("Adding MTOM/XOP byte array attachment for element: " + 
+                      "{" + namespace + "}" + localPart);
+        }
+        
+        String cid;
+        
+            try {
+                // Create MIME Body Part
+                InternetHeaders ih = new InternetHeaders();
+                ih.setHeader(HTTPConstants.HEADER_CONTENT_TYPE, mimeType);
+                MimeBodyPart mbp = new MimeBodyPart(ih, data);
+                
+                //Create a data source for the MIME Body Part
+                MimePartDataSource mpds = new MimePartDataSource(mbp);
+                
+                DataHandler dataHandler = new DataHandler(mpds);
+                cid = addDataHandler(dataHandler);
+                
+                // Add the content id to the mime body part
+                mbp.setHeader(HTTPConstants.HEADER_CONTENT_ID, cid);
+            } catch (MessagingException e) {
+                throw new OMException(e);
+            }
+        
+        return cid == null ? null : "cid:" + cid;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see javax.xml.bind.attachment.AttachmentMarshaller#addMtomAttachment(javax.activation.DataHandler, java.lang.String, java.lang.String)
+     */
+    public String addMtomAttachment(DataHandler data, String namespace, String localPart) {
+        if (log.isDebugEnabled()){ 
+            log.debug("Adding MTOM/XOP datahandler attachment for element: " + 
+                      "{" + namespace + "}" + localPart);
+        }
+        String cid = addDataHandler(data);
+        return cid == null ? null : "cid:" + cid;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see javax.xml.bind.attachment.AttachmentMarshaller#addSwaRefAttachment(javax.activation.DataHandler)
+     */
+    public String addSwaRefAttachment(DataHandler data) {
+        if (log.isDebugEnabled()){ 
+            log.debug("Adding SWAREF attachment");
+        }
+        
+        String cid = addDataHandler(data);
+        setDoingSWA();
+        return "cid:" + cid;
+    }
+    
+    /**
+     * Add the DataHandler to the writer and context
+     * @param dh
+     * @return
+     */
+    private String addDataHandler(DataHandler dh) {
+        String cid = null;
+        OMText textNode = null;
+        
+        // If this is an MTOMXMLStreamWriter then inform the writer 
+        // that it must write out this attchment (I guess we should do this
+        // even if the attachment is SWAREF ?)
+        if (writer instanceof MTOMXMLStreamWriter) {
+            textNode = new OMTextImpl(dh, null);
+            cid = textNode.getContentID();
+            ((MTOMXMLStreamWriter) writer).writeOptimized(textNode);
+            // Remember the attachment on the message.
+            addDataHandler(dh, cid);
+        }
+        
+        if (log.isDebugEnabled()){ 
+            log.debug("   content id=" + cid);
+            log.debug("   dataHandler  =" + dh);
+        }
+        return cid;
+    }
+
+    /**
+     * @return if MTOM enabled calculated from the context information
+     */
+    public boolean isMTOMEnabled() {
+        if (msgContext == null) {
+            return false;
+        } else {
+            String value = (String) msgContext.getProperty(Configuration.ENABLE_MTOM);
+            return ("true".equalsIgnoreCase(value));
+        }  
+    }
+    
+    /**
+     * Indicate on the context that SWA attachments are encountered
+     */
+    public void setDoingSWA() {
+        if (msgContext != null) {
+            msgContext.setDoingSwA(true);
+            msgContext.setProperty(Configuration.ENABLE_SWA, "true");
+        }
+    }
+    
+    /**
+     * Inform the context that an Attachment (DataHandler, CID) is written.
+     * @param dh
+     * @param cid
+     */
+    public void addDataHandler(DataHandler dh, String cid) {
+        if (msgContext != null) {
+            msgContext.addAttachment(cid, dh);
+        }
+    }
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentUnmarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentUnmarshaller.java?rev=603038&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentUnmarshaller.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentUnmarshaller.java Mon Dec 10 12:34:39 2007
@@ -0,0 +1,157 @@
+/*
+ * 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.datasource.jaxb;
+
+import org.apache.axiom.om.OMException;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.activation.DataHandler;
+import javax.xml.bind.attachment.AttachmentUnmarshaller;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * JAXBAttachmentUnmarshaller
+ * <p/>
+ * An implementation of the <link>javax.xml.bind.attachment.AttachmentUnmarshaller</link> that is
+ * used for deserializing XOP elements into their corresponding binary data packages.
+ */
+public class JAXBAttachmentUnmarshaller extends AttachmentUnmarshaller {
+
+    private static final Log log = LogFactory.getLog(JAXBAttachmentUnmarshaller.class);
+
+    private MessageContext msgContext;
+
+    public JAXBAttachmentUnmarshaller(MessageContext msgContext) {
+        this.msgContext = msgContext;
+    }
+
+    public boolean isXOPPackage() {
+        
+        // Any message that is received might contain MTOM.
+        // So always return true.
+        boolean value = true;
+    
+        if (log.isDebugEnabled()){ 
+            log.debug("isXOPPackage returns " + value);
+        }
+        return value;
+    }
+
+    public byte[] getAttachmentAsByteArray(String cid) {
+        if (log.isDebugEnabled()) {
+            log.debug("Attempting to retrieve attachment [" + cid + "] as a byte[]");
+        }
+        DataHandler dh = getAttachmentAsDataHandler(cid);
+        if (dh != null) {
+            try {
+                return convert(dh);
+            } catch (IOException ioe) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Exception occurred while getting the byte[] " + ioe);
+                }
+                throw new OMException(ioe);
+            }
+        }
+        if (log.isDebugEnabled()) {
+            log.debug("returning null byte[]");
+        }
+        return null;
+    }
+
+    public DataHandler getAttachmentAsDataHandler(String cid) {
+        if (log.isDebugEnabled()) {
+            log.debug("Attempting to retrieve attachment [" + cid + "] as a DataHandler");
+        }
+
+        DataHandler dh = getDataHandler(cid);
+        if (dh != null) {
+            return dh;
+        } else {
+            String cid2 = getNewCID(cid);
+            if (log.isDebugEnabled()) {
+                log.debug("A dataHandler was not found for [" + cid + "] trying [" + cid2 + "]");
+            }
+            dh = getDataHandler(cid2);
+            if (dh != null) {
+                return dh;
+            }
+        }
+        // No Data Handler found
+        throw new OMException(Messages.getMessage("noDataHandler", cid));
+    }
+    
+    /**
+     * @param cid
+     * @return cid with translated characters
+     */
+    private String getNewCID(String cid) {
+        String cid2 = cid;
+
+        try {
+            cid2 = java.net.URLDecoder.decode(cid, "UTF-8");
+        } catch (Exception e) {
+            if (log.isDebugEnabled()) {
+                log.debug("getNewCID decoding " + cid + " as UTF-8 decoding error: " + e);
+            }
+        }
+        return cid2;
+    }
+
+    /**
+     * Read the bytes from the DataHandler
+     * 
+     * @param dh
+     * @return byte[]
+     * @throws IOException
+     */
+    private byte[] convert(DataHandler dh) throws IOException {
+        if (log.isDebugEnabled()) {
+            log.debug("Reading byte[] from DataHandler " + dh);
+        }
+        InputStream is = dh.getInputStream();
+        if (log.isDebugEnabled()) {
+            log.debug("DataHandler InputStream " + is);
+        }
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        byte[] b = new byte[1024];
+        int num = is.read(b);
+        if (log.isDebugEnabled()) {
+            if (num <= 0) {
+                log.debug("DataHandler InputStream contains no data. num=" + num);
+            }
+        }
+        while (num > 0) {
+            baos.write(b, 0, num);
+            num = is.read(b);
+        }
+        return baos.toByteArray();
+    }
+    
+    protected DataHandler getDataHandler(String cid) {
+        if (msgContext != null) {
+            return msgContext.getAttachment(cid);
+        }
+        return null;
+    }
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java?rev=603038&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java Mon Dec 10 12:34:39 2007
@@ -0,0 +1,677 @@
+/*
+ * 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.datasource.jaxb;
+
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.java.security.AccessController;
+import org.apache.axis2.jaxws.message.databinding.JAXBUtils;
+import org.apache.axis2.jaxws.message.util.XMLStreamWriterWithOS;
+import org.apache.axis2.jaxws.spi.Constants;
+import org.apache.axis2.jaxws.utility.XMLRootElementUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.attachment.AttachmentMarshaller;
+import javax.xml.bind.attachment.AttachmentUnmarshaller;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.ws.Holder;
+import javax.xml.ws.WebServiceException;
+
+import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.PrivilegedAction;
+import java.text.ParseException;
+import java.util.TreeSet;
+
+/*
+ * To marshal or unmarshal a JAXB object, the JAXBContext is necessary.
+ * In addition, access to the MessageContext and other context objects may be necessary
+ * to get classloader information, store attachments etc.
+ * 
+ * The JAXBDSContext bundles all of this information together.
+ */
+public class JAXBDSContext {
+
+    private static final Log log = LogFactory.getLog(JAXBDSContext.class);
+    public static final boolean DEBUG_ENABLED = log.isDebugEnabled();
+
+    private TreeSet<String> contextPackages;  // List of packages needed by the context
+    private String contextPackagesKey;        // Unique key that represents the set of contextPackages (usually toString)
+    private JAXBContext jaxbContext = null;   // JAXBContext
+    private JAXBUtils.CONSTRUCTION_TYPE       // How the JAXBContext is constructed
+            constructionType = JAXBUtils.CONSTRUCTION_TYPE.UNKNOWN;
+    private MessageContext msgContext;    
+
+    // There are two modes of marshalling and unmarshalling: "by java type" and "by schema element".
+    // The prefered mode is "by schema element" because it is safe and xml-centric.
+    // However there are some circumstances when "by schema element" is not available.
+    //    Examples: RPC Lit processing (the wire element is defined by a wsdl:part...not schema)
+    //              Doc/Lit Bare "Minimal" Processing (JAXB ObjectFactories are missing...and thus we must use "by type" for primitives/String)
+    // Please don't use "by java type" processing to get around errors.
+    private Class processType = null;
+    private boolean isxmlList =false;
+
+    /**
+     * Full Constructor JAXBDSContext (most performant)
+     *
+     * @param packages Set of packages needed by the JAXBContext.
+     */
+    public JAXBDSContext(TreeSet<String> packages, String packagesKey) {
+        this.contextPackages = packages;
+        this.contextPackagesKey = packagesKey;
+    }
+
+    /**
+     * Slightly slower constructor
+     *
+     * @param packages
+     */
+    public JAXBDSContext(TreeSet<String> packages) {
+        this(packages, packages.toString());
+    }
+
+    /**
+     * Normal Constructor JAXBBlockContext
+     *
+     * @param contextPackage
+     * @deprecated
+     */
+    public JAXBDSContext(String contextPackage) {
+        this.contextPackages = new TreeSet();
+        this.contextPackages.add(contextPackage);
+        this.contextPackagesKey = this.contextPackages.toString();
+    }
+
+    /**
+     * "Dispatch" Constructor Use this full constructor when the JAXBContent is provided by the
+     * customer.
+     *
+     * @param jaxbContext
+     */
+    public JAXBDSContext(JAXBContext jaxbContext) {
+        this.jaxbContext = jaxbContext;
+    }
+
+    /** @return Class representing type of the element */
+    public TreeSet<String> getContextPackages() {
+        return contextPackages;
+    }
+    
+    public JAXBContext getJAXBContext() throws JAXBException {
+        return getJAXBContext(null);
+    }
+
+    /**
+     * @return get the JAXBContext
+     * @throws JAXBException
+     */
+    public JAXBContext getJAXBContext(ClassLoader cl) throws JAXBException {
+        if (jaxbContext == null) {
+            if (log.isDebugEnabled()) {
+                log.debug(
+                        "A JAXBContext did not exist, creating a new one with the context packages.");
+            }
+            Holder<JAXBUtils.CONSTRUCTION_TYPE> constructType =
+                    new Holder<JAXBUtils.CONSTRUCTION_TYPE>();
+            jaxbContext =
+                    JAXBUtils.getJAXBContext(contextPackages, constructType, contextPackagesKey, cl);
+            constructionType = constructType.value;
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug("Using an existing JAXBContext");
+            }
+        }
+        return jaxbContext;
+    }
+
+    /** @return RPC Declared Type */
+    public Class getProcessType() {
+        return processType;
+    }
+
+    /**
+     * Set RPC Declared Type.  The use of use this property if the message is style=document is
+     * discouraged.
+     *
+     * @param type
+     */
+    public void setProcessType(Class type) {
+        processType = type;
+    }
+
+    public JAXBUtils.CONSTRUCTION_TYPE getConstructionType() {
+        return constructionType;
+    }
+
+    public boolean isxmlList() {
+        return isxmlList;
+    }
+
+    public void setIsxmlList(boolean isxmlList) {
+        this.isxmlList = isxmlList;
+    }
+    
+    public MessageContext getMessageContext() {
+        return msgContext;
+    }
+
+    public void setMessageContext(MessageContext messageContext) {
+        this.msgContext = messageContext;
+    }
+    
+    public ClassLoader getClassLoader() {
+        if (getMessageContext() != null) {
+            return (ClassLoader) getMessageContext().getProperty(Constants.CACHE_CLASSLOADER);
+        }
+        return null;
+    }
+    
+    /**
+     * Create an AttachmentMarshaller to marshal MTOM/SWA Attachments
+     * @param writer
+     * @return
+     */
+    protected AttachmentMarshaller createAttachmentMarshaller(XMLStreamWriter writer) {
+        return new JAXBAttachmentMarshaller(getMessageContext(), writer);
+    }
+    
+    /**
+     * Create an Attachment unmarshaller for unmarshalling MTOM/SWA Attachments
+     * @return AttachmentUnmarshaller
+     */
+    protected AttachmentUnmarshaller createAttachmentUnmarshaller() {
+        return new JAXBAttachmentUnmarshaller(getMessageContext());
+    }
+
+    /**
+     * Unmarshal the xml into a JAXB object
+     * @param reader
+     * @return
+     * @throws JAXBException
+     */
+    public Object unmarshal(XMLStreamReader reader) throws JAXBException {
+
+        // There may be a preferred classloader that should be used
+        ClassLoader cl = getClassLoader();
+        
+        Unmarshaller u = JAXBUtils.getJAXBUnmarshaller(getJAXBContext(cl));
+
+        
+        // Create an attachment unmarshaller
+        AttachmentUnmarshaller aum = createAttachmentUnmarshaller();
+
+        if (aum != null) {
+            if (DEBUG_ENABLED) {
+                log.debug("Adding JAXBAttachmentUnmarshaller to Unmarshaller");
+            } 
+            u.setAttachmentUnmarshaller(aum);
+        }
+
+        Object jaxb = null;
+
+        // Unmarshal into the business object.
+        if (getProcessType() == null) {
+            jaxb = unmarshalByElement(u, reader);   // preferred and always used for
+                                                    // style=document
+        } else {
+            jaxb = unmarshalByType(u,
+                                   reader,
+                                   getProcessType(),
+                                   isxmlList(),
+                                   getConstructionType());
+        }
+
+        // Successfully unmarshalled the object
+        JAXBUtils.releaseJAXBUnmarshaller(getJAXBContext(cl), u);
+        
+        // Don't close the reader.  The reader is owned by the caller, and it
+        // may contain other xml instance data (other than this JAXB object)
+        // reader.close();
+        return jaxb;
+    }
+    
+    /**
+     * Marshal the jaxb object
+     * @param obj
+     * @param writer
+     * @param am AttachmentMarshaller, optional Attachment
+     */
+    public void marshal(Object obj, 
+                        XMLStreamWriter writer) throws JAXBException {
+            // There may be a preferred classloader that should be used
+            ClassLoader cl = getClassLoader();
+            
+            
+            // Very easy, use the Context to get the Marshaller.
+            // Use the marshaller to write the object.
+            Marshaller m = JAXBUtils.getJAXBMarshaller(getJAXBContext(cl));
+            
+            AttachmentMarshaller am = createAttachmentMarshaller(writer);
+            if (am != null) {
+                if (DEBUG_ENABLED) {
+                    log.debug("Adding JAXBAttachmentMarshaller to Marshaller");
+                }
+                m.setAttachmentMarshaller(am);
+            }
+
+
+            // Marshal the object
+            if (getProcessType() == null) {
+                marshalByElement(obj, 
+                                 m, 
+                                 writer, 
+                                 !am.isXOPPackage());
+            } else {
+                marshalByType(obj,
+                              m,
+                              writer,
+                              getProcessType(),
+                              isxmlList(),
+                              getConstructionType());
+            }
+
+            // Successfully marshalled the data
+            JAXBUtils.releaseJAXBMarshaller(getJAXBContext(cl), m);
+    }
+    
+    
+    /**
+     * Preferred way to marshal objects.
+     * 
+     * @param b Object that can be rendered as an element and the element name is known by the
+     * Marshaller
+     * @param m Marshaller
+     * @param writer XMLStreamWriter
+     */
+    private static void marshalByElement(final Object b, final Marshaller m, 
+                                         final XMLStreamWriter writer,
+                                         final boolean optimize) {
+        AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                // Marshalling directly to the output stream is faster than marshalling through the
+                // XMLStreamWriter. 
+                // Take advantage of this optimization if there is an output stream.
+                try {
+                    OutputStream os = (optimize) ? getOutputStream(writer) : null;
+                    if (os != null) {
+                        if (DEBUG_ENABLED) {
+                            log.debug("Invoking marshalByElement.  " +
+                                        "Marshaling to an OutputStream. " +
+                                      "Object is "
+                                      + getDebugName(b));
+                        }
+                        writer.flush();
+                        m.marshal(b, os);
+                    } else {
+                        if (DEBUG_ENABLED) {
+                            log.debug("Invoking marshalByElement.  " +
+                                        "Marshaling to an XMLStreamWriter. " +
+                                      "Object is "
+                                      + getDebugName(b));
+                        }
+                        m.marshal(b, writer);
+                    }
+                } catch (OMException e) {
+                    throw e;
+                }
+                catch (Throwable t) {
+                    throw new OMException(t);
+                }
+                return null;
+            }});
+    }
+    
+    private static String getDebugName(Object o) {
+        return (o == null) ? "null" : o.getClass().getCanonicalName();
+    }
+
+    /**
+     * If the writer is backed by an OutputStream, then return the OutputStream
+     * @param writer
+     * @return OutputStream or null
+     */
+    private static OutputStream getOutputStream(XMLStreamWriter writer) throws XMLStreamException {
+        if (writer.getClass() == MTOMXMLStreamWriter.class) {
+            return ((MTOMXMLStreamWriter) writer).getOutputStream();
+        }
+        if (writer.getClass() == XMLStreamWriterWithOS.class) {
+            return ((XMLStreamWriterWithOS) writer).getOutputStream();
+        }
+        return null;
+    }
+    
+    /**
+     * The root element being read is defined by schema/JAXB; however its contents are known by
+     * schema/JAXB. Therefore we use unmarshal by the declared type (This method is used to
+     * unmarshal rpc elements)
+     * 
+     * @param u Unmarshaller
+     * @param reader XMLStreamReader
+     * @param type Class
+     * @return Object
+     * @throws WebServiceException
+     */
+    public static Object unmarshalByType(final Unmarshaller u, final XMLStreamReader reader,
+                                          final Class type, final boolean isList,
+                                          final JAXBUtils.CONSTRUCTION_TYPE ctype)
+        throws WebServiceException {
+
+        if (DEBUG_ENABLED) {
+            log.debug("Invoking unmarshalByType.");
+        }
+
+        return AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                try {
+                    // Unfortunately RPC is type based. Thus a
+                    // declared type must be used to unmarshal the xml.
+                    Object jaxb;
+
+                    if (!isList) {
+                        // case: We are not unmarshalling an xsd:list but an Array.
+
+                        if (type.isArray()) {
+                            // If the context is created using package
+                            // we will not have common arrays or type array in the context
+                            // so let use a differet way to unmarshal this type
+                            if (ctype == JAXBUtils.CONSTRUCTION_TYPE.BY_CONTEXT_PATH) {
+                                jaxb = unmarshalAsListOrArray(reader, u, type);
+                            }
+                            // list on client array on server, Can happen only in start from java
+                            // case.
+                            else if ((ctype == JAXBUtils.CONSTRUCTION_TYPE.BY_CLASS_ARRAY)) {
+                                // The type could be any Object or primitive
+                                // I will first unmarshall the xmldata to a String[]
+                                // Then use the unmarshalled jaxbElement to create
+                                // proper type Object Array.
+                                jaxb = u.unmarshal(reader, String[].class);
+                                Object typeObj = getTypeEnabledObject(jaxb);
+                                // Now convert String Array in to the required Type Array.
+                                if (getTypeEnabledObject(typeObj) instanceof String[]) {
+                                    String[] strArray = (String[]) typeObj;
+                                    String strTokens = new String();
+                                    for (String str : strArray) {
+                                        strTokens = strTokens + " " + str;
+                                    }
+                                    QName qName =
+                                            XMLRootElementUtil.
+                                            getXmlRootElementQNameFromObject(jaxb);
+                                    Object obj = XSDListUtils.fromXSDListString(strTokens, type);
+                                    jaxb = new JAXBElement(qName, type, obj);
+                                }
+                            } else {
+                                jaxb = u.unmarshal(reader, type);
+                            }
+
+                        } else if (type.isEnum()) {
+                            // When JAXBContext is created using a context path, it will not 
+                            // include Enum classes.
+                            // These classes have @XmlEnum annotation but not @XmlType/@XmlElement,
+                            // so the user will see MarshallingEx, class not known to ctxt.
+                            // 
+                            // This is a jax-b defect, for now this fix is in place to pass CTS.
+                            // This only fixes the
+                            // situation where the enum is the top-level object (e.g., message-part
+                            // in rpc-lit scenario)
+                            //
+                            // Sample of what enum looks like:
+                            // @XmlEnum public enum EnumString {
+                            // @XmlEnumValue("String1") STRING_1("String1"),
+                            // @XmlEnumValue("String2") STRING_2("String2");
+                            //
+                            // public static getValue(String){} <-- resolves a "value" to an emum
+                            // object
+                            // ... }
+                            if (DEBUG_ENABLED) {
+                                log.debug("unmarshalByType. Unmarshalling " + type.getName()
+                                        + " as Enum");
+                            }
+
+                            JAXBElement<String> enumValue = u.unmarshal(reader, String.class);
+
+                            if (enumValue != null) {
+                                Method m =
+                                        type.getMethod("fromValue", new Class[] { String.class });
+                                jaxb = m.invoke(null, new Object[] { enumValue.getValue() });
+                            } else {
+                                jaxb = null;
+                            }
+                        }
+                        //Normal case: We are not unmarshalling a xsd:list or Array
+                        else {
+                            jaxb = u.unmarshal(reader, type);
+                        }
+
+                    } else {
+                        // If this is an xsd:list, we need to return the appropriate
+                        // list or array (see NOTE above)
+                        // First unmarshal as a String
+                        //Second convert the String into a list or array
+                        jaxb = unmarshalAsListOrArray(reader, u, type);
+                    }
+                    return jaxb;
+                } catch (OMException e) {
+                    throw e;
+                } catch (Throwable t) {
+                    throw new OMException(t);
+                }
+            }
+        });
+    }
+
+    /**
+     * convert the String into a list or array
+     * @param <T>
+     * @param jaxb
+     * @param type
+     * @return
+     * @throws IllegalAccessException
+     * @throws ParseException
+     * @throws NoSuchMethodException
+     * @throws InstantiationException
+     * @throws DatatypeConfigurationException
+     * @throws InvocationTargetException
+     */
+    public static Object unmarshalAsListOrArray(XMLStreamReader reader, Unmarshaller u, 
+                                                 Class type)
+        throws IllegalAccessException, ParseException,NoSuchMethodException,InstantiationException,
+        DatatypeConfigurationException,InvocationTargetException,JAXBException {
+        //If this is an xsd:list, we need to return the appropriate
+        // list or array (see NOTE above)
+        // First unmarshal as a String
+        Object jaxb = u.unmarshal(reader, String.class);
+        //Second convert the String into a list or array
+        if (getTypeEnabledObject(jaxb) instanceof String) {
+            QName qName = XMLRootElementUtil.getXmlRootElementQNameFromObject(jaxb);
+            Object obj = XSDListUtils.fromXSDListString((String) getTypeEnabledObject(jaxb), type);
+            return new JAXBElement(qName, type, obj);
+        } else {
+            return jaxb;
+        }
+
+    }
+
+    /**
+     * Return type enabled object
+     *
+     * @param obj type or element enabled object
+     * @return type enabled object
+     */
+    static Object getTypeEnabledObject(Object obj) {
+        if (obj == null) {
+            return null;
+        }
+        if (obj instanceof JAXBElement) {
+            return ((JAXBElement) obj).getValue();
+        }
+        return obj;
+    }
+
+    /**
+     * Marshal objects by type
+     * 
+     * @param b Object that can be rendered as an element, but the element name is not known to the
+     * schema (i.e. rpc)
+     * @param m Marshaller
+     * @param writer XMLStreamWriter
+     * @param type
+     */
+    private static void marshalByType(final Object b, final Marshaller m,
+                                      final XMLStreamWriter writer, final Class type,
+                                      final boolean isList, final JAXBUtils.CONSTRUCTION_TYPE ctype)
+        throws WebServiceException {
+        AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                try {
+
+                    // NOTE
+                    // Example:
+                    // <xsd:simpleType name="LongList">
+                    // <xsd:list>
+                    // <xsd:simpleType>
+                    // <xsd:restriction base="xsd:unsignedInt"/>
+                    // </xsd:simpleType>
+                    // </xsd:list>
+                    // </xsd:simpleType>
+                    // <element name="myLong" nillable="true" type="impl:LongList"/>
+                    //
+                    // LongList will be represented as an int[]
+                    // On the wire myLong will be represented as a list of integers
+                    // with intervening whitespace
+                    // <myLong>1 2 3</myLong>
+                    //
+                    // Unfortunately, we are trying to marshal by type. Therefore
+                    // we want to marshal an element (foo) that is unknown to schema.
+                    // If we use the normal marshal code, the wire will look like
+                    // this (which is incorrect):
+                    // <foo><item>1</item><item>2</item><item>3</item></foo>
+                    //
+                    // The solution is to detect this situation and marshal the
+                    // String instead. Then we get the correct wire format:
+                    // <foo>1 2 3</foo>
+                    Object jbo = b;
+
+                    if (isList || (type != null && type.isArray())) {
+                        if (DEBUG_ENABLED) {
+                            log.debug("marshalling type which is a List or Array");
+                        }
+                        // We conver to xsdListString only if the type is not known
+                        // to the context. In case a jaxbcontext is created from package
+                        // the array types or list are not know to the context.
+                        if (ctype == JAXBUtils.CONSTRUCTION_TYPE.BY_CONTEXT_PATH) {
+                            QName qName = XMLRootElementUtil.getXmlRootElementQNameFromObject(b);
+                            String text = XSDListUtils.toXSDListString(getTypeEnabledObject(b));
+                            jbo = new JAXBElement(qName, String.class, text);
+                        } else if (ctype == JAXBUtils.CONSTRUCTION_TYPE.BY_CLASS_ARRAY) {
+                            // do nothing common array types should be know to the jaxbcontext.
+                            // so do not use xsdListString conversion.
+                        }
+                    }
+
+                    // When JAXBContext is created using a context path, it will not include Enum
+                    // classes.
+                    // These classes have @XmlEnum annotation but not @XmlType/@XmlElement, so the
+                    // user will see MarshallingEx, class not known to ctxt.
+                    // 
+                    // This is a jax-b defect, for now this fix is in place to pass CTS. This only
+                    // fixes the
+                    // situation where the enum is the top-level object (e.g., message-part in
+                    // rpc-lit scenario)
+                    //
+                    // Sample of what enum looks like:
+                    // @XmlEnum public enum EnumString {
+                    // @XmlEnumValue("String1") STRING_1("String1"),
+                    // @XmlEnumValue("String2") STRING_2("String2");
+                    // ... }
+                    if (type.isEnum()) {
+                        if (b != null) {
+                            if (DEBUG_ENABLED) {
+                                log.debug("marshalByType. Marshaling " + type.getName()
+                                        + " as Enum");
+                            }
+                            JAXBElement jbe = (JAXBElement) b;
+                            String value = XMLRootElementUtil.getEnumValue((Enum) jbe.getValue());
+
+                            jbo = new JAXBElement(jbe.getName(), String.class, value);
+                        }
+                    }
+
+                    if (DEBUG_ENABLED) {
+                        log.debug("Invoking marshalByType.  " +
+                                        "Marshaling to an XMLStreamWriter. Object is "
+                                + getDebugName(b));
+                    }
+                    m.marshal(jbo, writer);
+
+                } catch (OMException e) {
+                    throw e;
+                } catch (Throwable t) {
+                    throw new OMException(t);
+                }
+                return null;
+            }
+        });
+    }
+
+    /**
+     * Preferred way to unmarshal objects
+     * 
+     * @param u Unmarshaller
+     * @param reader XMLStreamReader
+     * @return Object that represents an element
+     * @throws WebServiceException
+     */
+    public static Object unmarshalByElement(final Unmarshaller u, final XMLStreamReader reader)
+        throws WebServiceException {
+        try {
+            if (DEBUG_ENABLED) {
+                log.debug("Invoking unMarshalByElement");
+            }
+            return AccessController.doPrivileged(new PrivilegedAction() {
+                public Object run() {
+                    try {
+                        return u.unmarshal(reader);
+                    } catch (OMException e) {
+                        throw e;
+                    } catch (Throwable t) {
+                        throw new OMException(t);
+                    }
+                }
+            });
+
+        } catch (OMException e) {
+            throw e;
+        } catch (Throwable t) {
+            throw new OMException(t);
+        }
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDataSource.java?rev=603038&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDataSource.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDataSource.java Mon Dec 10 12:34:39 2007
@@ -0,0 +1,149 @@
+/*
+ * 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.datasource.jaxb;
+
+
+import org.apache.axiom.om.OMDataSourceExt;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.ds.OMDataSourceExtBase;
+import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
+import org.apache.axiom.om.util.StAXUtils;
+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.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+
+/**
+ * OMDataSource backed by a jaxb object
+ */
+public class JAXBDataSource extends OMDataSourceExtBase {
+    
+    private static final Log log = LogFactory.getLog(JAXBDataSource.class);
+    
+    Object jaxb;
+    JAXBDSContext context;
+
+    public JAXBDataSource(Object jaxb, JAXBDSContext context) {
+        super();
+        this.jaxb = jaxb;
+        this.context = context;
+    }
+
+    public void close() {
+    }
+
+    public OMDataSourceExt copy() {
+        return new JAXBDataSource(jaxb, context);
+    }
+
+    public Object getObject() {
+        return jaxb;
+    }
+
+    public XMLStreamReader getReader() throws XMLStreamException {
+
+        try {
+            String encoding = "utf-8";
+            InputStream is = new ByteArrayInputStream(getXMLBytes(encoding));
+            return StAXUtils.createXMLStreamReader(is, encoding);
+        } catch (UnsupportedEncodingException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
+        MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format);
+        serialize(writer);
+        writer.flush();
+        try {
+            writer.close();
+        } catch (XMLStreamException e) {
+            // An exception can occur if nothing is written to the 
+            // writer.  This is possible if the underlying data source
+            // writers to the output stream directly.
+            if (log.isDebugEnabled()) {
+                log.debug("Catching and swallowing exception " + e);
+            }
+        }
+    }
+
+    public void serialize(Writer writerTarget, OMOutputFormat format) throws XMLStreamException {
+        MTOMXMLStreamWriter writer =
+            new MTOMXMLStreamWriter(StAXUtils.createXMLStreamWriter(writerTarget));
+        writer.setOutputFormat(format);
+        serialize(writer);
+        writer.flush();
+        writer.close();
+    }
+
+    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+        try {
+            context.marshal(jaxb, xmlWriter);
+        } catch (JAXBException je) {
+            if (log.isDebugEnabled()) {
+                try {
+                    log.debug("JAXBContext for marshal failure:" + 
+                              context.getJAXBContext(context.getClassLoader()));
+                } catch (Exception e) {
+                }
+            }
+            throw new XMLStreamException(je);
+        }
+    }
+    
+    public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
+        try {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+            // Exposes getOutputStream, which allows faster writes.
+            XMLStreamWriterWithOS writer = new XMLStreamWriterWithOS(baos, encoding);
+
+            // Write the business object to the writer
+            serialize(writer);
+
+            // Flush the writer
+            writer.flush();
+            writer.close();
+            return baos.toByteArray();
+        } catch (XMLStreamException e) {
+            throw new OMException(e);
+        }
+    }
+
+    public boolean isDestructiveRead() {
+        return false;
+    }
+
+    public boolean isDestructiveWrite() {
+        return false;
+    }
+    
+}

Copied: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBXMLStreamWriterFilter.java (from r599938, webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBXMLStreamWriterFilter.java)
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBXMLStreamWriterFilter.java?p2=webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBXMLStreamWriterFilter.java&p1=webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBXMLStreamWriterFilter.java&r1=599938&r2=603038&rev=603038&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBXMLStreamWriterFilter.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBXMLStreamWriterFilter.java Mon Dec 10 12:34:39 2007
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.axis2.jaxws.message.databinding.impl;
+package org.apache.axis2.datasource.jaxb;
 
 import org.apache.axis2.jaxws.utility.JavaUtils;
 import org.apache.commons.logging.Log;

Copied: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/XSDListUtils.java (from r599938, webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/XSDListUtils.java)
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/XSDListUtils.java?p2=webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/XSDListUtils.java&p1=webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/XSDListUtils.java&r1=599938&r2=603038&rev=603038&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/XSDListUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/XSDListUtils.java Mon Dec 10 12:34:39 2007
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.axis2.jaxws.message.databinding;
+package org.apache.axis2.datasource.jaxb;
 
 import org.apache.axis2.jaxws.i18n.Messages;
 

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java?rev=603038&r1=603037&r2=603038&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java Mon Dec 10 12:34:39 2007
@@ -18,150 +18,50 @@
  */
 package org.apache.axis2.jaxws.message.attachments;
 
-import org.apache.axiom.om.OMText;
-import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
-import org.apache.axiom.om.impl.llom.OMTextImpl;
-import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.message.Message;
-import org.apache.axis2.transport.http.HTTPConstants;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 import javax.activation.DataHandler;
-import javax.mail.internet.InternetHeaders;
-import javax.mail.internet.MimeBodyPart;
-import javax.mail.internet.MimePartDataSource;
-import javax.xml.bind.attachment.AttachmentMarshaller;
 import javax.xml.stream.XMLStreamWriter;
 
 /**
  * An implementation of the JAXB AttachmentMarshaller that is used to handle binary data from JAXB
  * and create populate the appropriate constructs within the JAX-WS Message Model.
  */
-public class JAXBAttachmentMarshaller extends AttachmentMarshaller {
-
-    private static final Log log = LogFactory.getLog(JAXBAttachmentMarshaller.class);
-
+public class JAXBAttachmentMarshaller extends org.apache.axis2.datasource.jaxb.JAXBAttachmentMarshaller {
     private Message message;
-    private XMLStreamWriter writer;
-    private final String APPLICATION_OCTET = "application/octet-stream";
     
     public JAXBAttachmentMarshaller(Message message, XMLStreamWriter writer) {
+        super(null, writer);
         this.message = message;
-        this.writer = writer;
     }
-
-    @Override
-    public boolean isXOPPackage() {
-        boolean value = false;
-        
-        // For outbound messages, only trigger MTOM if
-        // the message is mtom enabled (which indicates that
-        // the api dispatch/provider/proxy/impl has an MTOM binding)
-        if (message != null) {
-          value = message.isMTOMEnabled();
-        }
-        
-        
-        // If the writer is not an MTOM XMLStreamWriter then we don't have
-        // any place to store the attachment
-        if (!(writer instanceof MTOMXMLStreamWriter)) {
-            if (log.isDebugEnabled()) {
-                log.debug("The writer is not enabled for MTOM.  " +
-                                "MTOM values will not be optimized");
-            }
-            value = false;
-        }
-    
-        if (log.isDebugEnabled()){ 
-            log.debug("isXOPPackage returns " + value);
-        }
-        return value;
-
-    }
-
-    @Override
-    public String addMtomAttachment(byte[] data, int offset, int length,
-                                    String mimeType, String namespace, String localPart) {
-
-        if (offset != 0 || length != data.length) {
-            int len = length - offset;
-            byte[] newData = new byte[len];
-            System.arraycopy(data, offset, newData, 0, len);
-            data = newData;
-        }
-        
-        if (mimeType == null || mimeType.length() == 0) {
-            mimeType = APPLICATION_OCTET;
-        }
-        
-        if (log.isDebugEnabled()){ 
-            log.debug("Adding MTOM/XOP byte array attachment for element: " + 
-                      "{" + namespace + "}" + localPart);
-        }
-        
-        String cid;
-        try {
-            // Create MIME Body Part
-            InternetHeaders ih = new InternetHeaders();
-            ih.setHeader(HTTPConstants.HEADER_CONTENT_TYPE, mimeType);
-            MimeBodyPart mbp = new MimeBodyPart(ih, data);
-            
-            //Create a data source for the MIME Body Part
-            MimePartDataSource mpds = new MimePartDataSource(mbp);
-            
-            DataHandler dataHandler = new DataHandler(mpds);
-            cid = addDataHandler(dataHandler);
-            
-            // Add the content id to the mime body part
-            mbp.setHeader(HTTPConstants.HEADER_CONTENT_ID, cid);
-        } catch (Throwable t) {
-            throw ExceptionFactory.makeWebServiceException(t);
-        }
-        return cid == null ? null : "cid:" + cid;
+    /**
+     * @return if MTOM enabled calculated from the context information
+     */
+    public boolean isMTOMEnabled() {
+        if (message == null) {
+            return false;
+        } else {
+            return message.isMTOMEnabled();
+        }  
     }
     
-    @Override
-    public String addMtomAttachment(DataHandler data, String namespace, String localPart) {
-        if (log.isDebugEnabled()){ 
-            log.debug("Adding MTOM/XOP datahandler attachment for element: " + 
-                      "{" + namespace + "}" + localPart);
-        }
-        String cid = addDataHandler(data);
-        return cid == null ? null : "cid:" + cid;
-    }
-    
-    @Override
-    public String addSwaRefAttachment(DataHandler data) {
-        if (log.isDebugEnabled()){ 
-            log.debug("Adding SWAREF attachment");
+    /**
+     * Indicate on the context that SWA attachments are encountered
+     */
+    public void setDoingSWA() {
+        if (message != null) {
+            message.setDoingSWA(true);
         }
-        
-        String cid = addDataHandler(data);
-        message.setDoingSWA(true);
-        return "cid:" + cid;
     }
     
-    private String addDataHandler(DataHandler dh) {
-        String cid = null;
-        OMText textNode = null;
-        
-        // If this is an MTOMXMLStreamWriter then inform the writer 
-        // that it must write out this attchment (I guess we should do this
-        // even if the attachment is SWAREF ?)
-        if (writer instanceof MTOMXMLStreamWriter) {
-            textNode = new OMTextImpl(dh, null);
-            cid = textNode.getContentID();
-            ((MTOMXMLStreamWriter) writer).writeOptimized(textNode);
-            // Remember the attachment on the message.
+    /**
+     * Inform the context that an Attachment (DataHandler, CID) is written.
+     * @param dh
+     * @param cid
+     */
+    public void addDataHandler(DataHandler dh, String cid) {
+        if (message != null) {
             message.addDataHandler(dh, cid);
         }
-        
-        if (log.isDebugEnabled()){ 
-            log.debug("   content id=" + cid);
-            log.debug("   dataHandler  =" + dh);
-        }
-        return cid;
     }
-
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentUnmarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentUnmarshaller.java?rev=603038&r1=603037&r2=603038&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentUnmarshaller.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentUnmarshaller.java Mon Dec 10 12:34:39 2007
@@ -18,17 +18,11 @@
  */
 package org.apache.axis2.jaxws.message.attachments;
 
-import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.message.Message;
-import org.apache.axis2.jaxws.utility.JavaUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import javax.activation.DataHandler;
-import javax.xml.bind.attachment.AttachmentUnmarshaller;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
 
 /**
  * JAXBAttachmentUnmarshaller
@@ -36,119 +30,21 @@
  * An implementation of the <link>javax.xml.bind.attachment.AttachmentUnmarshaller</link> that is
  * used for deserializing XOP elements into their corresponding binary data packages.
  */
-public class JAXBAttachmentUnmarshaller extends AttachmentUnmarshaller {
-
-    private static final Log log = LogFactory.getLog(JAXBAttachmentUnmarshaller.class);
+public class JAXBAttachmentUnmarshaller extends org.apache.axis2.datasource.jaxb.JAXBAttachmentUnmarshaller {
 
     private Message message;
 
     public JAXBAttachmentUnmarshaller(Message message) {
+        super(null);
         this.message = message;
     }
 
-    @Override
-    public boolean isXOPPackage() {
-        
-        // Any message that is received might contain MTOM.
-        // So always return true.
-        boolean value = true;
-    
-        if (log.isDebugEnabled()){ 
-            log.debug("isXOPPackage returns " + value);
-        }
-        return value;
-    }
-
-    @Override
-    public byte[] getAttachmentAsByteArray(String cid) {
-        if (log.isDebugEnabled()) {
-            log.debug("Attempting to retrieve attachment [" + cid + "] as a byte[]");
-        }
-        DataHandler dh = getAttachmentAsDataHandler(cid);
-        if (dh != null) {
-            try {
-                return convert(dh);
-            } catch (IOException ioe) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Exception occurred while getting the byte[] " + ioe);
-                }
-                throw ExceptionFactory.makeWebServiceException(ioe);
-            }
-        }
-        if (log.isDebugEnabled()) {
-            log.debug("returning null byte[]");
-        }
+    protected DataHandler getDataHandler(String cid) {
+        if (message != null) {
+            return super.getDataHandler(cid);
+        } 
         return null;
     }
 
-    @Override
-    public DataHandler getAttachmentAsDataHandler(String cid) {
-        if (log.isDebugEnabled()) {
-            log.debug("Attempting to retrieve attachment [" + cid + "] as a DataHandler");
-        }
-
-        DataHandler dh = message.getDataHandler(cid);
-        if (dh != null) {
-            return dh;
-        } else {
-            String cid2 = getNewCID(cid);
-            if (log.isDebugEnabled()) {
-                log.debug("A dataHandler was not found for [" + cid + "] trying [" + cid2 + "]");
-            }
-            dh = message.getDataHandler(cid2);
-            if (dh != null) {
-                return dh;
-            }
-        }
-        // No Data Handler found
-        throw ExceptionFactory.makeWebServiceException("A data handler was not found " +
-                        "for content id " + cid);
-    }
     
-    /**
-     * @param cid
-     * @return cid with translated characters
-     */
-    private String getNewCID(String cid) {
-        String cid2 = cid;
-
-        try {
-            cid2 = java.net.URLDecoder.decode(cid, "UTF-8");
-        } catch (Exception e) {
-            if (log.isDebugEnabled()) {
-                log.debug("getNewCID decoding " + cid + " as UTF-8 decoding error: " + e);
-            }
-        }
-        return cid2;
-    }
-
-    /**
-     * Read the bytes from the DataHandler
-     * 
-     * @param dh
-     * @return byte[]
-     * @throws IOException
-     */
-    private byte[] convert(DataHandler dh) throws IOException {
-        if (log.isDebugEnabled()) {
-            log.debug("Reading byte[] from DataHandler " + dh);
-        }
-        InputStream is = dh.getInputStream();
-        if (log.isDebugEnabled()) {
-            log.debug("DataHandler InputStream " + is);
-        }
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        byte[] b = new byte[1024];
-        int num = is.read(b);
-        if (log.isDebugEnabled()) {
-            if (num <= 0) {
-                log.debug("DataHandler InputStream contains no data. num=" + num);
-            }
-        }
-        while (num > 0) {
-            baos.write(b, 0, num);
-            num = is.read(b);
-        }
-        return baos.toByteArray();
-    }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBBlockContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBBlockContext.java?rev=603038&r1=603037&r2=603038&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBBlockContext.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBBlockContext.java Mon Dec 10 12:34:39 2007
@@ -18,50 +18,36 @@
  */
 package org.apache.axis2.jaxws.message.databinding;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.datasource.jaxb.JAXBDSContext;
+import org.apache.axis2.jaxws.message.Message;
+import org.apache.axis2.jaxws.message.attachments.JAXBAttachmentMarshaller;
+import org.apache.axis2.jaxws.message.attachments.JAXBAttachmentUnmarshaller;
+import org.apache.axis2.jaxws.spi.Constants;
 
 import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.ws.Holder;
+import javax.xml.bind.attachment.AttachmentMarshaller;
+import javax.xml.bind.attachment.AttachmentUnmarshaller;
+import javax.xml.stream.XMLStreamWriter;
+
 import java.util.TreeSet;
 
 /*
- * A JAXBBlockContext controls access to the JAXB Context
+ * A JAXBBlockContext controls access to the JAXBContext
  * In addition the JAXBBlockContext contains additional contextural information needed
  * by the JAX-WS component
- * 
- * This class is immutable after construction.
  */
 
-public class JAXBBlockContext {
-
-    private static final Log log = LogFactory.getLog(JAXBBlockContext.class);
-
-    private TreeSet<String> contextPackages;  // List of packages needed by the context
-    private String contextPackagesKey;        // Unique key that represents the set of contextPackages (usually toString)
-    private JAXBContext jaxbContext = null;   // JAXBContext
-    private JAXBUtils.CONSTRUCTION_TYPE       // How the JAXBContext is constructed
-            constructionType = JAXBUtils.CONSTRUCTION_TYPE.UNKNOWN;
-
-    // There are two modes of marshalling and unmarshalling: "by java type" and "by schema element".
-    // The prefered mode is "by schema element" because it is safe and xml-centric.
-    // However there are some circumstances when "by schema element" is not available.
-    //    Examples: RPC Lit processing (the wire element is defined by a wsdl:part...not schema)
-    //              Doc/Lit Bare "Minimal" Processing (JAXB ObjectFactories are missing...and thus we must use "by type" for primitives/String)
-    // Please don't use "by java type" processing to get around errors.
-
-    private Class processType = null;
-    private boolean isxmlList =false;
+public class JAXBBlockContext extends JAXBDSContext {
 
+    Message message = null;
     /**
      * Full Constructor JAXBBlockContext (most performant)
      *
      * @param packages Set of packages needed by the JAXBContext.
      */
     public JAXBBlockContext(TreeSet<String> packages, String packagesKey) {
-        this.contextPackages = packages;
-        this.contextPackagesKey = packagesKey;
+        super(packages, packagesKey);
     }
 
     /**
@@ -80,9 +66,7 @@
      * @deprecated
      */
     public JAXBBlockContext(String contextPackage) {
-        this.contextPackages = new TreeSet();
-        this.contextPackages.add(contextPackage);
-        this.contextPackagesKey = this.contextPackages.toString();
+        super(contextPackage);
     }
 
     /**
@@ -92,66 +76,39 @@
      * @param jaxbContext
      */
     public JAXBBlockContext(JAXBContext jaxbContext) {
-        this.jaxbContext = jaxbContext;
+        super(jaxbContext);
     }
 
-    /** @return Class representing type of the element */
-    public TreeSet<String> getContextPackages() {
-        return contextPackages;
-    }
-    
-    public JAXBContext getJAXBContext() throws JAXBException {
-        return getJAXBContext(null);
-    }
-
-    /**
-     * @return get the JAXBContext
-     * @throws JAXBException
-     */
-    public JAXBContext getJAXBContext(ClassLoader cl) throws JAXBException {
-        if (jaxbContext == null) {
-            if (log.isDebugEnabled()) {
-                log.debug(
-                        "A JAXBContext did not exist, creating a new one with the context packages.");
-            }
-            Holder<JAXBUtils.CONSTRUCTION_TYPE> constructType =
-                    new Holder<JAXBUtils.CONSTRUCTION_TYPE>();
-            jaxbContext =
-                    JAXBUtils.getJAXBContext(contextPackages, constructType, contextPackagesKey, cl);
-            constructionType = constructType.value;
-        } else {
-            if (log.isDebugEnabled()) {
-                log.debug("Using an existing JAXBContext");
-            }
-        }
-        return jaxbContext;
+    public Message getMessage() {
+        return message;
     }
 
-    /** @return RPC Declared Type */
-    public Class getProcessType() {
-        return processType;
+    public void setMessage(Message message) {
+        this.message = message;
     }
 
-    /**
-     * Set RPC Declared Type.  The use of use this property if the message is style=document is
-     * discouraged.
-     *
-     * @param type
-     */
-    public void setProcessType(Class type) {
-        processType = type;
+    protected AttachmentMarshaller createAttachmentMarshaller(XMLStreamWriter writer) {
+        return new JAXBAttachmentMarshaller(getMessage(), writer);
     }
-
-    public JAXBUtils.CONSTRUCTION_TYPE getConstructionType() {
-        return constructionType;
+    
+    protected AttachmentUnmarshaller createAttachmentUnmarshaller() {
+        return new JAXBAttachmentUnmarshaller(getMessage());
     }
 
-    public boolean isxmlList() {
-        return isxmlList;
+    public ClassLoader getClassLoader() {
+        if(message != null && message.getMessageContext() != null) {
+            return (ClassLoader) message.getMessageContext().
+                getProperty(Constants.CACHE_CLASSLOADER);
+        }
+        return super.getClassLoader();
     }
 
-    public void setIsxmlList(boolean isxmlList) {
-        this.isxmlList = isxmlList;
+    public MessageContext getMessageContext() {
+        if(message != null && message.getMessageContext() != null &&
+           message.getMessageContext().getAxisMessageContext() != null) {
+            super.setMessageContext(message.getMessageContext().getAxisMessageContext());
+        }
+        return super.getMessageContext();
     }
     
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org