wtanaka.praya
Class Protocol

java.lang.Object
  |
  +--wtanaka.praya.Protocol
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
BnetClient, Chimer, DictClient, GaleClient, IRCClient, MsnClient, YahooClient, ZhongWenClient

public abstract class Protocol
extends java.lang.Object
implements java.io.Serializable

Abstract base class for all protocols. This needs to be simplified.

Return to Sourceforge or the Praya Homepage

Version:
$Name: $ $Date: 2002/07/14 23:34:51 $
Author:
$Author: wtanaka $
See Also:
Serialized Form

Field Summary
private  java.util.Vector descriptionListeners
           
private  boolean iAmGarbage
           
private  java.util.Hashtable m_buddyList
           
protected  java.awt.Component m_configPanel
           
private  java.lang.String m_currentDescription
           
private  java.util.Vector m_messageListeners
           
private  java.util.Vector recipientListeners
           
 
Constructor Summary
Protocol()
           
 
Method Summary
 void addDescriptionListener(ProtocolDescriptionListener list)
           
 void addListener(Pushable listener)
          Adds listener to the list of listeners that get notified when a message is generated from this protocol (i.e.
protected  void addRecipient(Recipient r, Status initial)
          Adds a recipient to this protocol's buddy list.
 void addRecipientListener(ProtocolRecipientListener list)
           
protected  void changeRecipientStatus(Recipient r, Status s)
          Changes the status of a recipient in the buddy list, adding the recipient if she doesn't already exist.
abstract  void checkForNewMessages(boolean isAutomatic)
          Checks for new messages on the protocol.
 void clearBuddyList()
          Clears the buddy list.
abstract  void connect()
          Connects to the network, if that makes any sense.
 java.lang.String console(java.lang.String command)
          Protocol console command handler method.
abstract  CommandInterface[] consoleCommands()
          Returns a list of commands available through this console.
abstract  void disconnect()
          Disconnects from the network, if that makes any sense.
private  void fireDescriptionChanged(java.lang.String desc)
          Send a descriptionChanged to all ProtocolDescriptionListener listeners
private  void fireRecipientAppeared(ProtocolRecipientEvent evt)
          Maps from Recipient to Status
private  void fireRecipientChanged(ProtocolRecipientEvent evt)
           
private  void fireRecipientDisappeared(ProtocolRecipientEvent evt)
           
 java.util.Enumeration getBuddies()
          Gets the list of Recipient representing the buddies for this Protocol.
 java.awt.Component getConfigPanelInstance()
          Returns the sole instance of the config panel for this protocol instance, creating a new one if necessary.
 ConfigItem[] getConfiguration()
           
 java.lang.String getCurrentDescription()
          Gets the current description.
abstract  Recipient getDefaultRecipient()
           
static java.awt.Image getIcon()
           
 ProtoObj getObjInstance(NormalFolder rootFolder)
          Returns the sole instance of the ProtoObj for this protocol instance, creating a new one if necessary.
static java.lang.String getProtocolDescription()
          Used to describe the class of this protocol, before any instances have been created.
 Status getStatusForBuddy(Recipient r)
           
 void initialize()
          Runs any initialization for this protocol after the listener has been added.
abstract  boolean isConnected()
          Returns if the protocol is connected right now.
 boolean isGarbage()
          has this protocol been removed from the UI?
 void markAsGarbage()
          sets this protocol as garbage.
 void pushMessage(Message m)
           
private  void readObject(java.io.ObjectInputStream in)
           
 void removeDescriptionListener(ProtocolDescriptionListener list)
           
 void removeListener(Pushable listener)
           
protected  void removeRecipient(Recipient r)
          Removes a recipient from this protocol's buddy list.
 void removeRecipientListener(ProtocolRecipientListener list)
           
 void setCurrentDescription(java.lang.String desc)
          This sets the string that is displayed in the titlebar of the console window, next to the protocol (so that you can select it), etc.
abstract  void setStatus(Status status)
          Sets the currently connected user's status to the given status.
private  void writeObject(java.io.ObjectOutputStream out)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

iAmGarbage

private boolean iAmGarbage

m_messageListeners

private java.util.Vector m_messageListeners

m_currentDescription

private java.lang.String m_currentDescription
See Also:
setCurrentDescription(java.lang.String)

m_buddyList

private java.util.Hashtable m_buddyList

m_configPanel

protected java.awt.Component m_configPanel

descriptionListeners

private java.util.Vector descriptionListeners

recipientListeners

private java.util.Vector recipientListeners
Constructor Detail

Protocol

public Protocol()
Method Detail

writeObject

private void writeObject(java.io.ObjectOutputStream out)
                  throws java.io.IOException

readObject

private void readObject(java.io.ObjectInputStream in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException

initialize

public void initialize()
Runs any initialization for this protocol after the listener has been added.

disconnect

public abstract void disconnect()
Disconnects from the network, if that makes any sense. skip if it does not.

connect

public abstract void connect()
                      throws java.io.IOException,
                             java.lang.InterruptedException
Connects to the network, if that makes any sense. skip if it does not.
Throws:
java.io.IOException - if the connection fails due to an I/O error.
java.lang.InterruptedException - todo, why does it throw this?

setStatus

public abstract void setStatus(Status status)
                        throws java.io.IOException
Sets the currently connected user's status to the given status.

isConnected

public abstract boolean isConnected()
Returns if the protocol is connected right now. Good for telling if you need to call connect() again after the connection dies.

getConfiguration

public ConfigItem[] getConfiguration()
Returns:
(self != null) list of configuration items for this protocol.

getConfigPanelInstance

public java.awt.Component getConfigPanelInstance()
Returns the sole instance of the config panel for this protocol instance, creating a new one if necessary.

getObjInstance

public ProtoObj getObjInstance(NormalFolder rootFolder)
Returns the sole instance of the ProtoObj for this protocol instance, creating a new one if necessary. This should replace getConfigPanelInstance later.

checkForNewMessages

public abstract void checkForNewMessages(boolean isAutomatic)
                                  throws java.io.IOException
Checks for new messages on the protocol. This might make sense for nntp/usenet, email, etc. but not for irc, gale, zephyr, icq. If any new messages are found, push them.
Parameters:
isAutomatic - true if the check is generated automatically with a timer. false if the check is generated manually by the user.

addListener

public void addListener(Pushable listener)
Adds listener to the list of listeners that get notified when a message is generated from this protocol (i.e. received off the network)

removeListener

public void removeListener(Pushable listener)

pushMessage

public void pushMessage(Message m)

addDescriptionListener

public final void addDescriptionListener(ProtocolDescriptionListener list)

removeDescriptionListener

public final void removeDescriptionListener(ProtocolDescriptionListener list)

fireDescriptionChanged

private final void fireDescriptionChanged(java.lang.String desc)
Send a descriptionChanged to all ProtocolDescriptionListener listeners

setCurrentDescription

public void setCurrentDescription(java.lang.String desc)
This sets the string that is displayed in the titlebar of the console window, next to the protocol (so that you can select it), etc. It should describe the nature of the protocol, and anything interesting about this particular instance (perhaps a username, or the connection state) The protocol name should come first.
See Also:
getCurrentDescription()

getCurrentDescription

public java.lang.String getCurrentDescription()
Gets the current description.
See Also:
setCurrentDescription(java.lang.String)

addRecipientListener

public final void addRecipientListener(ProtocolRecipientListener list)

removeRecipientListener

public final void removeRecipientListener(ProtocolRecipientListener list)

fireRecipientAppeared

private void fireRecipientAppeared(ProtocolRecipientEvent evt)
Maps from Recipient to Status

fireRecipientDisappeared

private void fireRecipientDisappeared(ProtocolRecipientEvent evt)

fireRecipientChanged

private void fireRecipientChanged(ProtocolRecipientEvent evt)

addRecipient

protected void addRecipient(Recipient r,
                            Status initial)
Adds a recipient to this protocol's buddy list.

removeRecipient

protected void removeRecipient(Recipient r)
Removes a recipient from this protocol's buddy list.

changeRecipientStatus

protected void changeRecipientStatus(Recipient r,
                                     Status s)
Changes the status of a recipient in the buddy list, adding the recipient if she doesn't already exist.

getBuddies

public java.util.Enumeration getBuddies()
Gets the list of Recipient representing the buddies for this Protocol.
Returns:
an Enumeration of Recipient, the list of buddies for this Protocol.
See Also:
Recipient

getStatusForBuddy

public Status getStatusForBuddy(Recipient r)
Returns:
the status for the given buddy, null, if we do not know about that buddy.

clearBuddyList

public void clearBuddyList()
Clears the buddy list.

getDefaultRecipient

public abstract Recipient getDefaultRecipient()

markAsGarbage

public void markAsGarbage()
sets this protocol as garbage. This is called when the protocol is no longer accessible through the UI, but may have some messages still displayed.

isGarbage

public boolean isGarbage()
has this protocol been removed from the UI?
Returns:
true if it is no longer valid, false otherwise

console

public final java.lang.String console(java.lang.String command)
                               throws IllegalCommandException,
                                      java.io.IOException
Protocol console command handler method. Uses consoleCommands()
Returns:
null if the event was handled properly and does not warrant a response, else a string to be said to the user.
Throws:
IllegalCommandException - if the command is invalid
java.io.IOException - if an i/o exception occurs processing the command.
See Also:
consoleCommands()

consoleCommands

public abstract CommandInterface[] consoleCommands()
Returns a list of commands available through this console.

getIcon

public static java.awt.Image getIcon()

getProtocolDescription

public static java.lang.String getProtocolDescription()
Used to describe the class of this protocol, before any instances have been created.