User's Manual

Chapter 10. Kernel Tutorial 117
Note that the above two examples do not explicitly set a MIME type for the content. This is determined
automatically when the content is handed off to a DataHandler for processing. In both cases shown
above the content will be of type image/gif.
10.2.3.4. Simple Threading
A Message object can store a reference to another Message object to implement basic threading. A
reply is created using the reply() method of the parent Message:
Message parent = new Message(new BigDecimal(1234)); Message reply =
parent.reply();
reply.setFrom(from);
reply.setText("I do not agree, because...");
reply.save();
When a reply is created this way, the subject is initialized as appropriate for a reply to the parent, and a
reference to the parent message is stored internally. The client code must set other message properties,
including the body of the reply.
10.2.3.5. Advanced Threading
Many applications need to store a more complex, structured set of responses than the flat organization
provided by Message. The ThreadedMessage class provides support for organizing messages into
a tree structure as outlined above. The API for ThreadedMessage is identical, but the reply() also
takes care of setting a special sort key that determines the proper location of a message in the tree.
The following example shows a simple discussion thread and the technique used to retrieve all mes-
sages from the database for display in the correct order. The structure of the underlying tree is as
follows:
msg0
msg2
msg4
msg5
msg3
msg6
msg1
Although in a real application the structure of messages and replies would be generated over time, the
following example shows the sequence of calls that produces the same organization, for illustration
purposes.
// A common object that all messages refer to.
// In practice this might a forum or a content
// item that is being discussed by a group of
// collaborators.
ACSObject anchor;
// Create the message
ThreadedMessage msg[];
msg[0] = new ThreadedMessage();
msg[0].setRefersTo(anchor);
msg[1] = new ThreadedMessage();