You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2016/05/01 10:22:49 UTC

svn commit: r1741845 - in /webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom: attachments/LegacyPartDataHandler.java attachments/MIMEMessage.java attachments/MIMEMessageAdapter.java attachments/PartImpl.java mime/DataHandlerFactory.java

Author: veithen
Date: Sun May  1 08:22:49 2016
New Revision: 1741845

URL: http://svn.apache.org/viewvc?rev=1741845&view=rev
Log:
Further decouple MIMEMessage from the legacy attachments API.

Added:
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/DataHandlerFactory.java   (with props)
Modified:
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/LegacyPartDataHandler.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/LegacyPartDataHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/LegacyPartDataHandler.java?rev=1741845&r1=1741844&r2=1741845&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/LegacyPartDataHandler.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/LegacyPartDataHandler.java Sun May  1 08:22:49 2016
@@ -29,7 +29,7 @@ import org.apache.axiom.mime.Part;
 import org.apache.axiom.mime.PartDataHandler;
 
 final class LegacyPartDataHandler extends PartDataHandler implements DataHandlerExt {
-    public LegacyPartDataHandler(Part part) {
+    LegacyPartDataHandler(Part part) {
         super(part);
     }
 

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java?rev=1741845&r1=1741844&r2=1741845&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java Sun May  1 08:22:49 2016
@@ -32,6 +32,7 @@ import javax.activation.DataHandler;
 import org.apache.axiom.blob.MemoryBlob;
 import org.apache.axiom.blob.WritableBlobFactory;
 import org.apache.axiom.mime.ContentType;
+import org.apache.axiom.mime.DataHandlerFactory;
 import org.apache.axiom.mime.Header;
 import org.apache.axiom.mime.Part;
 import org.apache.axiom.om.OMException;
@@ -70,10 +71,13 @@ class MIMEMessage implements Iterable<Pa
     private PartImpl rootPart;
 
     private final WritableBlobFactory<?> attachmentBlobFactory;
+    private final DataHandlerFactory dataHandlerFactory;
     
     MIMEMessage(InputStream inStream, String contentTypeString,
-            WritableBlobFactory<?> attachmentBlobFactory) throws OMException {
+            WritableBlobFactory<?> attachmentBlobFactory,
+            DataHandlerFactory dataHandlerFactory) throws OMException {
         this.attachmentBlobFactory = attachmentBlobFactory;
+        this.dataHandlerFactory = dataHandlerFactory;
         try {
             contentType = new ContentType(contentTypeString);
         } catch (ParseException e) {
@@ -117,6 +121,10 @@ class MIMEMessage implements Iterable<Pa
         return contentID;
     }
 
+    DataHandlerFactory getDataHandlerFactory() {
+        return dataHandlerFactory;
+    }
+
     ContentType getContentType() {
         return contentType;
     }

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java?rev=1741845&r1=1741844&r2=1741845&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java Sun May  1 08:22:49 2016
@@ -30,6 +30,7 @@ import javax.activation.DataHandler;
 
 import org.apache.axiom.blob.WritableBlobFactory;
 import org.apache.axiom.mime.ContentType;
+import org.apache.axiom.mime.DataHandlerFactory;
 import org.apache.axiom.mime.Header;
 import org.apache.axiom.mime.Part;
 import org.apache.axiom.om.OMException;
@@ -67,7 +68,12 @@ final class MIMEMessageAdapter extends A
             filterIS = null;
         }
 
-        this.message = new MIMEMessage(inStream, contentTypeString, attachmentBlobFactory);
+        this.message = new MIMEMessage(inStream, contentTypeString, attachmentBlobFactory, new DataHandlerFactory() {
+            @Override
+            public DataHandler createDataHandler(Part part) {
+                return new LegacyPartDataHandler(part);
+            }
+        });
 
         rootPart = message.getRootPart();
         String rootPartContentID = rootPart.getContentID();

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java?rev=1741845&r1=1741844&r2=1741845&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java Sun May  1 08:22:49 2016
@@ -88,7 +88,7 @@ final class PartImpl implements Part {
      */
     private WritableBlob content;
     
-    private final DataHandler dataHandler;
+    private DataHandler dataHandler;
     
     private PartInputStream partInputStream;
     
@@ -100,8 +100,6 @@ final class PartImpl implements Part {
         this.contentID = contentID;
         this.headers = headers;
         this.parser = parser;
-        // TODO: use factory here
-        this.dataHandler = new LegacyPartDataHandler(this);
     }
     
     public String getHeader(String name) {
@@ -132,6 +130,9 @@ final class PartImpl implements Part {
     }
     
     public DataHandler getDataHandler() {
+        if (dataHandler == null) {
+            dataHandler = message.getDataHandlerFactory().createDataHandler(this);
+        }
         return dataHandler;
     }
 

Added: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/DataHandlerFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/DataHandlerFactory.java?rev=1741845&view=auto
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/DataHandlerFactory.java (added)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/DataHandlerFactory.java Sun May  1 08:22:49 2016
@@ -0,0 +1,45 @@
+/*
+ * 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.axiom.mime;
+
+import javax.activation.DataHandler;
+
+/**
+ * Factory for the {@link DataHandler} instances returned by {@link Part#getDataHandler()}.
+ */
+public interface DataHandlerFactory {
+    /**
+     * Default factory that creates {@link PartDataHandler} instances.
+     */
+    DataHandlerFactory DEFAULT = new DataHandlerFactory() {
+        @Override
+        public DataHandler createDataHandler(Part part) {
+            return new PartDataHandler(part);
+        }
+    };
+
+    /**
+     * Create a data handler for the given MIME part.
+     * 
+     * @param part
+     *            the MIME part
+     * @return the data handler
+     */
+    DataHandler createDataHandler(Part part);
+}

Propchange: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/DataHandlerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native