f00f.net.irc.martyr.commands
Class GenericCommand

java.lang.Object
  |
  +--f00f.net.irc.martyr.commands.GenericCommand
All Implemented Interfaces:
Command
Direct Known Subclasses:
GenericError, JoinCommand, KickCommand, MessageCommand, NickCommand, NoticeCommand, PartCommand, PingCommand, QuitCommand, TopicCommand, UnknownCommand, UserCommand, WelcomeCommand

public abstract class GenericCommand
extends java.lang.Object
implements Command

Defines a generic command. Most commands will simply have to override the getIrcIdentifier method and implement the parse and render methods using convenience methods.


Constructor Summary
GenericCommand()
           
 
Method Summary
 int getIntParameter(java.lang.String params, int paramnum, int defaultNum)
           
abstract  java.lang.String getIrcIdentifier()
          Returns the string IRC uses to identify this command.
 java.lang.String getParameter(java.lang.String params, int num)
          Utility method to make parsing easy.
 java.lang.String getSourceString()
          Allows a third party to receive a copy of the raw string.
 State getState()
          Some commands, when received by the server, can only occur in one state.
abstract  Command parse(java.lang.String prefix, java.lang.String identifier, java.lang.String params)
          Parses a string and produces a formed command object, if it can.
 java.lang.String render()
          Forms a string appropriate to send to the server.
abstract  java.lang.String renderParams()
          Renders the parameters of this command.
 void selfRegister(CommandRegister commandRegister)
          Every command should know how to register itself (or not) with the command parsing engine.
 void setSourceString(java.lang.String source)
          Gives the command a copy of the raw string from the server.
 boolean updateClientState(ClientState state)
          By default, commands do not update the client state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericCommand

public GenericCommand()
Method Detail

getState

public State getState()
Some commands, when received by the server, can only occur in one state. Thus, when this command is received, the protocol should assume that it is that state. A command can use the 'unknown' state to indicate it can be received in any state (for example, ping). Most commands will occur in the REGISTERED state, so for a few exeptions, commands can leave this alone.
Specified by:
getState in interface Command

selfRegister

public void selfRegister(CommandRegister commandRegister)
Every command should know how to register itself (or not) with the command parsing engine. If a command is available under mutiple identifiers, then this method can be overridden and the addCommand method can be called multiple times.
Specified by:
selfRegister in interface Command

render

public java.lang.String render()
Forms a string appropriate to send to the server. All commands can be sent by the client.
Specified by:
render in interface Command

parse

public abstract Command parse(java.lang.String prefix,
                              java.lang.String identifier,
                              java.lang.String params)
Parses a string and produces a formed command object, if it can. Should return null if it cannot form the command object.
Specified by:
parse in interface Command

getIrcIdentifier

public abstract java.lang.String getIrcIdentifier()
Returns the string IRC uses to identify this command. Examples: NICK, PING, KILL, 332

renderParams

public abstract java.lang.String renderParams()
Renders the parameters of this command.

updateClientState

public boolean updateClientState(ClientState state)
By default, commands do not update the client state.
Specified by:
updateClientState in interface Command

getParameter

public java.lang.String getParameter(java.lang.String params,
                                     int num)
Utility method to make parsing easy. Provides parameter n, where n=0 is the first parameter. Parses out the : and considers anything after a : to be one string, the final parameter. If the index doesn't exist, returns null. Should it throw IndexOutOfBoundsException? No, some commands may have optional fields.

getIntParameter

public int getIntParameter(java.lang.String params,
                           int paramnum,
                           int defaultNum)

setSourceString

public void setSourceString(java.lang.String source)
Description copied from interface: Command
Gives the command a copy of the raw string from the server. Called by IRCConnection after the command is parsed.
Specified by:
setSourceString in interface Command

getSourceString

public java.lang.String getSourceString()
Description copied from interface: Command
Allows a third party to receive a copy of the raw string.
Specified by:
getSourceString in interface Command


Copyright ? 2000,2001, f00f networks. All Rights Reserved.