f00f.net.irc.martyr.commands
Class GenericInCommand
java.lang.Object
|
+--f00f.net.irc.martyr.commands.GenericInCommand
- All Implemented Interfaces:
- Command, InCommand
- Direct Known Subclasses:
- GenericCommand, GenericError, GenericReply, UnknownCommand, WelcomeCommand
- public abstract class GenericInCommand
- 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.
|
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 |
attributes
protected java.util.Map attributes
GenericInCommand
protected GenericInCommand()
GenericInCommand
protected GenericInCommand(java.lang.String[] attributeNames)
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
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
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
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
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
updateClientState
public boolean updateClientState(ClientState state)
- By default, commands do not update the client state.
- Specified by:
updateClientState in interface InCommand
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:
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
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
Copyright © 2000,2001,2002,2003 f00f networks.