Class MessageFactory


public class MessageFactory
extends java.lang.Object

A MessageFactory object is used to create any number of messages based on a default message. The default message is first specified in the constructor:

 messageFactory = new MessageFactory(message);

The default message can later be changed using setDefault(SpreadMessage):


To get a message from the factory, use createMessage():

 SpreadMessage message = messageFactory.createMessage();

Classes that extend MessageFactory can override createMessage() to provide behaviors other than simply cloning the default message. One example is a factory that sets a time-stamp in the message:

 public class TimeStampMessageFactory extends MessageFactory
     public SpreadMessage createMessage()
         SpreadMessage message = super.createMessage();
         message.setObject(new Long(System.currentTimeMillis()));
         return message;

Constructor Summary
MessageFactory(SpreadMessage message)
          Constructs a new MessageFactory and sets the default message.
Method Summary
 SpreadMessage createMessage()
          Returns a new message.
 void setDefault(SpreadMessage message)
          Sets a new default message for this factory.
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public MessageFactory(SpreadMessage message)
Constructs a new MessageFactory and sets the default message.
message - the default message
Method Detail


public void setDefault(SpreadMessage message)
Sets a new default message for this factory.
message - the new default message


public SpreadMessage createMessage()
Returns a new message. The message is a clone of the default message. If the default message has been specified as null, null is returned.
a new message