1 package org.springframework.ws.mime; 2 3 import java.io.File; 4 import java.util.Iterator; 5 import javax.activation.DataHandler; 6 7 import org.springframework.core.io.InputStreamSource; 8 import org.springframework.ws.WebServiceMessage; 9 10 /** 11 * Represents a Web service message with MIME attachments. Attachments can be added as a file, an {@link 12 * InputStreamSource}, or a {@link DataHandler}. 13 * 14 * @author Arjen Poutsma 15 * @see Attachment 16 * @since 1.0.0 17 */ 18 public interface MimeMessage extends WebServiceMessage { 19 20 /** 21 * Indicates whether this message is a XOP package. 22 * 23 * @return <code>true</code> when the constraints specified in <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#identifying_xop_documents">Identifying 24 * XOP Documents</a> are met. 25 * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#xop_packages">XOP Packages</a> 26 */ 27 boolean isXopPackage(); 28 29 /** 30 * Turns this message into a XOP package. 31 * 32 * @return <code>true</code> when the message is a XOP package 33 * @see <a href="http://www.w3.org/TR/2005/REC-xop10-20050125/#xop_packages">XOP Packages</a> 34 */ 35 boolean convertToXopPackage(); 36 37 /** 38 * Returns the {@link Attachment} with the specified content Id. 39 * 40 * @return the attachment with the specified content id; or <code>null</code> if it cannot be found 41 * @throws AttachmentException in case of errors 42 */ 43 Attachment getAttachment(String contentId) throws AttachmentException; 44 45 /** 46 * Returns an <code>Iterator</code> over all {@link Attachment} objects that are part of this message. 47 * 48 * @return an iterator over all attachments 49 * @throws AttachmentException in case of errors 50 * @see Attachment 51 */ 52 Iterator getAttachments() throws AttachmentException; 53 54 /** 55 * Add an attachment to the message, taking the content from a {@link File}. 56 * <p/> 57 * The content type will be determined by the name of the given content file. Do not use this for temporary files 58 * with arbitrary filenames (possibly ending in ".tmp" or the like)! 59 * 60 * @param contentId the content Id of the attachment 61 * @param file the file to take the content from 62 * @return the added attachment 63 * @throws AttachmentException in case of errors 64 */ 65 Attachment addAttachment(String contentId, File file) throws AttachmentException; 66 67 /** 68 * Add an attachment to the message, taking the content from an {@link InputStreamSource}. 69 * <p/> 70 * Note that the stream returned by the source needs to be a <em>fresh one on each call</em>, as underlying 71 * implementations can invoke {@link InputStreamSource#getInputStream()} multiple times. 72 * 73 * @param contentId the content Id of the attachment 74 * @param inputStreamSource the resource to take the content from (all of Spring's Resource implementations can be 75 * passed in here) 76 * @param contentType the content type to use for the element 77 * @return the added attachment 78 * @throws AttachmentException in case of errors 79 * @see org.springframework.core.io.Resource 80 */ 81 Attachment addAttachment(String contentId, InputStreamSource inputStreamSource, String contentType); 82 83 /** 84 * Add an attachment to the message, taking the content from a {@link DataHandler}. 85 * 86 * @param dataHandler the data handler to take the content from 87 * @return the added attachment 88 * @throws AttachmentException in case of errors 89 */ 90 Attachment addAttachment(String contentId, DataHandler dataHandler); 91 }