ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1748305 - in /webservices/axiom/trunk: aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/ aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/ aspects/om-aspects/src/main/java/org/apache/axiom/so...
Date Mon, 13 Jun 2016 19:32:50 GMT
Author: veithen
Date: Mon Jun 13 19:32:50 2016
New Revision: 1748305

URL: http://svn.apache.org/viewvc?rev=1748305&view=rev
Log:
Enable creation of builders from MIMEMessage objects and deprecate the OMXMLBuilderFactory
methods that take an Attachments argument.

Added:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Detachable.java
      - copied, changed from r1748300, webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/Detachable.java
Removed:
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/AttachmentsMimePartProvider.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/
Modified:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/OMXMLParserWrapperImpl.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/BuilderSpec.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableInputStream.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableReader.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/builder/SOAPModelBuilderImpl.java
    webservices/axiom/trunk/axiom-api/pom.xml
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentSet.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentsDelegate.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/mime/MIMEMessage.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/Part.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/PartImpl.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
    webservices/axiom/trunk/axiom-compat/src/main/java/org/apache/axiom/om/impl/builder/AttachmentsMimePartProvider.java

Copied: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Detachable.java
(from r1748300, webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/Detachable.java)
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Detachable.java?p2=webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Detachable.java&p1=webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/Detachable.java&r1=1748300&r2=1748305&rev=1748305&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/Detachable.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Detachable.java
Mon Jun 13 19:32:50 2016
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.axiom.om.impl.builder;
+package org.apache.axiom.om.impl.common.builder;
 
 import org.apache.axiom.om.OMException;
 

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/OMXMLParserWrapperImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/OMXMLParserWrapperImpl.java?rev=1748305&r1=1748304&r2=1748305&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/OMXMLParserWrapperImpl.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/OMXMLParserWrapperImpl.java
Mon Jun 13 19:32:50 2016
@@ -27,7 +27,6 @@ import org.apache.axiom.om.OMXMLParserWr
 import org.apache.axiom.om.ds.custombuilder.CustomBuilder;
 import org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport;
 import org.apache.axiom.om.ds.custombuilder.CustomBuilder.Selector;
-import org.apache.axiom.om.impl.builder.Detachable;
 import org.apache.axiom.om.impl.common.AxiomExceptionTranslator;
 import org.apache.axiom.om.impl.intf.AxiomDocument;
 

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/BuilderSpec.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/BuilderSpec.java?rev=1748305&r1=1748304&r2=1748305&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/BuilderSpec.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/BuilderSpec.java
Mon Jun 13 19:32:50 2016
@@ -37,9 +37,10 @@ import org.apache.axiom.core.stream.Name
 import org.apache.axiom.core.stream.XmlInput;
 import org.apache.axiom.core.stream.dom.DOMInput;
 import org.apache.axiom.core.stream.sax.SAXInput;
+import org.apache.axiom.mime.MIMEMessage;
 import org.apache.axiom.mime.MimePartProvider;
 import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.impl.builder.Detachable;
+import org.apache.axiom.om.impl.common.builder.Detachable;
 import org.apache.axiom.om.impl.stream.stax.pull.StAXPullInput;
 import org.apache.axiom.om.impl.stream.xop.XOPDecodingFilter;
 import org.apache.axiom.om.util.StAXParserConfiguration;
@@ -178,13 +179,24 @@ final class BuilderSpec {
     }
 
     static BuilderSpec from(StAXParserConfiguration configuration,
-            InputSource rootPart, MimePartProvider mimePartProvider) {
+            InputSource rootPart, final MimePartProvider mimePartProvider) {
         BuilderSpec spec = create(configuration, rootPart, false);
+        Detachable detachable;
+        if (mimePartProvider instanceof MIMEMessage) {
+            detachable = new Detachable() {
+                @Override
+                public void detach() {
+                    ((MIMEMessage)mimePartProvider).detach();
+                }
+            };
+        } else {
+            detachable = null;
+        }
         return new BuilderSpec(
                 new FilteredXmlInput(
                         spec.getInput(),
                         new XOPDecodingFilter(mimePartProvider)),
-                mimePartProvider instanceof Detachable ? (Detachable) mimePartProvider :
null);
+                detachable);
     }
 
     static BuilderSpec from(StAXParserConfiguration configuration, Source source, MimePartProvider
mimePartProvider) {

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableInputStream.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableInputStream.java?rev=1748305&r1=1748304&r2=1748305&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableInputStream.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableInputStream.java
Mon Jun 13 19:32:50 2016
@@ -25,7 +25,7 @@ import org.apache.axiom.blob.Blobs;
 import org.apache.axiom.blob.MemoryBlob;
 import org.apache.axiom.ext.io.StreamCopyException;
 import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.impl.builder.Detachable;
+import org.apache.axiom.om.impl.common.builder.Detachable;
 
 final class DetachableInputStream extends InputStream implements Detachable {
     private InputStream target;

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableReader.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableReader.java?rev=1748305&r1=1748304&r2=1748305&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableReader.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableReader.java
Mon Jun 13 19:32:50 2016
@@ -29,7 +29,7 @@ import java.nio.charset.Charset;
 import org.apache.axiom.blob.Blobs;
 import org.apache.axiom.blob.MemoryBlob;
 import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.impl.builder.Detachable;
+import org.apache.axiom.om.impl.common.builder.Detachable;
 
 final class DetachableReader extends Reader implements Detachable {
     private static final Charset UTF8 = Charset.forName("UTF-8");

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/builder/SOAPModelBuilderImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/builder/SOAPModelBuilderImpl.java?rev=1748305&r1=1748304&r2=1748305&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/builder/SOAPModelBuilderImpl.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/builder/SOAPModelBuilderImpl.java
Mon Jun 13 19:32:50 2016
@@ -21,7 +21,7 @@ package org.apache.axiom.soap.impl.commo
 
 import org.apache.axiom.core.impl.builder.BuilderImpl;
 import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.impl.builder.Detachable;
+import org.apache.axiom.om.impl.common.builder.Detachable;
 import org.apache.axiom.om.impl.common.builder.OMXMLParserWrapperImpl;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPMessage;

Modified: webservices/axiom/trunk/axiom-api/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/pom.xml?rev=1748305&r1=1748304&r2=1748305&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/pom.xml (original)
+++ webservices/axiom/trunk/axiom-api/pom.xml Mon Jun 13 19:32:50 2016
@@ -277,11 +277,12 @@
                                         </value>
                                     </visibilityRules>
                                 </layer>
-                                <!-- layer>
+                                <layer>
+                                    <!-- The attachments API is considered a legacy API
and shouldn't be used anywhere. -->
                                     <packages>
                                         <value>org.apache.axiom.attachments</value>
                                     </packages>
-                                </layer -->
+                                </layer>
                                 <layer>
                                     <packages>
                                         <value>org.apache.axiom.util</value>
@@ -294,17 +295,13 @@
                                 </layer>
                             </layers>
                             <ignore>
-                                <!-- o.a.a.attachments shouldn't depend on o.a.a.om -->
-                                org.apache.axiom.attachments.Attachments -> org.apache.axiom.om.OMException,
-                                org.apache.axiom.attachments.AttachmentsDelegate -> org.apache.axiom.om.OMException,
-                                org.apache.axiom.attachments.AttachmentSet -> org.apache.axiom.om.OMException,
-                                org.apache.axiom.attachments.IncomingAttachmentStreams ->
org.apache.axiom.om.OMException,
-                                org.apache.axiom.attachments.MIMEMessageAdapter -> org.apache.axiom.om.OMException,
                                 <!-- Bad API design: a public API shouldn't depend on
classes in an impl package in its interface -->
                                 org.apache.axiom.attachments.lifecycle.LifecycleManager ->
org.apache.axiom.attachments.lifecycle.impl.FileAccessor,
                                 <!-- TODO -->
                                 org.apache.axiom.mime.MIMEMessage -> org.apache.axiom.om.OMException,
                                 org.apache.axiom.mime.PartImpl -> org.apache.axiom.om.OMException,
+                                org.apache.axiom.om.impl.OMMultipartWriter -> org.apache.axiom.attachments.ConfigurableDataHandler,
+                                org.apache.axiom.om.ds.jaxb.AttachmentMarshallerImpl ->
org.apache.axiom.attachments.ByteArrayDataSource,
                                 <!-- o.a.a.soap should be a layer on top of o.a.a.om -->
                                 org.apache.axiom.om.OMAbstractFactory -> org.apache.axiom.soap.SOAPFactory,
                                 org.apache.axiom.om.OMMetaFactory -> org.apache.axiom.soap.SOAPFactory,
@@ -322,8 +319,6 @@
                                 org.apache.axiom.om.ds.AbstractPushOMDataSource -> org.apache.axiom.om.util.StAXUtils,
                                 org.apache.axiom.om.ds.BlobOMDataSource -> org.apache.axiom.om.util.StAXUtils,
                                 org.apache.axiom.om.ds.StringOMDataSource -> org.apache.axiom.om.util.StAXUtils,
-                                <!-- TODO: Detachable should go to om-aspects -->
-                                org.apache.axiom.om.impl.builder.Detachable -> org.apache.axiom.om.OMException,
                                 <!-- TODO -->
                                 org.apache.axiom.om.impl.OMMultipartWriter -> org.apache.axiom.om.util.CommonUtils,
                                 <!-- Incorrect layering -->

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentSet.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentSet.java?rev=1748305&r1=1748304&r2=1748305&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentSet.java
(original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentSet.java
Mon Jun 13 19:32:50 2016
@@ -28,6 +28,7 @@ import java.util.Set;
 import javax.activation.DataHandler;
 
 import org.apache.axiom.mime.ContentType;
+import org.apache.axiom.mime.MIMEMessage;
 import org.apache.axiom.om.OMException;
 
 /**
@@ -82,4 +83,10 @@ class AttachmentSet extends AttachmentsD
     long getContentLength() throws IOException {
         return -1;
     }
+
+    @Override
+    MIMEMessage getMIMEMessage() {
+        throw new IllegalStateException(
+                "The attachments map was created programatically. MIMEMessage is not available.");
+    }
 }

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java?rev=1748305&r1=1748304&r2=1748305&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
(original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
Mon Jun 13 19:32:50 2016
@@ -28,6 +28,7 @@ import org.apache.axiom.blob.WritableBlo
 import org.apache.axiom.blob.WritableBlobFactory;
 import org.apache.axiom.ext.activation.SizeAwareDataSource;
 import org.apache.axiom.mime.ContentType;
+import org.apache.axiom.mime.MIMEMessage;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.impl.MTOMConstants;
 
@@ -401,4 +402,8 @@ public class Attachments {
     public InputStream getIncomingAttachmentsAsSingleStream() throws IllegalStateException
{
         throw new UnsupportedOperationException();
     }
+
+    public MIMEMessage getMIMEMessage() {
+        return delegate.getMIMEMessage();
+    }
 }
\ No newline at end of file

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentsDelegate.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentsDelegate.java?rev=1748305&r1=1748304&r2=1748305&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentsDelegate.java
(original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentsDelegate.java
Mon Jun 13 19:32:50 2016
@@ -26,6 +26,7 @@ import java.util.Set;
 import javax.activation.DataHandler;
 
 import org.apache.axiom.mime.ContentType;
+import org.apache.axiom.mime.MIMEMessage;
 import org.apache.axiom.om.OMException;
 
 /**
@@ -59,4 +60,5 @@ abstract class AttachmentsDelegate {
     abstract Set<String> getContentIDs(boolean fetchAll);
     abstract Map<String,DataHandler> getMap();
     abstract long getContentLength() throws IOException;
+    abstract MIMEMessage getMIMEMessage();
 }

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=1748305&r1=1748304&r2=1748305&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
Mon Jun 13 19:32:50 2016
@@ -33,13 +33,14 @@ import org.apache.axiom.mime.ContentType
 import org.apache.axiom.mime.DataHandlerFactory;
 import org.apache.axiom.mime.Header;
 import org.apache.axiom.mime.MIMEMessage;
+import org.apache.axiom.mime.MIMEMessage.PartCreationListener;
 import org.apache.axiom.mime.Part;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.util.UIDGenerator;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-final class MIMEMessageAdapter extends AttachmentsDelegate {
+final class MIMEMessageAdapter extends AttachmentsDelegate implements PartCreationListener
{
     private static final Log log = LogFactory.getLog(MIMEMessageAdapter.class);
 
     private final MIMEMessage message;
@@ -74,15 +75,23 @@ final class MIMEMessageAdapter extends A
             public DataHandler createDataHandler(Part part) {
                 return new LegacyPartDataHandler(part);
             }
-        });
+        }, this);
 
         rootPart = message.getRootPart();
         String rootPartContentID = rootPart.getContentID();
         if (rootPartContentID == null) {
             rootPartContentID = "firstPart_" + UIDGenerator.generateContentId();
+            map.put(rootPartContentID, rootPart.getDataHandler());
         }
         this.rootPartContentID = rootPartContentID;
-        map.put(rootPartContentID, rootPart.getDataHandler());
+    }
+
+    @Override
+    public void partCreated(Part part) {
+        String contentID = part.getContentID();
+        if (contentID != null) {
+            map.put(contentID, part.getDataHandler());
+        }
     }
 
     private boolean fetchNext() {
@@ -93,6 +102,7 @@ final class MIMEMessageAdapter extends A
             partIterator = message.iterator();
         }
         if (partIterator.hasNext()) {
+            // This will add the DataHandler to the map (via the PartCreationListener interface)
             Part part = partIterator.next();
             if (part != rootPart) {
                 String contentID = part.getContentID();
@@ -100,7 +110,6 @@ final class MIMEMessageAdapter extends A
                     throw new OMException(
                             "Part content ID cannot be blank for non root MIME parts");
                 }
-                map.put(contentID, part.getDataHandler());
             }
             return true;
         } else {
@@ -205,4 +214,9 @@ final class MIMEMessageAdapter extends A
             return filterIS.getCount();
         }
     }
+
+    @Override
+    MIMEMessage getMIMEMessage() {
+        return message;
+    }
 }

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/MIMEMessage.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/MIMEMessage.java?rev=1748305&r1=1748304&r2=1748305&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/MIMEMessage.java
(original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/MIMEMessage.java
Mon Jun 13 19:32:50 2016
@@ -44,7 +44,11 @@ import org.apache.james.mime4j.stream.Re
 /**
  * Represents a MIME multipart message read from a stream.
  */
-public final class MIMEMessage implements Iterable<Part> {
+public final class MIMEMessage implements Iterable<Part>, MimePartProvider {
+    public interface PartCreationListener {
+        void partCreated(Part part);
+    }
+
     private static final Log log = LogFactory.getLog(MIMEMessage.class);
     
     /** <code>ContentType</code> of the MIME message */
@@ -67,12 +71,15 @@ public final class MIMEMessage implement
 
     private final WritableBlobFactory<?> attachmentBlobFactory;
     private final DataHandlerFactory dataHandlerFactory;
+    private final PartCreationListener partCreationListener;
     
     public MIMEMessage(InputStream inStream, String contentTypeString,
             WritableBlobFactory<?> attachmentBlobFactory,
-            DataHandlerFactory dataHandlerFactory) throws OMException {
+            DataHandlerFactory dataHandlerFactory,
+            PartCreationListener partCreationListener) throws OMException {
         this.attachmentBlobFactory = attachmentBlobFactory;
         this.dataHandlerFactory = dataHandlerFactory;
+        this.partCreationListener = partCreationListener;
         try {
             contentType = new ContentType(contentTypeString);
         } catch (ParseException e) {
@@ -124,14 +131,20 @@ public final class MIMEMessage implement
         return contentType;
     }
 
-    DataHandler getDataHandler(String contentID) {
+    @Override
+    public boolean isLoaded(String contentID) {
+        // TODO: throw IllegalStateException if we know that the part doesn't exist
+        return partMap.containsKey(contentID);
+    }
+
+    public DataHandler getDataHandler(String contentID) {
         do {
             PartImpl part = partMap.get(contentID);
             if (part != null) {
                 return part.getDataHandler();
             }
         } while (getNextPart() != null);
-        return null;
+        throw new IllegalArgumentException("No MIME part found for content ID '" + contentID
+ "'");
     }
 
     PartImpl getFirstPart() {
@@ -210,6 +223,9 @@ public final class MIMEMessage implement
             if (isRootPart) {
                 rootPart = currentPart;
             }
+            if (partCreationListener != null) {
+                partCreationListener.partCreated(currentPart);
+            }
         }
         return currentPart;
     }
@@ -225,4 +241,10 @@ public final class MIMEMessage implement
     public Iterator<Part> iterator() {
         return new PartIterator(this);
     }
+
+    public void detach() {
+        while (getNextPart() != null) {
+            // Just loop
+        }
+    }
 }

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/Part.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/Part.java?rev=1748305&r1=1748304&r2=1748305&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/Part.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/Part.java Mon Jun
13 19:32:50 2016
@@ -49,6 +49,13 @@ public interface Part {
     String getHeader(String name);
 
     /**
+     * Get the content type of this part.
+     * 
+     * @return the parsed value of the {@code Content-Type} header
+     */
+    ContentType getContentType();
+
+    /**
      * Get the content ID of this part, i.e. the value of the {@code Content-ID} header with
the
      * enclosing brackets removed.
      * 
@@ -73,6 +80,7 @@ public interface Part {
      * @throws IOException
      *             if the content couldn't be read
      */
+    // TODO: should we really use IOException here?
     InputStream getInputStream(boolean preserve) throws IOException;
 
     /**

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/PartImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/PartImpl.java?rev=1748305&r1=1748304&r2=1748305&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/PartImpl.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/PartImpl.java Mon
Jun 13 19:32:50 2016
@@ -35,6 +35,7 @@ import javax.activation.DataHandler;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.text.ParseException;
 import java.util.Collections;
 import java.util.List;
 
@@ -71,7 +72,8 @@ final class PartImpl implements Part {
     private final WritableBlobFactory<?> blobFactory;
     
     private final String contentID;
-    private List<Header> headers;
+    private final List<Header> headers;
+    private ContentType contentType;
     
     private int state = STATE_UNREAD;
     
@@ -123,8 +125,15 @@ final class PartImpl implements Part {
         return contentID;
     }
 
-    public String getContentType() {
-        return getHeader("content-type");
+    public ContentType getContentType() {
+        if (contentType == null) {
+            try {
+                contentType = new ContentType(getHeader("content-type"));
+            } catch (ParseException ex) {
+                throw new OMException(ex);
+            }
+        }
+        return contentType;
     }
     
     public DataHandler getDataHandler() {

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java?rev=1748305&r1=1748304&r2=1748305&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
(original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
Mon Jun 13 19:32:50 2016
@@ -18,9 +18,9 @@
  */
 package org.apache.axiom.om;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
-import java.text.ParseException;
 
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamReader;
@@ -30,8 +30,9 @@ import javax.xml.transform.sax.SAXSource
 
 import org.apache.axiom.attachments.Attachments;
 import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
-import org.apache.axiom.mime.ContentType;
+import org.apache.axiom.mime.MIMEMessage;
 import org.apache.axiom.mime.MimePartProvider;
+import org.apache.axiom.mime.Part;
 import org.apache.axiom.om.util.StAXParserConfiguration;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.soap.SOAPModelBuilder;
@@ -437,9 +438,28 @@ public class OMXMLBuilderFactory {
      * @throws OMException
      *             if an error occurs while processing the content type information from
the
      *             {@link Attachments} object
+     * 
+     * @deprecated Use {@link #createOMBuilder(StAXParserConfiguration, MIMEMessage)} instead.
      */
     public static OMXMLParserWrapper createOMBuilder(StAXParserConfiguration configuration,
Attachments attachments) {
-        return createOMBuilder(OMAbstractFactory.getMetaFactory().getOMFactory(), configuration,
attachments);
+        return createOMBuilder(configuration, attachments.getMIMEMessage());
+    }
+    
+    /**
+     * Create an XOP aware model builder from the provided {@link MIMEMessage} object and
with a
+     * given parser configuration.
+     * 
+     * @param configuration
+     *            the parser configuration to use
+     * @param message
+     *            the MIME message
+     * @return the builder
+     * @throws OMException
+     *             if an error occurs while processing the content type information from
the
+     *             {@link MIMEMessage} object
+     */
+    public static OMXMLParserWrapper createOMBuilder(StAXParserConfiguration configuration,
MIMEMessage message) {
+        return createOMBuilder(OMAbstractFactory.getMetaFactory().getOMFactory(), configuration,
message);
     }
     
     /**
@@ -456,18 +476,34 @@ public class OMXMLBuilderFactory {
      * @throws OMException
      *             if an error occurs while processing the content type information from
the
      *             {@link Attachments} object
+     * 
+     * @deprecated Use {{@link #createOMBuilder(OMFactory, StAXParserConfiguration, MIMEMessage)}
+     *             instead.
      */
     public static OMXMLParserWrapper createOMBuilder(OMFactory omFactory,
             StAXParserConfiguration configuration, Attachments attachments) {
-        ContentType contentType;
-        try {
-            contentType = new ContentType(attachments.getRootPartContentType());
-        } catch (ParseException ex) {
-            throw new OMException(ex);
-        }
-        InputSource rootPart = getRootPartInputSource(attachments, contentType);
-        return omFactory.getMetaFactory().createOMBuilder(configuration, rootPart,
-                new AttachmentsMimePartProvider(attachments));
+        return createOMBuilder(omFactory, configuration, attachments.getMIMEMessage());
+    }
+
+    /**
+     * Create an XOP aware model builder from the provided {@link MIMEMessage} object using
a
+     * specified object model factory and with a given parser configuration.
+     * 
+     * @param omFactory
+     *            the object model factory to use
+     * @param configuration
+     *            the parser configuration to use
+     * @param message
+     *            the MIME message
+     * @return the builder
+     * @throws OMException
+     *             if an error occurs while processing the content type information from
the
+     *             {@link MIMEMessage} object
+     */
+    public static OMXMLParserWrapper createOMBuilder(OMFactory omFactory,
+            StAXParserConfiguration configuration, MIMEMessage message) {
+        return omFactory.getMetaFactory().createOMBuilder(configuration,
+                getRootPartInputSource(message), message);
     }
     
     public static OMXMLParserWrapper createOMBuilder(OMFactory omFactory,
@@ -617,9 +653,28 @@ public class OMXMLBuilderFactory {
      * @throws OMException
      *             if an error occurs while processing the content type information from
the
      *             {@link Attachments} object
+     * 
+     * @deprecated Use {@link #createSOAPModelBuilder(MIMEMessage)} instead
      */
     public static SOAPModelBuilder createSOAPModelBuilder(Attachments attachments) {
-        return createSOAPModelBuilder(OMAbstractFactory.getMetaFactory(), attachments);
+        return createSOAPModelBuilder(attachments.getMIMEMessage());
+    }
+    
+    /**
+     * Create an MTOM aware model builder from the provided {@link MIMEMessage} object. The
method
+     * will determine the SOAP version based on the content type information from the
+     * {@link MIMEMessage} object. It will configure the underlying parser as specified by
+     * {@link StAXParserConfiguration#SOAP}.
+     * 
+     * @param message
+     *            the MIME message
+     * @return the builder
+     * @throws OMException
+     *             if an error occurs while processing the content type information from
the
+     *             {@link MIMEMessage} object
+     */
+    public static SOAPModelBuilder createSOAPModelBuilder(MIMEMessage message) {
+        return createSOAPModelBuilder(OMAbstractFactory.getMetaFactory(), message);
     }
     
     /**
@@ -636,16 +691,32 @@ public class OMXMLBuilderFactory {
      * @throws OMException
      *             if an error occurs while processing the content type information from
the
      *             {@link Attachments} object
+     * 
+     * @deprecated Use {@link #createSOAPModelBuilder(OMMetaFactory, MIMEMessage)} instead.
      */
     public static SOAPModelBuilder createSOAPModelBuilder(OMMetaFactory metaFactory,
             Attachments attachments) {
-        ContentType contentType;
-        try {
-            contentType = new ContentType(attachments.getRootPartContentType());
-        } catch (ParseException ex) {
-            throw new OMException(ex);
-        }
-        String type = contentType.getParameter("type");
+        return createSOAPModelBuilder(metaFactory, attachments.getMIMEMessage());
+    }
+
+    /**
+     * Create an MTOM aware model builder from the provided {@link MIMEMessage} object using
a
+     * particular Axiom implementation. The method will determine the SOAP version based
on the
+     * content type information from the {@link MIMEMessage} object. It will configure the
+     * underlying parser as specified by {@link StAXParserConfiguration#SOAP}.
+     * 
+     * @param metaFactory
+     *            the meta factory for the Axiom implementation to use
+     * @param message
+     *            the MIME message
+     * @return the builder
+     * @throws OMException
+     *             if an error occurs while processing the content type information from
the
+     *             {@link MIMEMessage} object
+     */
+    public static SOAPModelBuilder createSOAPModelBuilder(OMMetaFactory metaFactory,
+            MIMEMessage message) {
+        String type = message.getRootPart().getContentType().getParameter("type");
         SOAPFactory soapFactory;
         if ("text/xml".equalsIgnoreCase(type)) {
             soapFactory = metaFactory.getSOAP11Factory();
@@ -654,15 +725,20 @@ public class OMXMLBuilderFactory {
         } else {
             throw new OMException("Unable to determine SOAP version");
         }
-        InputSource rootPart = getRootPartInputSource(attachments, contentType);
         return metaFactory.createSOAPModelBuilder(StAXParserConfiguration.SOAP, soapFactory,
-                rootPart, new AttachmentsMimePartProvider(attachments));
+                getRootPartInputSource(message), message);
     }
     
-    private static InputSource getRootPartInputSource(Attachments attachments, ContentType
contentType) {
-        InputSource rootPart = new InputSource(attachments.getRootPartInputStream(false));
-        rootPart.setEncoding(contentType.getParameter("charset"));
-        return rootPart;
+    private static InputSource getRootPartInputSource(MIMEMessage message) {
+        Part rootPart = message.getRootPart();
+        InputSource is;
+        try {
+            is = new InputSource(rootPart.getInputStream(false));
+        } catch (IOException ex) {
+            throw new OMException(ex);
+        }
+        is.setEncoding(rootPart.getContentType().getParameter("charset"));
+        return is;
     }
     
     public static SOAPModelBuilder createSOAPModelBuilder(OMMetaFactory metaFactory,

Modified: webservices/axiom/trunk/axiom-compat/src/main/java/org/apache/axiom/om/impl/builder/AttachmentsMimePartProvider.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-compat/src/main/java/org/apache/axiom/om/impl/builder/AttachmentsMimePartProvider.java?rev=1748305&r1=1748304&r2=1748305&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-compat/src/main/java/org/apache/axiom/om/impl/builder/AttachmentsMimePartProvider.java
(original)
+++ webservices/axiom/trunk/axiom-compat/src/main/java/org/apache/axiom/om/impl/builder/AttachmentsMimePartProvider.java
Mon Jun 13 19:32:50 2016
@@ -31,7 +31,7 @@ import org.apache.axiom.util.stax.xop.Mi
  * <p>
  * For internal use only.
  */
-public class AttachmentsMimePartProvider implements MimePartProvider, Detachable {
+public class AttachmentsMimePartProvider implements MimePartProvider {
     private final Attachments attachments;
 
     public AttachmentsMimePartProvider(Attachments attachments) {
@@ -51,8 +51,4 @@ public class AttachmentsMimePartProvider
             return dh;
         }
     }
-
-    public void detach() {
-        attachments.getAllContentIDs();
-    }
 }




Mime
View raw message