f00f.net.irc.martyr.commands
Class AbstractInCommand

java.lang.Object
  extended by f00f.net.irc.martyr.commands.AbstractInCommand
All Implemented Interfaces:
Command, InCommand
Direct Known Subclasses:
AbstractCommand, GenericError, GenericReply, UnknownCommand, WelcomeCommand

public abstract class AbstractInCommand
extends java.lang.Object
implements InCommand

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


Field Summary
protected  java.util.Map<java.lang.String,java.lang.String> attributes
           
 
Constructor Summary
protected AbstractInCommand()
           
protected AbstractInCommand(java.lang.String[] attributeNames)
           
 
Method Summary
 java.lang.String getAttribute(java.lang.String key)
          Returns the attribute, or null if the attribute does not exist, or is not defined.
 java.util.Iterator getAttributeKeys()
          Returns an iterator of String objects over the attribute names for this command.
 int getIntParameter(java.lang.String params, int paramnum, int defaultNum)
           
 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  InCommand 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.
 void selfRegister(CommandRegister commandRegister)
          Every command should know how to register itself (or not) with the command parsing engine.
protected  void setAttribute(java.lang.String key, java.lang.String value)
           
 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
 
Methods inherited from interface f00f.net.irc.martyr.Command
getIrcIdentifier
 

Field Detail

attributes

protected java.util.Map<java.lang.String,java.lang.String> attributes
Constructor Detail

AbstractInCommand

protected AbstractInCommand()

AbstractInCommand

protected AbstractInCommand(java.lang.String[] attributeNames)
Method Detail

getAttribute

public java.lang.String getAttribute(java.lang.String key)
Description copied from interface: InCommand
Returns the attribute, or null if the attribute does not exist, or is not defined.

Specified by:
getAttribute in interface InCommand
Parameters:
key - Attribute to get value of
Returns:
Attribute value or null if attribute doesn't exist

getAttributeKeys

public java.util.Iterator getAttributeKeys()
Description copied from interface: InCommand
Returns an iterator of String objects over the attribute names for this command. Warning: Still new, support for this is not yet widespread. Should return all possible attribute keys, not just those that have a value in the current context.

Specified by:
getAttributeKeys in interface InCommand
Returns:
Iterator of attribute keys

setAttribute

protected void setAttribute(java.lang.String key,
                            java.lang.String value)

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 InCommand
Returns:
State associated with 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 InCommand
Parameters:
commandRegister - Command register we want to register with

parse

public abstract InCommand 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 InCommand
Parameters:
prefix - Prefix of the command
identifier - ID of the command
params - Parameters of the command
Returns:
InCommand instance for parsed command

updateClientState

public boolean updateClientState(ClientState state)
By default, commands do not update the client state.

Specified by:
updateClientState in interface InCommand
Parameters:
state - Client state to be updated
Returns:
True or false if changes were made

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.

Parameters:
params - String with parameters in it
num - Position number of parameter to be requested
Returns:
Parameter specified by id in params string

getIntParameter

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

setSourceString

public void setSourceString(java.lang.String source)
Description copied from interface: InCommand
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 InCommand
Parameters:
source - Sets the source string to be parsed

getSourceString

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

Specified by:
getSourceString in interface InCommand
Returns:
The original source string from the server


Copyright © 2000-2007 Ben Damm, Daniel Henninger, et al.