f00f.net.irc.martyr.commands
Class ModeCommand

java.lang.Object
  extended by f00f.net.irc.martyr.commands.ModeCommand
All Implemented Interfaces:
Command, InCommand, OutCommand
Direct Known Subclasses:
ChannelModeCommand, UserModeCommand

public class ModeCommand
extends java.lang.Object
implements InCommand, OutCommand

Defines MODE command. Since the MODE command is of two distinct types, this class is really more of a command mini-factory. It determines which type of command it is, either a UserModeCommand or a ChannelModeCommand.


Field Summary
static java.lang.String IDENTIFIER
           
 
Constructor Summary
ModeCommand()
          For use as a factory
 
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.
 java.lang.String getIrcIdentifier()
          Returns the string IRC uses to identify this command.
 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.
 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.
 java.util.List<Mode> parseModes(java.util.Map<java.lang.Character,Mode> modes, java.util.StringTokenizer tokens)
          Takes a mode string, such as: '+ooo A B C' or '+o A +o B' or even '+o-o A B' and returns a List containing Mode objects that correspond to the modes specified.
static void registerMode(java.util.Map<java.lang.Character,Mode> modes, Mode mode)
           
 java.lang.String render()
          Should not be called, as ModeCommand doesn't actually represent a command.
 void selfRegister(CommandRegister reg)
          Every incoming command should know how to register itself with the command register.
 void setSourceString(java.lang.String source)
          Gives the command a copy of the raw string from the server.
 java.lang.String toString()
           
 boolean updateClientState(ClientState cs)
          Does nothing, as this is a factory command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IDENTIFIER

public static final java.lang.String IDENTIFIER
See Also:
Constant Field Values
Constructor Detail

ModeCommand

public ModeCommand()
For use as a factory

Method Detail

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

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

registerMode

public static void registerMode(java.util.Map<java.lang.Character,Mode> modes,
                                Mode mode)

getState

public State getState()
Description copied from interface: InCommand
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 in that state, and a state change may be triggered. A command can use the 'unknown' state to indicate it can be received in any state (for example, ping).

Specified by:
getState in interface InCommand
Returns:
State associated with command

selfRegister

public void selfRegister(CommandRegister reg)
Description copied from interface: InCommand
Every incoming command should know how to register itself with the command register.

Specified by:
selfRegister in interface InCommand
Parameters:
reg - Command register we want to register with

getIrcIdentifier

public java.lang.String getIrcIdentifier()
Description copied from interface: Command
Returns the string IRC uses to identify this command. Examples: NICK, PING, KILL, 332. Not strictly required for OutCommands as the irc identifier is expected to be part of the reder() result.

Specified by:
getIrcIdentifier in interface Command
Returns:
The IRC identifier string

parse

public InCommand parse(java.lang.String prefix,
                       java.lang.String identifier,
                       java.lang.String params)
Description copied from interface: InCommand
Parses a string and produces a formed command object, if it can. Should return null if it cannot form the command object. The identifier is usually ignored, except in the special case where commands can be identified by multiple identifiers. In that case, the behaviour of the command may change in sublte ways.

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

render

public java.lang.String render()
Should not be called, as ModeCommand doesn't actually represent a command. Use UserModeCommand or ChannelModeCommand instead.

Specified by:
render in interface OutCommand
Returns:
Rendered string

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

updateClientState

public boolean updateClientState(ClientState cs)
Does nothing, as this is a factory command.

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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

parseModes

public java.util.List<Mode> parseModes(java.util.Map<java.lang.Character,Mode> modes,
                                       java.util.StringTokenizer tokens)
Takes a mode string, such as: '+ooo A B C' or '+o A +o B' or even '+o-o A B' and returns a List containing Mode objects that correspond to the modes specified.

Parameters:
modes - is a Map of Character to Mode objects.
tokens - is the sequence of tokens making up the parameters of the command.
Returns:
List of modes


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