This chapter tells you how you can convert the concepts discussed in the
previous chapter to code.
A client first has to get a list of all protocols supported by Hamsam,
this can be done by invoking ProtocolManager.getAvailableProtocols().
This returns an array of supported Protocols. You may identify
which all features are supported by one protocol, by invoke isXXXSupported()
methods. You can log in to a protocol by invoking Protocol.connect(username,
password, proxyInfo). Before that you have to setup a listener for this
protocol by invoking Protocol.setListener(IMListener)
method. You can either implement the IMListener interface or
extend the IMAdapter class.
After this, all the communication from the protocol to the client is via
the IMListener interface.
The concept of buddy is modeled in the class Buddy. After a successful log
in, the friend list is passed to you by IMListener.buddyListReceived(Protocol,
Buddy[]) method. The list of blocked users is passed by IMListener.ignoreListReceived(Protocol,
Buddy[]) method. All operations to be done on a buddy are to be done
through Buddy class.
You may change your status information by invoking Protocol.changeStatus(newStatus).
Whenever a user in friend list changes his/her status, you will be notified
through IMListener.buddyStatusChanged(Buddy)
method.
All instant messages of a normal IM session are sent out by invoking Buddy.sendInstantMessage(Message).
All incoming instant messages will be notified through IMListener.instantMessageReceived(Buddy,
Message). In case of conferences, you should make use of the class Conference.
For sending rich text messages, the class Message should be used. Support
for font and color is provided in TextComponent. URLs
may be handled in URLComponent,
while smileys are modeled in SmileyComponent.
Support for operation behind a firewall, is provided by the ProxyInfo class.
The logging framework uses JDK 1.4 logging mechanism. You can get a Logger
object by invoking LogManager.getLogger().
Hamsam sends all log records to this logger.