Author: jochen
Date: Tue Apr 15 04:30:30 2008
New Revision: 648212

URL: http://svn.apache.org/viewvc?rev=648212&view=rev
Log:
Opened the MTOMXMLStreamWriter for processing of attachments without OMText 
instances.

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/DefaultMTOMAttachment.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMAttachment.java
   (with props)
    webservices/commons/trunk/modules/axiom/target-eclipse/
    webservices/commons/trunk/modules/axiom/target-eclipse/classes/
    webservices/commons/trunk/modules/axiom/target-eclipse/test-classes/
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MIMEOutputUtils.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMXMLStreamWriter.java

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/DefaultMTOMAttachment.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/DefaultMTOMAttachment.java?rev=648212&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/DefaultMTOMAttachment.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/DefaultMTOMAttachment.java
 Tue Apr 15 04:30:30 2008
@@ -0,0 +1,28 @@
+package org.apache.axiom.om.impl;
+
+import javax.activation.DataHandler;
+
+
+/**
+ * Default implementation of [EMAIL PROTECTED] MTOMAttachment}.
+ */
+public class DefaultMTOMAttachment implements MTOMAttachment {
+    private final String id;
+    private final DataHandler dataHandler;
+
+    /**
+     * Creates a new instance with the given data and content ID.
+     */
+    public DefaultMTOMAttachment(DataHandler pDataHandler, String pId) {
+        dataHandler = pDataHandler;
+        id = pId;
+    }
+
+    public String getContentID() {
+        return id;
+    }
+
+    public DataHandler getDataHandler() {
+        return dataHandler;
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/DefaultMTOMAttachment.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MIMEOutputUtils.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MIMEOutputUtils.java?rev=648212&r1=648211&r2=648212&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MIMEOutputUtils.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MIMEOutputUtils.java
 Tue Apr 15 04:30:30 2008
@@ -94,10 +94,24 @@
             // text nodes int the binary node list)
             Iterator binaryNodeIterator = binaryNodeList.iterator();
             while (binaryNodeIterator.hasNext()) {
-                OMText binaryNode = (OMText) binaryNodeIterator.next();
-                writeBodyPart(outStream, createMimeBodyPart(binaryNode
-                        .getContentID(), (DataHandler) binaryNode
-                        .getDataHandler()), boundary);
+                Object o = binaryNodeIterator.next();
+                /* Upwards compatibiliy: Should be an instance of
+                 * MTOMAttachment, if the user calls us via
+                 * [EMAIL PROTECTED] 
MTOMXMLStreamWriter#writeOptimized(OMText)},
+                 * or [EMAIL PROTECTED] 
MTOMXMLStreamWriter#writeOptimized(MTOMAttachment)}.
+                 * However, this is a public method and possibly someone
+                 * invokes us directly.
+                 */
+                final MTOMAttachment attachment;
+                if (o instanceof OMText) {
+                    final OMText omText = (OMText) o;
+                    attachment = new DefaultMTOMAttachment((DataHandler) 
omText.getDataHandler(), omText.getContentID());
+                } else {
+                    attachment = (MTOMAttachment) o;
+                }
+                writeBodyPart(outStream, createMimeBodyPart(attachment
+                        .getContentID(), attachment.getDataHandler()),
+                        boundary);
             }
             finishWritingMime(outStream);
             outStream.flush();

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMAttachment.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMAttachment.java?rev=648212&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMAttachment.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMAttachment.java
 Tue Apr 15 04:30:30 2008
@@ -0,0 +1,20 @@
+package org.apache.axiom.om.impl;
+
+import javax.activation.DataHandler;
+
+
+/**
+ * Interface of an MTOM attachment, as processed by
+ * [EMAIL PROTECTED] 
MTOMXMLStreamWriter#writeOptimized(org.apache.axiom.om.OMText)}
+ * and [EMAIL PROTECTED] MIMEOutputUtils#complete(java.io.OutputStream, 
java.io.StringWriter, java.util.LinkedList, String, String, String, String)}.
+ */
+public interface MTOMAttachment {
+    /**
+     * Returns the attachments ID.
+     */
+    String getContentID();
+    /**
+     * Returns the attachments contents.
+     */
+    DataHandler getDataHandler();
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMAttachment.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMXMLStreamWriter.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMXMLStreamWriter.java?rev=648212&r1=648211&r2=648212&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMXMLStreamWriter.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMXMLStreamWriter.java
 Tue Apr 15 04:30:30 2008
@@ -273,32 +273,46 @@
         return format.getContentType();
     }
 
-    public void writeOptimized(OMText node) {
-        if(log.isDebugEnabled()){
-            log.debug("Start MTOMXMLStreamWriter.writeOptimized()");
-        }
-        DataHandler dh = (DataHandler)node.getDataHandler();
-        int optimized = UNSUPPORTED;
-        if(dh!=null){
+    private boolean isAttachmentPossible(DataHandler pDataHandler) {
+        if (pDataHandler != null) {
             if(log.isDebugEnabled()){
                 log.debug("DataHandler fetched, starting optimized Threshold 
processing");
             }
-            optimized= BufferUtils.doesDataHandlerExceedLimit(dh, 
format.getOptimizedThreshold());
+            int optimized = 
BufferUtils.doesDataHandlerExceedLimit(pDataHandler, 
format.getOptimizedThreshold());
+            return optimized != UNSUPPORTED  &&  optimized != EXCEED_LIMIT;
         }
-        if(optimized == UNSUPPORTED || optimized == EXCEED_LIMIT){
-            if(log.isDebugEnabled()){
-                log.debug("node added to binart NodeList for optimization");
-            }
-            binaryNodeList.add(node);    
+        return false;
+    }
+
+    public void writeOptimized(MTOMAttachment attachment) {
+        if (log.isDebugEnabled()){
+            log.debug("Start MTOMXMLStreamWriter.writeOptimized()");
+        }
+        if (isAttachmentPossible(attachment.getDataHandler())) {
+            binaryNodeList.add(attachment);    
+        } else {
+            throw new RuntimeException("Unable to inline an attachment.");
+        }
+        if (log.isDebugEnabled()){
+            log.debug("Exit MTOMXMLStreamWriter.writeOptimized()");
+        }
+    }
+
+    public void writeOptimized(OMText node) {
+        if (log.isDebugEnabled()){
+            log.debug("Start MTOMXMLStreamWriter.writeOptimized()");
         }
-        else{
+        final DataHandler dh = (DataHandler) node.getDataHandler();
+        if (isAttachmentPossible(dh)) {
+            binaryNodeList.add(new DefaultMTOMAttachment(dh, 
node.getContentID()));
+        } else {
             try{
                 writeOutput(node);
-            }catch(XMLStreamException e){
+            } catch(XMLStreamException e) {
                 throw new RuntimeException("XMLStreamException in 
writeOutput() call", e);
             }
         }
-        if(log.isDebugEnabled()){
+        if (log.isDebugEnabled()){
             log.debug("Exit MTOMXMLStreamWriter.writeOptimized()");
         }
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to