hamsam.api
Class Message

java.lang.Object
  |
  +--hamsam.api.Message
All Implemented Interfaces:
java.io.Serializable

public class Message
extends java.lang.Object
implements java.io.Serializable

An instant message. Instant messages contain not only plain text messages, but various other things such as URLs, font and color variations, smileys etc. Unfortunately, different protocols use different encoding schemes for sending instant messages. This class provides an implementation independent way of representing instant messages, so that users of Hamsam library do not have to worry about proprietory message formats.

Each message object contains a sequence of message components. Each message component will be one of the following.

1. TextComponent

A text component contains a sequence of characters that represent a message. This sequence, together with the font and color information, determines what to display to the user.

2. SmileyComponent

This is a small picture, sometimes referred to as an emoticon, used to represent a user's emotions. For each smiley, there will be an alternate text representation. For clients that don't want to display smileys, may use this text representation.

3. URLComponent

A URL is special in that clients may want to show it as a "web link" rather than plain text. The URL component allows this by providing a link text and link URL. The link text is a text component that needs to be displayed to the user, while the link URL is a URL to which the user may connect to.

All the message components mentioned above are inherited from the MessageComponent interface. You can use these components in an IMListener as shown below.

public void instantMessageReceived(Buddy buddy, Message message) { Enumeration e = message.getComponents(); while(e.hasMoreElements()) { MessageComponent comp = (MessageComponent) e.nextElement(); if(comp instanceof TextComponent) { // handle text component } else if(comp instanceof SmileyComponent) { // handle smiley component } else if(comp instanceof URLComponent) { // handle URL component } } }

See Also:
Serialized Form

Constructor Summary
Message()
          Default constructor.
 
Method Summary
 void addComponent(MessageComponent comp)
          Add a message component to this message.
 java.util.Enumeration getComponents()
          Returns an enumeration of the components of this message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Message

public Message()
Default constructor.

Method Detail

addComponent

public void addComponent(MessageComponent comp)
Add a message component to this message.

Parameters:
comp - the component to be added.

getComponents

public java.util.Enumeration getComponents()
Returns an enumeration of the components of this message. The returned Enumeration object will generate all message components in this message.

Returns:
an enumeration of the message components of this message.
See Also:
MessageComponent