uk.org.ogsadai.client.toolkit.soap
Class AttachmentManager

java.lang.Object
  |
  +--uk.org.ogsadai.client.toolkit.soap.AttachmentManager

public class AttachmentManager
extends java.lang.Object

This class is used to manage SOAP attachments.

Author:
OGSA-DAI team

Nested Class Summary
(package private) static class AttachmentManager.MemoryOnlyDataSource
          This class caches attachments in memory.
 
Field Summary
private static java.lang.String COPYRIGHT_NOTICE
          Copyright statement
private static DAILogger LOG
          Logger object for logging in this class
private  java.util.Vector mAttachmentParts
          Collection of attachment parts
 
Constructor Summary
AttachmentManager()
          Creates a new AttachmentManager object.
 
Method Summary
 void addAttachments(org.apache.axis.Message message)
          Adds stored attachemnts to a SOAP message.
 java.lang.String addFile(java.io.File file)
          Crates and stores new SOAP attachment created from a file.
 java.lang.String addNewOctetStream(byte[] data)
          Creates and stores new application/octet-stream MIME type attachment.
 java.lang.String addNewPlainText(java.lang.String data)
          Creates and stores new text/plain MIME type attachment.
 void addRcvOctetStreamText(byte[] data, java.lang.String contentID)
          Creates new application/octet-stream MIME type attachment and sets Content-Id MIME header to a user specified value.
 void addRcvPlainText(byte[] data, java.lang.String contentID)
          Creates new text/plain MIME type attachment and sets Content-Id MIME header to a user specified value.
 byte[] getAttachmentAsByteArray(java.lang.String contentID)
          Get attachment data as an array of bytes.
 java.io.InputStream getAttachmentAsInputStream(java.lang.String contentID)
          Get InputStream for data associated with the attachment described by the provided Content-Id MIME header.
 java.lang.String getAttachmentAsString(java.lang.String contentID)
          Get attachment data as an array of bytes.
 org.apache.axis.attachments.AttachmentPart getAttachmentPart(java.lang.String contentID)
          Searches stored attachments for a given value of the Content-Id MIME header and returns its reference.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT_NOTICE

private static final java.lang.String COPYRIGHT_NOTICE
Copyright statement

See Also:
Constant Field Values

LOG

private static final DAILogger LOG
Logger object for logging in this class


mAttachmentParts

private java.util.Vector mAttachmentParts
Collection of attachment parts

Constructor Detail

AttachmentManager

public AttachmentManager()
Creates a new AttachmentManager object.

Method Detail

addAttachments

public void addAttachments(org.apache.axis.Message message)
Adds stored attachemnts to a SOAP message.

Parameters:
message - The SOAP message.

addNewPlainText

public java.lang.String addNewPlainText(java.lang.String data)
                                 throws java.io.IOException
Creates and stores new text/plain MIME type attachment. Unique Content-Id MIME header identyfing this attachemnt is returned.

Parameters:
data - Textual data to be sent to the client as a SOAP attachment.
Returns:
Value of the Content-ID MIME Header.
Throws:
java.io.IOException - When there is a problem with creating DataSource for DataHandler.

addRcvPlainText

public void addRcvPlainText(byte[] data,
                            java.lang.String contentID)
                     throws java.io.IOException
Creates new text/plain MIME type attachment and sets Content-Id MIME header to a user specified value. This method is by the code that extracts attachments from recieved messages.

Parameters:
data - Byte array representing attachment data.
contentID - Value of Content-Id MIME header
Throws:
java.io.IOException - When there is a problem with creating DataSource for DataHandler.

addNewOctetStream

public java.lang.String addNewOctetStream(byte[] data)
                                   throws java.io.IOException
Creates and stores new application/octet-stream MIME type attachment. Unique Content-Id MIME header identyfing this attachemnt is returned.

Parameters:
data - Binary data to be sent to the client as a SOAP attachment.
Returns:
Value of the Content-ID MIME Header.
Throws:
java.io.IOException - When there is a problem with creating DataSource for DataHandler.

addRcvOctetStreamText

public void addRcvOctetStreamText(byte[] data,
                                  java.lang.String contentID)
                           throws java.io.IOException
Creates new application/octet-stream MIME type attachment and sets Content-Id MIME header to a user specified value. This method is by the code that extracts attachments from recieved messages.

Parameters:
data - Byte array representing attachment data.
contentID - Value of Content-Id MIME header
Throws:
java.io.IOException - When there is a problem with creating DataSource for DataHandler.

addFile

public java.lang.String addFile(java.io.File file)
Crates and stores new SOAP attachment created from a file. It tries to determine file type either by looking at file extension or by opening a file and trying to determine it automatically.Unique Content-Id MIME header identyfing this attachemnt is returned.

Parameters:
file - Reference to a File object to be sent to the client as a SOAP attachment.
Returns:
Value of the Content-ID MIME Header.
Throws:
java.io.IOException - When there is a problem with creating DataSource for DataHandler.

getAttachmentPart

public org.apache.axis.attachments.AttachmentPart getAttachmentPart(java.lang.String contentID)
Searches stored attachments for a given value of the Content-Id MIME header and returns its reference.

Parameters:
contentID - Value of attachment's Content-Id MIME header.
Returns:
AttachmentPart object associated with a given Content-Id

getAttachmentAsInputStream

public java.io.InputStream getAttachmentAsInputStream(java.lang.String contentID)
                                               throws SOAPAttachmentException
Get InputStream for data associated with the attachment described by the provided Content-Id MIME header.

Parameters:
contentID - Value of the Content-Id MIME header.
Returns:
The InputStream representing data.
Throws:
SOAPAttachmentException - If there is a problem with extracting data from attachment.

getAttachmentAsByteArray

public byte[] getAttachmentAsByteArray(java.lang.String contentID)
                                throws SOAPAttachmentException
Get attachment data as an array of bytes. This method makes a copy of attachement data. Consider using getAttachmentAsInputStream() when processing large attachments.

Parameters:
contentID - Value of the Content-Id MIME header.
Returns:
Byte array with attachment data.
Throws:
SOAPAttachmentException - If there is a problem with extracting data from attachment.

getAttachmentAsString

public java.lang.String getAttachmentAsString(java.lang.String contentID)
                                       throws SOAPAttachmentException
Get attachment data as an array of bytes. This method makes a copy of attachement data. Consider using getAttachmentAsInputStream() when processing large attachments.

Parameters:
contentID - Value of the Content-Id MIME header.
Returns:
String created from attachment data.
Throws:
SOAPAttachmentException - If there is a problem with extracting data from attachment.