com.arsdigita.messaging
Class MessagePart

java.lang.Object
  extended bycom.arsdigita.domain.DomainObject
      extended bycom.arsdigita.domain.ObservableDomainObject
          extended bycom.arsdigita.messaging.MessagePart
All Implemented Interfaces:
MessageType, MessageType

public class MessagePart
extends ObservableDomainObject
implements MessageType

Represents a message part (that is, an attachment). Each part has a content represented as an arbitrary block of bytes and a MIME type that identifies the format of the content.

Version:
$Id: //core-platform/dev/src/com/arsdigita/messaging/MessagePart.java#9 $
Author:
Ron Henderson

Field Summary
static String ATTACHMENT
          Disposition of "attachment"
static String BASE_DATA_OBJECT_TYPE
          Base DataObject type
static String INLINE
          Disposition of "inline"
 
Fields inherited from class com.arsdigita.domain.ObservableDomainObject
versionId
 
Fields inherited from interface com.arsdigita.util.MessageType
TEXT_HTML, TEXT_PLAIN, TEXT_PREFORMATTED, TEXT_SMART
 
Constructor Summary
MessagePart()
          Default constructor.
MessagePart(DataObject dataObject)
          Creates a part from its underlying DataObject.
MessagePart(OID oid)
          Retrieves an existing part from the database using its OID.
MessagePart(String name)
          Creates a new MessagePart with a given name and default disposition of ATTACHMENT.
MessagePart(String name, String description)
          Creates a new MessagePart with a given name and description, and a disposition of ATTACHMENT.
MessagePart(String name, String description, String disposition)
          Creates a new MessagePart with a given name, description and disposition.
 
Method Summary
protected  String getBaseDataObjectType()
          Gets the base DataObject type.
 Object getContent()
          Returns the content of this part as an Object.
 String getContentType()
          Returns the MIME type of this part.
 javax.activation.DataHandler getDataHandler()
          Gets the DataHandler for this part.
 String getDescription()
          Gets the description of this part.
 String getDisposition()
          Gets the disposition of this part.
 String getName()
          Gets the name of this part.
 int getSize()
          Gets the size of the content of this part in bytes, or -1 if the size cannot be determined.
 void setContent(File file, String name, String description)
          Sets the content of this part to a file with a given name and description.
 void setContent(String text, String type)
          Convenience method that sets the given String as this part's content, with the specified MIME type.
protected  void setContentType(String type)
          Sets the MIME type of this part.
 void setDataHandler(javax.activation.DataHandler dh)
          Provides the mechanism to set this part's content for anything other than plain text attachments.
 void setDescription(String description)
          Sets the description of this part.
 void setDisposition(String disposition)
          Sets the disposition of this part.
 void setName(String name)
          Sets the name of this part.
 void setText(String text)
          Convenience method that sets the given String as this part's content, with a MIME type of "text/plain".
 
Methods inherited from class com.arsdigita.domain.ObservableDomainObject
addObserver, getObservers
 
Methods inherited from class com.arsdigita.domain.DomainObject
add, add, addToAssociation, afterDelete, afterSave, beforeDelete, beforeSave, clear, delete, disconnect, equals, get, getObjectType, getOID, getSession, hashCode, initialize, isDeleted, isDisconnected, isModified, isNew, isPropertyModified, isValid, remove, remove, remove, removeFromAssociation, save, set, setAssociation, setAssociation, specializeDataObject, specializeDataObject, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BASE_DATA_OBJECT_TYPE

public static final String BASE_DATA_OBJECT_TYPE
Base DataObject type


INLINE

public static final String INLINE
Disposition of "inline"

See Also:
Constant Field Values

ATTACHMENT

public static final String ATTACHMENT
Disposition of "attachment"

See Also:
Constant Field Values
Constructor Detail

MessagePart

public MessagePart()
Default constructor.


MessagePart

public MessagePart(OID oid)
            throws DataObjectNotFoundException
Retrieves an existing part from the database using its OID.

Parameters:
oid - the OID of the part

MessagePart

public MessagePart(DataObject dataObject)
            throws DataObjectNotFoundException
Creates a part from its underlying DataObject.

Parameters:
dataObject - the DataObject that represents this part

MessagePart

public MessagePart(String name)
Creates a new MessagePart with a given name and default disposition of ATTACHMENT.

Parameters:
name - the name of the part.

MessagePart

public MessagePart(String name,
                   String description)
Creates a new MessagePart with a given name and description, and a disposition of ATTACHMENT.

Parameters:
name - the name of the part.
description - a description of the part.

MessagePart

public MessagePart(String name,
                   String description,
                   String disposition)
Creates a new MessagePart with a given name, description and disposition.

Parameters:
name - the name of the part.
description - a description of the part.
disposition - the disposition of the part, INLINE or ATTACHMENT
Method Detail

getBaseDataObjectType

protected String getBaseDataObjectType()
Gets the base DataObject type.

Overrides:
getBaseDataObjectType in class DomainObject
Returns:
The fully qualified name ("modelName.typeName") of the base data object type for this domain object class, or null if there is no restriction on the data object type for the primary data object encapsulated by this class.

getName

public String getName()
Gets the name of this part.

Returns:
the name of this part.

setName

public void setName(String name)
Sets the name of this part.

Parameters:
name - the name of this part

getDescription

public String getDescription()
Gets the description of this part.

Returns:
the description of this part.

setDescription

public void setDescription(String description)
Sets the description of this part.

Parameters:
description - the description of this part

getContentType

public String getContentType()
Returns the MIME type of this part. Returns null if the content type cannot be determined.

Returns:
the MIME type of this part, or null if the content type cannot be determined.

setContentType

protected void setContentType(String type)
Sets the MIME type of this part. Protected because content type is normally set by one of the setContent methods. This is for internal package use only.

Parameters:
type - the content type of this part

getDisposition

public String getDisposition()
Gets the disposition of this part.

Returns:
the disposition of this part.

setDisposition

public void setDisposition(String disposition)
Sets the disposition of this part.

Parameters:
disposition - the disposition of this part

getSize

public int getSize()
Gets the size of the content of this part in bytes, or -1 if the size cannot be determined.

Returns:
the size of the content in bytes, or -1 if the size cannot be determined.

getContent

public Object getContent()
Returns the content of this part as an Object. The type of the Object returned depends on the content itself. For any primary MIME type of "text", the object returned is a String. For anything else, a ByteArrayInputStream is returned and applications can deal with processing the object appropriately.

Returns:
the content as a Java object.

setText

public void setText(String text)
Convenience method that sets the given String as this part's content, with a MIME type of "text/plain".

Parameters:
text - the plain text content of this part.

setContent

public void setContent(String text,
                       String type)
Convenience method that sets the given String as this part's content, with the specified MIME type.

Parameters:
text - the plain text content of this part.
type - the MIME type of this part.

setContent

public void setContent(File file,
                       String name,
                       String description)
                throws MessagingException
Sets the content of this part to a file with a given name and description.

Parameters:
file - the File to attach content from
name - the name of the file
description - the description of the file
Throws:
MessagingException
Since:
4.7.1

getDataHandler

public javax.activation.DataHandler getDataHandler()
Gets the DataHandler for this part.

Returns:
the DataHandler for this part.

setDataHandler

public void setDataHandler(javax.activation.DataHandler dh)
                    throws MessagingException
Provides the mechanism to set this part's content for anything other than plain text attachments. It does not work exactly like MimeBodyPart since the ACS persistence layer cannot deal with an InputStream for a BLOB (our internal representation of the content). Instead, this method retrieves the data from the given DataHandler and copies it to an internal buffer, where it can be passed into the persistence layer.

Therefore, if you call setDataHandler / getDataHandler you will get two distinct DataHandlers, one for the input data and one for the internal byte array that holds the content.

Parameters:
dh - the DataHandler for this part's content
Throws:
MessagingException


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC