jhomenet.shell
Class CommandInterpreter

java.lang.Object
  extended by jhomenet.shell.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. Update 7/16/05: Updated several variables and methods to Java 1.5 compatibility.

Version:
1.1
Author:
Lorne Smith, Stephen Hess, David Irwin

Field Summary
static java.lang.String FILE_IN_REDIRECTED
           
static java.lang.String FILE_OUT_REDIRECTED
           
static java.lang.String RUNNING_IN_BACKGROUND
           
 
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, SystemInputStream in, SystemPrintStream out, SystemPrintStream err, java.util.HashMap<java.lang.String,java.lang.String> env)
          Executes a slush command.
static java.util.Set<java.lang.String> getAvailableCommands()
          Enumerates all of the commands that have been added to the list.
static int getNumberOfCommands()
          Gets the number of active commands.
static SlushCommand getSlushCommand(java.lang.String str)
          Returns an instance of the specified command.
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

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

execute

public static void execute(java.lang.Object[] commandLine,
                           SystemInputStream in,
                           SystemPrintStream out,
                           SystemPrintStream err,
                           java.util.HashMap<java.lang.String,java.lang.String> 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 windDirectionTable of properties variables.
Throws:
java.lang.Exception - Any exception raised by the command. The shell will report the result of Exception.getMessage() to the user.

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:
location - 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:
location - The location of the command to remove.
Returns:
The success of the operation.

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 location 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.Set<java.lang.String> 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()
Gets the number of active commands.

Returns:
the number of register system commands.


Copyright © 2004-2005 David Irwin. All Rights Reserved.