Class TrivialMessage

    • Constructor Detail

      • TrivialMessage

        protected TrivialMessage​(java.lang.String type)
        Create a new TrivialMessage of a given type.
        Parameters:
        type - The message type.
      • TrivialMessage

        protected TrivialMessage​(java.lang.String tag,
                                 Game game,
                                 FreeColXMLReader xr)
                          throws javax.xml.stream.XMLStreamException
        Create a new TrivialMessage from a stream. Note: only call this from direct subclasses of TrivialMessage as it consumes the whole message.
        Parameters:
        tag - The message tag.
        game - The Game this message belongs to.
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if the stream is corrupt.
    • Method Detail

      • getType

        public java.lang.String getType()
        Get the message tag.
        Specified by:
        getType in class Message
        Returns:
        The message tag.
      • setType

        protected void setType​(java.lang.String type)
        Set the message tag.
        Specified by:
        setType in class Message
        Parameters:
        type - The new message tag.
      • hasAttribute

        protected boolean hasAttribute​(java.lang.String key)
        Checks if an attribute is present in this message.
        Specified by:
        hasAttribute in class Message
        Parameters:
        key - The attribute to look for.
        Returns:
        True if the attribute is present.
      • getStringAttribute

        protected java.lang.String getStringAttribute​(java.lang.String key)
        Get a string attribute value.
        Specified by:
        getStringAttribute in class Message
        Parameters:
        key - The attribute to look for.
        Returns:
        The string value found, or null if the attribute was absent.
      • setStringAttribute

        protected void setStringAttribute​(java.lang.String key,
                                          java.lang.String value)
        Sets an attribute in this message.
        Specified by:
        setStringAttribute in class Message
        Parameters:
        key - The attribute to set.
        value - The new value of the attribute.
      • getStringAttributeMap

        protected java.util.Map<java.lang.String,​java.lang.String> getStringAttributeMap()
        Get a map of all the attributes in this message.
        Specified by:
        getStringAttributeMap in class Message
        Returns:
        A Map of the attributes.
      • getChildCount

        protected int getChildCount()
        Get the number of child objects.
        Specified by:
        getChildCount in class Message
        Returns:
        The child count.
      • getChildren

        protected java.util.List<FreeColObject> getChildren()
        Get the child objects of this message.
        Specified by:
        getChildren in class Message
        Returns:
        A list of child FreeColObjects.
      • setChildren

        protected void setChildren​(java.util.List<? extends FreeColObject> fcos)
        Set the list of objects attached to this message.
        Specified by:
        setChildren in class Message
        Parameters:
        fcos - The new list of attached FreeColObjects.
      • appendChild

        protected <T extends FreeColObject> void appendChild​(T fco)
        Append a new child.
        Specified by:
        appendChild in class Message
        Type Parameters:
        T - The child type.
        Parameters:
        fco - The new child object.
      • appendChildren

        protected <T extends FreeColObject> void appendChildren​(java.util.Collection<T> fcos)
        Append a multiple new children.
        Specified by:
        appendChildren in class Message
        Type Parameters:
        T - The child type.
        Parameters:
        fcos - The new child objects.
      • currentPlayerMessage

        public boolean currentPlayerMessage()
        Should this message only be sent to a server by the current player?
        Specified by:
        currentPlayerMessage in class Message
        Returns:
        True if this is a current-player-only message.
      • aiHandler

        public void aiHandler​(FreeColServer freeColServer,
                              AIPlayer aiPlayer)
                       throws FreeColException
        AI-side handler for this message. AI handlers always return null. FIXME: One day the FreeColServer should devolve to AIMain.
        Specified by:
        aiHandler in class Message
        Parameters:
        freeColServer - The FreeColServer handling the request.
        aiPlayer - The AIPlayer the message was sent to.
        Throws:
        FreeColException - if there is a problem handling the message.
      • clientHandler

        public void clientHandler​(FreeColClient freeColClient)
                           throws FreeColException
        Client-side handler for this message. Client handlers always return null.
        Specified by:
        clientHandler in class Message
        Parameters:
        freeColClient - The FreeColClient to handle this message.
        Throws:
        FreeColException - if there is a problem building the message.
      • serverHandler

        public ChangeSet serverHandler​(FreeColServer freeColServer,
                                       ServerPlayer serverPlayer)
        Server-side handler for this message.
        Specified by:
        serverHandler in class Message
        Parameters:
        freeColServer - The FreeColServer handling the request.
        serverPlayer - The ServerPlayer that sent the request.
        Returns:
        A ChangeSet defining the response.