com.arsdigita.messaging
Class ThreadedMessage

java.lang.Object
  extended bycom.arsdigita.domain.DomainObject
      extended bycom.arsdigita.domain.ObservableDomainObject
          extended bycom.arsdigita.kernel.ACSObject
              extended bycom.arsdigita.messaging.Message
                  extended bycom.arsdigita.messaging.ThreadedMessage
All Implemented Interfaces:
MessageType, MessageType

public class ThreadedMessage
extends Message

Extends Message in a way that allows messages to be organized into discussion threads with a tree structure. A typical discussion might be organized as follows:

     msg-0
         msg-0.0
         msg-0.1
             msg-0.1.0
             msg-0.1.1
         msg-0.2
     msg-1
         msg-1.0
     msg-2
 

where msg-0.0 and msg-0.1 are replies to msg-0, msg-0.1.0 is a reply to msg-0.1, and so forth. Messages at the first level (msg-0, msg-1, and msg-2) are referred to as "root" message, and higher-level messages contain a pointer to their common root. If a root message is deleted, all of its children are deleted.

A structure like the one shown above is created using the reply() method, which returns a new ThreadedMessage correctly initialized to represent a response to its parent. For example, you might generate a similar structure using:

     msg0 = new Message();       // root message

     msg00  = msg0.reply();      // level 1 replies
     msg01  = msg0.reply();

     msg010 = msg01.reply();     // level 2 replies (to msg01)
     msg011 = msg01.reply();
 

Replying to a message always generates a new message one level deeper in the tree. Successive replies to the same message generate the appropriate "next child" for that message.

Version:
$Id: //core-platform/dev/services/messaging/src/ThreadedMessage.java#3 $
Author:
Ron Henderson

Field Summary
static String BASE_DATA_OBJECT_TYPE
          Base data object type.
 
Fields inherited from class com.arsdigita.messaging.Message
BODY, INREPLYTO, MESSAGE_ID, MESSAGE_PART, OBJECT_ID, REPLY_TO, SENDER, SENT, SUBJECT, TYPE
 
Fields inherited from class com.arsdigita.kernel.ACSObject
CONTAINER, DEFAULT_DOMAIN_CLASS, DISPLAY_NAME, ID, OBJECT_TYPE, versionId
 
Fields inherited from interface com.arsdigita.util.MessageType
TEXT_HTML, TEXT_PLAIN, TEXT_PREFORMATTED, TEXT_SMART
 
Constructor Summary
ThreadedMessage()
          Creates a new message with the sentDate initialized to the current time, but leaves all other parameters null.
ThreadedMessage(BigDecimal id)
          Creates a threaded message by retrieving it from the database using its id;
ThreadedMessage(DataObject dataObject)
          Creates a threaded message from its underlying data object.
ThreadedMessage(OID oid)
          Creates a threaded message by retrieving it from the database using its OID.
ThreadedMessage(Party f, String s)
          Creates a threaded message from a party with a given subject.
ThreadedMessage(Party from, String subject, String body)
          Creates a threaded message from a party with a given subject and body.
ThreadedMessage(String type)
          Creates a threaded message from its underlying data type.
 
Method Summary
protected  void afterSave()
           
protected  void beforeSave()
          Saves the message after verifying that the root and sort key are valid.
 int getDepth()
          Gets the depth of the message within a tree of messages.
 long getNumReplies()
          Deprecated. use getThread().getNumReplies();
 BigDecimal getRoot()
          Gets the ID of the root message associated with this family of messages.
 ThreadedMessage getRootMsg()
           
 SortKey getSortKey()
          Gets the value of the sort key (possibly null).
 MessageThread getThread()
          gets the MessageThread that this message belongs to
 ThreadedMessage newInstance()
           
 ThreadedMessage replyTo()
          Gets a new message that is suitable for a reply to this message.
 ThreadedMessage replyTo(Party from, String body)
          Gets a new message suitable for a reply to this message, with the given sender and message body.
 ThreadedMessage replyTo(ThreadedMessage reply)
           
 void setRoot(BigDecimal root)
          Deprecated. Use the replyTo() method instead of this method
 void setSortKey(SortKey key)
          Sets the value of the sort key.
 
Methods inherited from class com.arsdigita.messaging.Message
attach, attach, attach, attach, doWriteCheck, generateHTMLText, getAttachmentCount, getAttachments, getBody, getBodyAsHTML, getBodyType, getContainer, getDisplayName, getFrom, getMessageID, getRefersTo, getReplyInfo, getReplyTo, getRFCMessageID, getSentDate, getSubject, isContainerModified, isMimeType, reply, setBody, setFrom, setRefersTo, setRefersTo, setReplyTo, setRFCMessageID, setSentDate, setSubject, setText
 
Methods inherited from class com.arsdigita.kernel.ACSObject
assertPrivilege, checkPrivilege, doCreateCheck, getBaseDataObjectType, getDefaultDomainClass, getID, getSpecificObjectType, getSpecificOID, gimmeContainer, initialize, setID, setID
 
Methods inherited from class com.arsdigita.domain.ObservableDomainObject
addObserver, getObservers
 
Methods inherited from class com.arsdigita.domain.DomainObject
add, add, addToAssociation, afterDelete, beforeDelete, clear, delete, disconnect, equals, get, getObjectType, getOID, getSession, hashCode, 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 data object type.

Constructor Detail

ThreadedMessage

public ThreadedMessage()
Creates a new message with the sentDate initialized to the current time, but leaves all other parameters null.


ThreadedMessage

public ThreadedMessage(Party f,
                       String s)
Creates a threaded message from a party with a given subject.

Parameters:
f - the party sending the message
s - the subject of the message

ThreadedMessage

public ThreadedMessage(Party from,
                       String subject,
                       String body)
Creates a threaded message from a party with a given subject and body.

Parameters:
from - the party sending the message
subject - the subject of the message
body - the plain-text body of the message

ThreadedMessage

public ThreadedMessage(String type)
Creates a threaded message from its underlying data type.

Parameters:
type - the DataObject type.

ThreadedMessage

public ThreadedMessage(DataObject dataObject)
Creates a threaded message from its underlying data object.

Parameters:
dataObject - the DataObject representing this message.

ThreadedMessage

public ThreadedMessage(BigDecimal id)
                throws DataObjectNotFoundException
Creates a threaded message by retrieving it from the database using its id;


ThreadedMessage

public ThreadedMessage(OID oid)
                throws DataObjectNotFoundException
Creates a threaded message by retrieving it from the database using its OID.

Parameters:
oid - the OID of the message
Method Detail

newInstance

public ThreadedMessage newInstance()

replyTo

public ThreadedMessage replyTo(Party from,
                               String body)
Gets a new message suitable for a reply to this message, with the given sender and message body.

Parameters:
from - the Party sending the reply
body - the text/plain body of the reply

replyTo

public ThreadedMessage replyTo()
Gets a new message that is suitable for a reply to this message. The message object returned will have its root and sort key properties initialized so that it is a valid child of this message in the message tree.

For example, if root = 14 and sortKey = 04a, the new message will have root = 14 and sortKey = 04a000.

If this message already has many responses, the new sort key will be computed based on the maximum value of the current responses. Absolute uniqueness of sort keys is not guaranteed, but conflicts are highly unlikely.

Returns:
a new child response to this message.

replyTo

public ThreadedMessage replyTo(ThreadedMessage reply)

getRoot

public BigDecimal getRoot()
Gets the ID of the root message associated with this family of messages.

Returns:
the ID of the root message

getRootMsg

public ThreadedMessage getRootMsg()

setRoot

public void setRoot(BigDecimal root)
Deprecated. Use the replyTo() method instead of this method

Throws:
UnsupportedOperationException

getSortKey

public SortKey getSortKey()
Gets the value of the sort key (possibly null).

Returns:
the sort key

setSortKey

public void setSortKey(SortKey key)
Sets the value of the sort key.

Parameters:
key - is the sort key for this message

getDepth

public int getDepth()
Gets the depth of the message within a tree of messages.


getNumReplies

public long getNumReplies()
Deprecated. use getThread().getNumReplies();

Gets the number of replies in this thread. Note -- this is not the number of replies below this message, but the total number in the entire thread to which this message belongs.


getThread

public MessageThread getThread()
gets the MessageThread that this message belongs to


beforeSave

protected void beforeSave()
Saves the message after verifying that the root and sort key are valid. Also creates a new MessageThread if this is a root message.

Overrides:
beforeSave in class ACSObject

afterSave

protected void afterSave()
Overrides:
afterSave in class Message


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