com.dalsemi.slush
Class CommandInterpreter

java.lang.Object
  |
  +--com.dalsemi.slush.CommandInterpreter

public class CommandInterpreter
extends java.lang.Object

The CommandInterpreter class is responsible for dispatching any commands received by the slush shell to their appropriate handlers.


Field Summary
static java.lang.String FALSE
           
static java.lang.String FILE_IN_REDIRECTED
           
static java.lang.String FILE_OUT_REDIRECTED
           
static java.lang.String RUNNING_IN_BACKGROUND
           
static java.lang.String TRUE
           
 
Constructor Summary
CommandInterpreter()
           
 
Method Summary
static boolean addCommand(java.lang.String name, SlushCommand executer)
          Adds a command to the list of those recognized by the slush shell.
static void execute(java.lang.Object[] commandLine, com.dalsemi.slush.SlushInputStream in, com.dalsemi.slush.SlushPrintStream out, com.dalsemi.slush.SlushPrintStream err, java.util.Hashtable env)
          Executes a slush command.
static java.util.Enumeration getAvailableCommands()
          Enumerates all of the commands that have been added to the list.
static java.util.Hashtable getEnvironment()
          Creates and returns a copy of the current environment.
static int getNumberOfCommands()
           
static SlushCommand getSlushCommand(java.lang.String str)
          Returns an instance of the specified command.
static java.util.Hashtable getSystemEnvironment()
          Returns the current environment.
static boolean removeCommand(java.lang.String name)
          Removes the named command from the list of those recognized by the slush shell.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRUE

public static java.lang.String TRUE

FALSE

public static java.lang.String FALSE

FILE_IN_REDIRECTED

public static java.lang.String FILE_IN_REDIRECTED

FILE_OUT_REDIRECTED

public static java.lang.String FILE_OUT_REDIRECTED

RUNNING_IN_BACKGROUND

public static java.lang.String RUNNING_IN_BACKGROUND
Constructor Detail

CommandInterpreter

public CommandInterpreter()
Method Detail

addCommand

public static final boolean addCommand(java.lang.String name,
                                       SlushCommand executer)
Adds a command to the list of those recognized by the slush shell. After a command has been added, it can be executed from any instance of the shell including those that were started before the command was added. If an attempt is made to add a command that already exists, the operation will fail unless the current user is an administrator or that user is the one who added the command.
Parameters:
name - The string that will be typed from the shell command line to execute the command.
executer - An instance of the command to be added.
Returns:
The success of the add operation.

removeCommand

public static final boolean removeCommand(java.lang.String name)
Removes the named command from the list of those recognized by the slush shell. Once a command has been removed, it can no longer be executed from any instance of the shell including those that were started before the command was removed. Only administrators and the user that added the command will be allowed to remove it. NOTE: Currently all users have administrative rights.
Parameters:
name - The name of the command to remove.
Returns:
The success of the operation.

execute

public static void execute(java.lang.Object[] commandLine,
                           com.dalsemi.slush.SlushInputStream in,
                           com.dalsemi.slush.SlushPrintStream out,
                           com.dalsemi.slush.SlushPrintStream err,
                           java.util.Hashtable env)
                    throws java.lang.Exception
Executes a slush command.
Parameters:
commandLine - An Object array containing the command in the first element, followed by any parameters need for that command in a String[] in the second element.
in - The stream the command will use to get input.
out - The stream used to report non-critical messages.
err - The stream used to report critical messages.
env - A table of environment variables.
Throws:
java.lang.Exception - Any exception raised by the command. The shell will report the result of Exception.getMessage() to the user.

getEnvironment

public static java.util.Hashtable getEnvironment()
Creates and returns a copy of the current environment.
Returns:
the environment.

getSystemEnvironment

public static java.util.Hashtable getSystemEnvironment()
Returns the current environment. (Not a copy!)
Returns:
the environment.

getSlushCommand

public static SlushCommand getSlushCommand(java.lang.String str)
Returns an instance of the specified command. Note: This will not create a new instance of the command--it simply searches the list of current command.
Parameters:
str - The name of the command to find.
Returns:
an instance of the command or null if the command has not been added to the list of available commands.
See Also:
addCommand(String, SlushCommand)

getAvailableCommands

public static java.util.Enumeration getAvailableCommands()
Enumerates all of the commands that have been added to the list.
Returns:
An enumeration of Strings representing the command names.
See Also:
addCommand(String, SlushCommand)

getNumberOfCommands

public static int getNumberOfCommands()