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.


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 java.io.File deriveFileName(java.lang.String file, java.util.Hashtable environment)
          Creates an instance of a File object from a file name and the current directory that is stored in the environment hash table.
static void execute(java.lang.String[] 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 SlushCommand getSlushCommand(java.lang.String str)
          Returns an instance of the specified command.
static byte getUserID(java.lang.String userName, java.lang.String password)
          Returns the user ID associated with a name and password pair.
static boolean isAdmin(byte b)
          Determines if the given user ID has administrative rights.
static boolean removeCommand(java.lang.String name)
          Removes the named command from the list of those recognized by the SLUSH shell.
static java.lang.String resolveFileName(java.lang.String file)
          Resolves a absolute path name into its canonical representation.
 
Methods inherited from class java.lang.Object
equals, hashCode, toString
 

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.String[] 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 - A String array containing the command followed by any parameters need for that command.
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.

getUserID

public static final byte getUserID(java.lang.String userName,
                                   java.lang.String password)
Returns the user ID associated with a name and password pair.
Parameters:
userName - The user name.
password - The password for that user.
Returns:
An eight-bit user ID.

deriveFileName

public static java.io.File deriveFileName(java.lang.String file,
                                          java.util.Hashtable environment)
                                   throws java.io.FileNotFoundException
Creates an instance of a File object from a file name and the current directory that is stored in the environment hash table.
Parameters:
file - The name of the file to create. This String can contain a relative or absolute path (including any references to "..", "...", etc.).
environment - A table of environment variables that must include a "current directory" key.
Returns:
The file requested.
Throws:
java.io.FileNotFoundException - If any problems occur while resolving the file (Such as trying to get the parent of the root directory).

resolveFileName

public static java.lang.String resolveFileName(java.lang.String file)
                                        throws java.io.FileNotFoundException
Resolves a absolute path name into its canonical representation. This includes resolving references to "..", "...", etc.
Parameters:
file - The absolute path to resolve.
Returns:
The canonical representation of the file's name.
Throws:
java.io.FileNotFoundException - If the file name cannot be completely resolved.

getEnvironment

public static java.util.Hashtable getEnvironment()
Creates and returns a copy of the current environment.
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)

isAdmin

public static boolean isAdmin(byte b)
Determines if the given user ID has administrative rights.
Parameters:
b - the user ID.
Returns:
true if the user is an administrator, false otherwise.