net.sf.freecol.server.ai
Class AIInGameInputHandler

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

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

Handles the network messages that arrives while in the game.


Field Summary
private  AIMain aiMain
           
private  FreeColServer freeColServer
          The server.
private static java.util.logging.Logger logger
           
private  ServerPlayer serverPlayer
          The player for whom I work.
 
Constructor Summary
AIInGameInputHandler(FreeColServer freeColServer, ServerPlayer me, AIMain aiMain)
          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 chooseFoundingFather(DummyConnection connection, org.w3c.dom.Element element)
          Handles a "chooseFoundingFather"-message.
private  org.w3c.dom.Element diplomaticTrade(DummyConnection connection, org.w3c.dom.Element element)
          Handles an "diplomaticTrade"-message.
private  org.w3c.dom.Element fountainOfYouth(DummyConnection connection, org.w3c.dom.Element element)
          Replies to fountain of youth offer.
private  AIPlayer getAIPlayer()
          Gets the AIPlayer using this AIInGameInputHandler.
private  AIUnit getAIUnit(Unit unit)
          Gets the AI unit corresponding to a given unit, if any.
 org.w3c.dom.Element handle(Connection connection, org.w3c.dom.Element element)
          Deals with incoming messages that have just been received.
 void handle(Connection connection, javax.xml.stream.XMLStreamReader in, javax.xml.stream.XMLStreamWriter out)
          Handles the main element of an XML message.
private  org.w3c.dom.Element indianDemand(DummyConnection connection, org.w3c.dom.Element element)
          Handles an "indianDemand"-message.
private  org.w3c.dom.Element lootCargo(Connection connection, org.w3c.dom.Element element)
          Replies to loot cargo offer.
private  org.w3c.dom.Element monarchAction(DummyConnection connection, org.w3c.dom.Element element)
          Handles a "monarchAction"-message.
 org.w3c.dom.Element multiple(Connection connection, org.w3c.dom.Element element)
          Handle all the children of this element.
private  org.w3c.dom.Element newLandName(DummyConnection connection, org.w3c.dom.Element element)
          Replies to offer to name the new land.
private  org.w3c.dom.Element newRegionName(DummyConnection connection, org.w3c.dom.Element element)
          Replies to offer to name a new region name.
private  org.w3c.dom.Element setCurrentPlayer(DummyConnection connection, org.w3c.dom.Element setCurrentPlayerElement)
          Handles a "setCurrentPlayer"-message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

serverPlayer

private final ServerPlayer serverPlayer
The player for whom I work.


freeColServer

private final FreeColServer freeColServer
The server.


aiMain

private final AIMain aiMain
Constructor Detail

AIInGameInputHandler

public AIInGameInputHandler(FreeColServer freeColServer,
                            ServerPlayer me,
                            AIMain aiMain)
The constructor to use.

Parameters:
freeColServer - The main server.
me - The AI player that is being managed by this AIInGameInputHandler.
aiMain - The main AI-object.
Method Detail

handle

public org.w3c.dom.Element handle(Connection connection,
                                  org.w3c.dom.Element element)
Deals with incoming messages that have just been received.

Specified by:
handle in interface MessageHandler
Parameters:
connection - The Connection the message was received on.
element - The root element of the message.
Returns:
The reply.

getAIPlayer

private AIPlayer getAIPlayer()
Gets the AIPlayer using this AIInGameInputHandler.

Returns:
The AIPlayer.

getAIUnit

private AIUnit getAIUnit(Unit unit)
Gets the AI unit corresponding to a given unit, if any.

Parameters:
unit - The Unit to look up.
Returns:
The corresponding AI unit or null if not found.

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 (currently always false).

setCurrentPlayer

private org.w3c.dom.Element setCurrentPlayer(DummyConnection connection,
                                             org.w3c.dom.Element setCurrentPlayerElement)
Handles a "setCurrentPlayer"-message.

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

chooseFoundingFather

private org.w3c.dom.Element chooseFoundingFather(DummyConnection connection,
                                                 org.w3c.dom.Element element)
Handles a "chooseFoundingFather"-message.

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

monarchAction

private org.w3c.dom.Element monarchAction(DummyConnection connection,
                                          org.w3c.dom.Element element)
Handles a "monarchAction"-message.

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

indianDemand

private org.w3c.dom.Element indianDemand(DummyConnection connection,
                                         org.w3c.dom.Element element)
Handles an "indianDemand"-message.

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

diplomaticTrade

private org.w3c.dom.Element diplomaticTrade(DummyConnection connection,
                                            org.w3c.dom.Element element)
Handles an "diplomaticTrade"-message.

Parameters:
connection - The connection the message was received on.
element - The element (root element in a DOM-parsed XML tree) that holds all the information.
Returns:
Either the original message with "accept" set, or null on rejection.

newLandName

private org.w3c.dom.Element newLandName(DummyConnection connection,
                                        org.w3c.dom.Element element)
Replies to offer to name the new land.

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

newRegionName

private org.w3c.dom.Element newRegionName(DummyConnection connection,
                                          org.w3c.dom.Element element)
Replies to offer to name a new region name.

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

fountainOfYouth

private org.w3c.dom.Element fountainOfYouth(DummyConnection connection,
                                            org.w3c.dom.Element element)
Replies to fountain of youth offer.

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

lootCargo

private org.w3c.dom.Element lootCargo(Connection connection,
                                      org.w3c.dom.Element element)
Replies to loot cargo offer.

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

multiple

public org.w3c.dom.Element multiple(Connection connection,
                                    org.w3c.dom.Element element)
Handle all the children of this element.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.