ikrs.util
Class AbstractCommandFactory<C extends Command>

java.lang.Object
  extended by ikrs.util.AbstractCommandFactory<C>
All Implemented Interfaces:
CommandFactory<C>
Direct Known Subclasses:
DefaultCommandFactory

public abstract class AbstractCommandFactory<C extends Command>
extends java.lang.Object
implements CommandFactory<C>


Constructor Summary
AbstractCommandFactory()
          Create a new command factory.
 
Method Summary
 CommandFactory<C> getParentFactory()
          Get the parent factory for this factory.
abstract  java.util.Set<C> getSupportedCommands()
          Get a set of all supported commands.
abstract  C make(java.lang.String name, BasicType[] params)
          Make a new Command with the given name and params.
 C make(java.lang.String name, java.lang.String[] params)
          Make a new Command with the given name and params.
 C make(java.lang.String name, java.lang.String[] params, int start, int end)
          This is a slight modifiaction of the make( String, String[] ) method; but it accepts some bounds for the array.
 C parse(java.lang.String str)
          Make a new Command by parsing it from a string.
 void setParentFactory(CommandFactory<C> newParent)
          Set the parent factory for this factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCommandFactory

public AbstractCommandFactory()
Create a new command factory.

Method Detail

getSupportedCommands

public abstract java.util.Set<C> getSupportedCommands()
Get a set of all supported commands. This is usually a set of the commands that are understood by this factory plus all commands that are understood by all parent factories (if exist).

Specified by:
getSupportedCommands in interface CommandFactory<C extends Command>
Returns:
A set containting all commands that are supported by this factory.

getParentFactory

public CommandFactory<C> getParentFactory()
Get the parent factory for this factory. If there is no parent factory present the method returns null.

Specified by:
getParentFactory in interface CommandFactory<C extends Command>
Returns:
The parent factory or null if no such exists.

setParentFactory

public void setParentFactory(CommandFactory<C> newParent)
Set the parent factory for this factory. Pass null to clear the parent factory.

Specified by:
setParentFactory in interface CommandFactory<C extends Command>
Parameters:
The - new parent factory or null to clear.

make

public C make(java.lang.String name,
              java.lang.String[] params)
                       throws UnknownCommandException,
                              CommandStringIncompleteException
Make a new Command with the given name and params.

Specified by:
make in interface CommandFactory<C extends Command>
Parameters:
name - The command's name.
params - The command's params - in string representation.
Returns:
The new command.
Throws:
UnknownCommandException
CommandStringIncompleteException

make

public abstract C make(java.lang.String name,
                       BasicType[] params)
                                throws UnknownCommandException,
                                       CommandStringIncompleteException
Make a new Command with the given name and params.

Specified by:
make in interface CommandFactory<C extends Command>
Parameters:
name - The command's name.
params - The command's params - in BasicType representation.
Returns:
The new command.
Throws:
UnknownCommandException
CommandStringIncompleteException

parse

public C parse(java.lang.String str)
                        throws java.lang.UnsupportedOperationException,
                               UnknownCommandException,
                               CommandStringIncompleteException,
                               java.text.ParseException
Make a new Command by parsing it from a string. Some command classes might not support this method as the parsing process would be too complex. In this case an UnsupportedOperationException is thrown.

Specified by:
parse in interface CommandFactory<C extends Command>
Parameters:
str - The string to parse the command from.
Returns:
The new command.
Throws:
java.lang.UnsupportedOperationException - if the underlying command implementation does not support parsing.
CommandStringIncompleteException - If the given String lacks some data at the end.
java.text.ParseException - If the given String is malformed.
UnknownCommandException

make

public C make(java.lang.String name,
              java.lang.String[] params,
              int start,
              int end)
                       throws UnknownCommandException,
                              CommandStringIncompleteException
This is a slight modifiaction of the make( String, String[] ) method; but it accepts some bounds for the array.

Throws:
UnknownCommandException
CommandStringIncompleteException