comshell
Class CommandInterface

java.lang.Object
  |
  +--comshell.CommandInterface

public class CommandInterface
extends java.lang.Object

Handles universal commands and basic maintenance for the command shell

Author:
Scott Sanner

Field Summary
 java.util.HashMap bindings
           
 Command command
           
 java.io.InputStream is
          Local data members
 java.util.LinkedList is_stack
           
static int MAX_INPUT
          Static constant members
 java.io.PrintStream os
           
 
Constructor Summary
CommandInterface(java.io.InputStream is, java.io.PrintStream os)
          Constructor
 
Method Summary
 void exec_return()
          Handles the 'return' command (to return execution to the calling script (if any).
 void exec(java.lang.String filename)
          Handles the 'exec' command
 java.lang.String getBindings(java.lang.String varname)
          Gets an environmental variable binding (local to this shell only)
 void getCommand()
          Parses a command from the current input stream and determines if it is locally executable.
 void initEnvVarsFromFile(java.lang.String filename)
          Initializes the environmental variable bindings from a file
 boolean isStreamStackEmpty()
          Are we at the top level of the execution stack? (When exec is called, the newly exec'ed input stream is pushed onto the execution stack.
 void listEnv()
          Handles the 'listenv' command
 java.io.InputStream popStream()
          Pops the current command stream from the execution stack
 void printHelp()
          Handles the 'help' command - prints the command menu
 void pushStream(java.io.InputStream is)
          Pushes a new command stream onto the execution stack
 void setBindings(java.lang.String varname, java.lang.String value)
          Registers a new environmental variable binding (local to this shell only)
 void setEnv()
          Handles the 'setenv' command
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_INPUT

public static final int MAX_INPUT
Static constant members

is

public java.io.InputStream is
Local data members

os

public java.io.PrintStream os

bindings

public java.util.HashMap bindings

command

public Command command

is_stack

public java.util.LinkedList is_stack
Constructor Detail

CommandInterface

public CommandInterface(java.io.InputStream is,
                        java.io.PrintStream os)
Constructor
Parameters:
is - InputStream for shell input
os - OutputStream for shell output
Method Detail

isStreamStackEmpty

public boolean isStreamStackEmpty()
Are we at the top level of the execution stack? (When exec is called, the newly exec'ed input stream is pushed onto the execution stack. This allows one script to call another and retain its current position.)
Returns:
True if top level stream

pushStream

public void pushStream(java.io.InputStream is)
Pushes a new command stream onto the execution stack
Parameters:
is - Command stream to push

popStream

public java.io.InputStream popStream()
Pops the current command stream from the execution stack
Returns:
The command stream that is popped

setBindings

public void setBindings(java.lang.String varname,
                        java.lang.String value)
Registers a new environmental variable binding (local to this shell only)
Parameters:
varname - Environmental variable name
value - Environmental variable binding

getBindings

public java.lang.String getBindings(java.lang.String varname)
Gets an environmental variable binding (local to this shell only)
Parameters:
varname - The binding to retrieve
Returns:
The binding (if null returns the empty string)

initEnvVarsFromFile

public void initEnvVarsFromFile(java.lang.String filename)
Initializes the environmental variable bindings from a file
Parameters:
filename - File name to load env var bindings from

listEnv

public void listEnv()
Handles the 'listenv' command

setEnv

public void setEnv()
Handles the 'setenv' command

exec

public void exec(java.lang.String filename)
Handles the 'exec' command
Parameters:
filename - File to execute

exec_return

public void exec_return()
Handles the 'return' command (to return execution to the calling script (if any).

printHelp

public void printHelp()
Handles the 'help' command - prints the command menu

getCommand

public void getCommand()
                throws java.io.IOException
Parses a command from the current input stream and determines if it is locally executable. If not, it calls the command handler which should be overridden by any derived class.