org.nukesoft.bot2.core
Class Dialog

java.lang.Object
  |
  +--java.util.Observable
        |
        +--org.nukesoft.bot2.core.Dialog
All Implemented Interfaces:
LineProcContextCallback, Observer

public class Dialog
extends Observable
implements LineProcContextCallback, Observer

A Dialog is the bridge between CommPort objects and LineProc objects. They serve to provide the internal glue that binds the two ends togeather. All Dialog objects are managed by the DialogManager class.

Author:
Ryan Michela

Constructor Summary
Dialog(DialogManager manager, CommPort comm, DynamicLoadLPContext lineProc, String identity, String adminEscapeSequence, String adminLineProcBindID)
          Creates a dialog binding.
 
Method Summary
 void addObserver(Observer o)
           
 boolean bindConversation(String dialogID)
          Binds this dialog to another.
 void deleteObserver(Observer o)
           
 int getAge()
          Gets the Dialog age.
 Set getComPortBindIDs()
          Returns a set of comm port bind ids.
 Set getConversations()
          Returns a list of active conversations.
 String getIdentity()
          Returns this dialog's identity.
 Set getLineProcBindIDs()
          Returns a set of line proc bind ids.
 String getLineProcLibPath(String lineProcBindID)
          Returns the line proc lib path based on bind ID.
 String getWarningLevel()
          Gets the warning level from the CommLib.
 void handleIM(IM message)
          Handles incomming message from the CommLib.
 void handleWarn(String screenName)
          Handles incomming warning from the CommLib.
 void initiateConversation(String commPortBindID, String remoteScreenName, String salutation)
          Initiates a conversation.
 void interject(String dialogID, String interjection)
          Interjects text into a conversation.
 boolean loadNewLineProcOnPeer(String dialogID, String lineProcBindID)
          Tells a peer to load a new line proc.
 void sendIM(IM message)
          Sends an outbound IM.
 void sendWarning(String screenName, boolean anonymous)
          Sends an outbound warning.
 void shutdown()
          Cleanly shuts down the Dialog.
 void tickAge()
          Incraments the age by one.
 boolean unbindConversation(String dialogID)
          Unbinds this dialog from another.
 void update(Observable o, Object arg)
          Handles incomming message forewards.
 
Methods inherited from class java.util.Observable
clearChanged, countObservers, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Dialog

public Dialog(DialogManager manager,
              CommPort comm,
              DynamicLoadLPContext lineProc,
              String identity,
              String adminEscapeSequence,
              String adminLineProcBindID)
Creates a dialog binding.

Method Detail

handleIM

public void handleIM(IM message)
Handles incomming message from the CommLib.

Parameters:
message - The message to foreward.

handleWarn

public void handleWarn(String screenName)
Handles incomming warning from the CommLib.

Parameters:
screenName - The screen name doing the warning.

getConversations

public Set getConversations()
Returns a list of active conversations.

Specified by:
getConversations in interface LineProcContextCallback
Returns:
String array with fully qualified conversation names in the format CommPortBindName~ForeignScreenName.
See Also:
LineProcContextCallback.getConversations()

getIdentity

public String getIdentity()
Returns this dialog's identity.

Specified by:
getIdentity in interface LineProcContextCallback
Returns:
Identity string in the form CommPortBindName~ForeignScreenName.
See Also:
LineProcContextCallback.getIdentity()

getWarningLevel

public String getWarningLevel()
Gets the warning level from the CommLib.

Specified by:
getWarningLevel in interface LineProcContextCallback
Returns:
Integer string containing warning level if warning is supported on the supporting network. "N/A" if warning is not.
See Also:
LineProcContextCallback.getWarningLevel()

sendIM

public void sendIM(IM message)
Sends an outbound IM.

Specified by:
sendIM in interface LineProcContextCallback
Parameters:
message - The IM to send.
See Also:
LineProcContextCallback.sendIM(org.nukesoft.bot2.core.IM)

sendWarning

public void sendWarning(String screenName,
                        boolean anonymous)
Sends an outbound warning.

Specified by:
sendWarning in interface LineProcContextCallback
Parameters:
screenName - The screen name to warn.
anonymous - If TRUE, warn anonymously.
See Also:
LineProcContextCallback.sendWarning(java.lang.String, boolean)

bindConversation

public boolean bindConversation(String dialogID)
Binds this dialog to another.

Specified by:
bindConversation in interface LineProcContextCallback
Parameters:
dialogID - Dialog ID to bind to in the format CommPortBindName~ForeignScreenName.
See Also:
LineProcContextCallback.bindConversation(java.lang.String)

unbindConversation

public boolean unbindConversation(String dialogID)
Unbinds this dialog from another.

Specified by:
unbindConversation in interface LineProcContextCallback
Parameters:
dialogID - Dialog ID to unbind from in the format CommPortBindName~ForeignScreenName.
See Also:
LineProcContextCallback.unbindConversation(java.lang.String)

tickAge

public void tickAge()
Incraments the age by one.


getAge

public int getAge()
Gets the Dialog age.

Returns:
Age in seconds.

shutdown

public void shutdown()
Cleanly shuts down the Dialog.


update

public void update(Observable o,
                   Object arg)
Handles incomming message forewards.

Specified by:
update in interface Observer
Parameters:
arg - The third party IM
See Also:
Observer.update(java.util.Observable, java.lang.Object)

addObserver

public void addObserver(Observer o)
Overrides:
addObserver in class Observable
See Also:
Observable.addObserver(java.util.Observer)

deleteObserver

public void deleteObserver(Observer o)
Overrides:
deleteObserver in class Observable
See Also:
Observable.deleteObserver(java.util.Observer)

getComPortBindIDs

public Set getComPortBindIDs()
Returns a set of comm port bind ids.

Specified by:
getComPortBindIDs in interface LineProcContextCallback
Returns:
A set of Strings.
See Also:
LineProcContextCallback.getComPortBindIDs()

getLineProcBindIDs

public Set getLineProcBindIDs()
Returns a set of line proc bind ids.

Specified by:
getLineProcBindIDs in interface LineProcContextCallback
Returns:
A set of Strings.
See Also:
LineProcContextCallback.getLineProcBindIDs()

initiateConversation

public void initiateConversation(String commPortBindID,
                                 String remoteScreenName,
                                 String salutation)
Initiates a conversation.

Specified by:
initiateConversation in interface LineProcContextCallback
Parameters:
commPortBindID - The commPort to use for the dialog.
remoteScreenName - The screen name to initiate a conversation with.
salutation - The salutation to send them.
See Also:
LineProcContextCallback.initiateConversation(java.lang.String, java.lang.String, java.lang.String)

interject

public void interject(String dialogID,
                      String interjection)
Interjects text into a conversation. This is the sending half of the interjection system. When a dialog recieves a message to interject, it obtains a reference to the target Dialog and calls the handleInterjection() method on it.

Specified by:
interject in interface LineProcContextCallback
Parameters:
dialogID - The name of the dialog to interject into.
interjection - The text to interject with.
See Also:
LineProcContextCallback.interject(java.lang.String, java.lang.String)

getLineProcLibPath

public String getLineProcLibPath(String lineProcBindID)
Returns the line proc lib path based on bind ID.

Specified by:
getLineProcLibPath in interface LineProcContextCallback
Parameters:
lineProcBindID - The bind ID to look up.
Returns:
The lip path to the selected line proc.
See Also:
LineProcContextCallback.getLineProcLibPath(java.lang.String)

loadNewLineProcOnPeer

public boolean loadNewLineProcOnPeer(String dialogID,
                                     String lineProcBindID)
Tells a peer to load a new line proc.

Specified by:
loadNewLineProcOnPeer in interface LineProcContextCallback
Parameters:
dialogID - The peer to manipulate.
lineProcBindID - The line proc to load.
Returns:
TRUE if success, FALSE if otherwise.
See Also:
LineProcContextCallback.loadNewLineProcOnPeer(java.lang.String, java.lang.String)