net.sf.freecol.server.control
Class UserConnectionHandler

java.lang.Object
  extended by net.sf.freecol.server.control.UserConnectionHandler
All Implemented Interfaces:
MessageHandler, StreamedMessageHandler

public final class UserConnectionHandler
extends java.lang.Object
implements MessageHandler, StreamedMessageHandler

Handles a new client connection. PreGameInputHandler is set as the message handler when the client has successfully logged on.


Field Summary
private  FreeColServer freeColServer
           
private static java.util.logging.Logger logger
           
 
Constructor Summary
UserConnectionHandler(FreeColServer freeColServer)
          The constructor to use.
 
Method Summary
 boolean accepts(java.lang.String tagName)
          Checks if the message handler support the given message.
private  org.w3c.dom.Element disconnect(Connection connection, org.w3c.dom.Element disconnectElement)
          Handles a "disconnect"-message.
private  org.w3c.dom.Element getVacantPlayers(Connection connection, org.w3c.dom.Element element)
          Handles a "getVacantPlayers"-request.
 org.w3c.dom.Element handle(Connection connection, org.w3c.dom.Element element)
          Handles a network message.
 void handle(Connection connection, javax.xml.stream.XMLStreamReader in, javax.xml.stream.XMLStreamWriter out)
          Handles the main element of an XML message.
private  void login(Connection connection, javax.xml.stream.XMLStreamReader in, javax.xml.stream.XMLStreamWriter out)
          Handles a "login"-request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static java.util.logging.Logger logger

freeColServer

private final FreeColServer freeColServer
Constructor Detail

UserConnectionHandler

public UserConnectionHandler(FreeColServer freeColServer)
The constructor to use.

Parameters:
freeColServer - The main control object.
Method Detail

handle

public org.w3c.dom.Element handle(Connection connection,
                                  org.w3c.dom.Element element)
Handles a network message.

Specified by:
handle in interface MessageHandler
Parameters:
connection - The Connection the message came from.
element - The message to be processed.
Returns:
The reply.

handle

public void handle(Connection connection,
                   javax.xml.stream.XMLStreamReader in,
                   javax.xml.stream.XMLStreamWriter out)
Handles the main element of an XML message.

Specified by:
handle in interface StreamedMessageHandler
Parameters:
connection - The connection the message came from.
in - The stream containing the message.
out - The output stream for the reply.

accepts

public boolean accepts(java.lang.String tagName)
Checks if the message handler support the given message.

Specified by:
accepts in interface StreamedMessageHandler
Parameters:
tagName - The tag name of the message to check.
Returns:
The result.

getVacantPlayers

private org.w3c.dom.Element getVacantPlayers(Connection connection,
                                             org.w3c.dom.Element element)
Handles a "getVacantPlayers"-request.

Parameters:
connection - The connection the message came from.
element - The element containing the request.
Returns:
The reply: An XML element containing a list of the vacant players.

login

private void login(Connection connection,
                   javax.xml.stream.XMLStreamReader in,
                   javax.xml.stream.XMLStreamWriter out)
Handles a "login"-request.

Parameters:
connection - The connection the message is comming from.
in - The stream with the incoming data.
out - The target stream for the reply.

disconnect

private org.w3c.dom.Element disconnect(Connection connection,
                                       org.w3c.dom.Element disconnectElement)
Handles a "disconnect"-message.

Parameters:
connection - The Connection the message was received on.
disconnectElement - The element (root element in a DOM-parsed XML tree) that holds all the information.
Returns:
The reply.