org.adougou.cline
Class BaseCommand
java.lang.Object
|
+--org.adougou.cline.BaseCommand
- All Implemented Interfaces:
- Command
- Direct Known Subclasses:
- ExitCommand, HelpCommand, ListCommand, PrintWorkingDirectoryCommand, TimeCommand, URLCommand, WindowCommand
- public abstract class BaseCommand
- extends java.lang.Object
- implements Command
Base class for creating named commands. The BaseCommand constructor should
be called from the constructor of a derived class that is the actual
command. For example:
class ExitCommand extends BaseCommand {
ExitCommand() {
super("exit", 0, "calls the System to exit");
}
}
For a complete example of creating a command, see the RunScriptCommand.
- See Also:
RunScriptCommand
|
Constructor Summary |
protected |
BaseCommand(java.lang.String name,
int numArgs,
java.lang.String help)
All inheriting classes are required to call this constructor using
|
|
Method Summary |
protected void |
checkPermission(java.security.Permission permission)
Dervied classes that require a special permission (for example, to
call the VM to exit as in the ExitCommand) should call this method to
check the java.security.Permission. |
void |
execute(java.util.Iterator iter)
This method is called internally whenever a command is executed to
check the arguments. |
void |
execute(java.lang.String args)
This method enables a command to be used independently of the
command prompt. |
abstract void |
execute(java.lang.String[] args)
This method should be overloaded by each command that is defined -
it will be called by the CommandRegister after the number of
arguments have been checked. |
java.lang.String |
getHelp()
Return a the help string for this command. |
java.lang.String |
getName()
|
protected BasePrompt |
getPrompt()
|
void |
set(CommandRegister cregister)
This method is called by the CommandRegister whenever a new command
is registered - this gives commands access to help information for
other commands - eg. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
name_
protected java.lang.String name_
numArgs_
protected int numArgs_
register_
protected CommandRegister register_
help_
protected java.lang.String help_
prompt
protected static BasePrompt prompt
BaseCommand
protected BaseCommand(java.lang.String name,
int numArgs,
java.lang.String help)
- All inheriting classes are required to call this constructor using
super(name, numArgs, help)
.
- Parameters:
name - the name of the command - an exception will be thrown if
a command already exists with this namenumArgs - the number of arguments this command takes.
-1 can be specified if the command takes a variable number of
arguments, in which case it is up to the derived command to carefully
check the arguments.help - this string is returned to the user when they request
help about a command. It should include a brief description of what
the command accomplishes and what each of the required arguments is.
set
public void set(CommandRegister cregister)
- This method is called by the CommandRegister whenever a new command
is registered - this gives commands access to help information for
other commands - eg. see the HelpCommand.
- Specified by:
set in interface Command
checkPermission
protected void checkPermission(java.security.Permission permission)
- Dervied classes that require a special permission (for example, to
call the VM to exit as in the ExitCommand) should call this method to
check the java.security.Permission. If permission is not granted,
this permission will be added to a list of failed permissions for this
command, the command will be disabled, and a message describing the
permission failure will be displayed to the user if they attempt to
execute the command.
getPrompt
protected BasePrompt getPrompt()
getName
public java.lang.String getName()
- Specified by:
getName in interface Command
execute
public void execute(java.lang.String args)
- This method enables a command to be used independently of the
command prompt. You instantiate a command, and then execute it
by passing a string containing the arguments. If the arguments are
not properly formatted, an error will be printed.
execute
public abstract void execute(java.lang.String[] args)
- This method should be overloaded by each command that is defined -
it will be called by the CommandRegister after the number of
arguments have been checked.
- Specified by:
execute in interface Command
execute
public void execute(java.util.Iterator iter)
- This method is called internally whenever a command is executed to
check the arguments. After checking arguments, it will call the
execute(String[]) method for the specific command.
- Specified by:
execute in interface Command
getHelp
public java.lang.String getHelp()
- Return a the help string for this command. This is basically the help
string required in the constructor for all BaseCommands.
- Specified by:
getHelp in interface Command