src.translators
Class ServerConnection

java.lang.Object
  extended bysrc.translators.ServerConnection
All Implemented Interfaces:
org.apache.xmlrpc.XmlRpcHandler
Direct Known Subclasses:
ICQServerConnection, IRCServerConnection, JServerConnection, MailServerConnection

public abstract class ServerConnection
extends java.lang.Object
implements org.apache.xmlrpc.XmlRpcHandler

Handles the translator's connection to the server. Anything exchanged with the server goes through here.

Version:
2005-apr-28

Constructor Summary
ServerConnection(java.lang.String translatorConfigId)
          Constructor for ServerConnection.
 
Method Summary
 java.lang.Object execute(java.lang.String method, java.util.Vector params)
          Handles incoming XMLRPC requests.
 void freeMessageId(java.lang.String messageId)
          Frees a message Id from the active message id list so that the id may be reused for another message.
abstract  void handleAlert(java.lang.String messageId, java.lang.String userDetails, java.lang.String message)
          Handles all incoming alert from the server.
abstract  void handleResponse(java.lang.String messageId, java.lang.String userDetails, java.lang.String message)
          Handles all incoming messages that are answeres to queries earlier sent by users.
 java.lang.String sendQuery(java.lang.String userDetails, java.lang.String query)
          Sends a query (which originate from users) to the server.
 void start()
          Starts up the server connection.
 void stop()
          Shuts down the server connection.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerConnection

public ServerConnection(java.lang.String translatorConfigId)
Constructor for ServerConnection.

Method Detail

start

public void start()
Starts up the server connection. Sets up the incoming and outgoing communication with the server and registers the translator.


stop

public void stop()
Shuts down the server connection.


execute

public java.lang.Object execute(java.lang.String method,
                                java.util.Vector params)
Handles incoming XMLRPC requests. Finds the corresponding method and runs it with the parameters supplied.

Specified by:
execute in interface org.apache.xmlrpc.XmlRpcHandler
Parameters:
method - The XMLRPC method that was requested.
params - The parameters of the XMLRPC method.
Returns:
A String with a possible error message, if the String is empty then everything went well.

handleResponse

public abstract void handleResponse(java.lang.String messageId,
                                    java.lang.String userDetails,
                                    java.lang.String message)
Handles all incoming messages that are answeres to queries earlier sent by users. The messages are sent on to the intended user.

Parameters:
userDetails - The user specific details (how to reach the user).
message - The message that should be sent to the user.

handleAlert

public abstract void handleAlert(java.lang.String messageId,
                                 java.lang.String userDetails,
                                 java.lang.String message)
Handles all incoming alert from the server. An alert is not a response to a user's query, it's a message invoked by the server.

Parameters:
userDetails - The user specific details (how to reach the user).
message - The message that should be sent to the user.

sendQuery

public java.lang.String sendQuery(java.lang.String userDetails,
                                  java.lang.String query)
                           throws java.io.IOException,
                                  java.lang.IllegalStateException
Sends a query (which originate from users) to the server.

Parameters:
userDetails - The user specific details (how to reach the user).
query - The query that should be sent.
Returns:
The message identifier for the query which is then used to identify the response.
Throws:
IOExcpetion - If a communication error occurs.
java.lang.IllegalStateException - If the translator is not registered yet.
java.io.IOException

freeMessageId

public void freeMessageId(java.lang.String messageId)
Frees a message Id from the active message id list so that the id may be reused for another message. This should be called as soon as the repsonse has been fully processed.

Parameters:
messageId - The message Id to free.