edu.nmu.os.shell
Class CommandImpl

java.lang.Object
  |
  +--edu.nmu.os.shell.Command
        |
        +--edu.nmu.os.shell.CommandImpl
All Implemented Interfaces:
java.lang.Runnable

public class CommandImpl
extends Command

Encapsulates the functionality of a single shell command

Since:
jdk1.4
Version:
1.0, 01/24/2003
Author:
Matt Murphy

Constructor Summary
CommandImpl(Shell shell, java.lang.String string, java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err, java.lang.String[] args, java.lang.String program, boolean fork, boolean exit, boolean force)
          Constructs a new CommandImpl
 
Method Summary
 boolean forceCurrentThread()
          Determines whether the Command should be run in the same Thread as the executor
 boolean fork()
          Determines whether this Command should be joined with immediately after its execution
 java.lang.String[] getArgs()
          Gets the parameters that will be given to the program when this Command is executed
 java.io.PrintStream getErr()
          Gets the PrintStream that should be used as NewSystem.err during execution
 java.io.InputStream getIn()
          Gets the InputStream that should be used as NewSystem.in during execution
 java.io.PrintStream getOut()
          Gets the PrintStream that should be used as NewSystem.out during execution
 java.lang.String getProgram()
          Gets the name of the program that will be run when this Command is executed
protected  Shell getShell()
           
 boolean isExit()
          Determines whether or not this Command is a command to exit the Shell
protected  java.lang.Class resolveClass(java.lang.String program)
          Resolves the given program as a Class
protected  java.io.File resolveExecutable(java.lang.String program)
          Resolves the given program as a File
 java.lang.String toString()
          Returns the string specified in the constructor
 
Methods inherited from class edu.nmu.os.shell.Command
isResolved, run
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CommandImpl

public CommandImpl(Shell shell,
                   java.lang.String string,
                   java.io.InputStream in,
                   java.io.PrintStream out,
                   java.io.PrintStream err,
                   java.lang.String[] args,
                   java.lang.String program,
                   boolean fork,
                   boolean exit,
                   boolean force)
Constructs a new CommandImpl

Parameters:
string - to be returned by toString()
in - to be returned by getIn()
out - to be returned by getOut()
err - to be returned by getErr()
args - to be returned by getArgs()
program - to be returned by getProgram()
fork - to be returned by fork()
exit - to be returned by isExit()
force - to be returned by forceCurrentThread()
Method Detail

getShell

protected Shell getShell()
Specified by:
getShell in class Command

getProgram

public java.lang.String getProgram()
Description copied from class: Command
Gets the name of the program that will be run when this Command is executed

Specified by:
getProgram in class Command
Returns:
the name of the program

getArgs

public java.lang.String[] getArgs()
Description copied from class: Command
Gets the parameters that will be given to the program when this Command is executed

Specified by:
getArgs in class Command
Returns:
the parameters

fork

public boolean fork()
Description copied from class: Command
Determines whether this Command should be joined with immediately after its execution

Specified by:
fork in class Command
Returns:
false if the executor should wait for the Thread to exit before continuing, true otherwise

getIn

public java.io.InputStream getIn()
Description copied from class: Command
Gets the InputStream that should be used as NewSystem.in during execution

Specified by:
getIn in class Command
Returns:
the InputStream

getOut

public java.io.PrintStream getOut()
Description copied from class: Command
Gets the PrintStream that should be used as NewSystem.out during execution

Specified by:
getOut in class Command
Returns:
the PrintStream

getErr

public java.io.PrintStream getErr()
Description copied from class: Command
Gets the PrintStream that should be used as NewSystem.err during execution

Specified by:
getErr in class Command
Returns:
the PrintStream

isExit

public boolean isExit()
Description copied from class: Command
Determines whether or not this Command is a command to exit the Shell

Specified by:
isExit in class Command
Returns:
true if the Shell should exit after execution, false othewise

forceCurrentThread

public boolean forceCurrentThread()
Description copied from class: Command
Determines whether the Command should be run in the same Thread as the executor

Specified by:
forceCurrentThread in class Command
Returns:
true if the Command should be run in the current Thread

toString

public java.lang.String toString()
Returns the string specified in the constructor

Overrides:
toString in class java.lang.Object
Returns:
this Command as a String

resolveClass

protected java.lang.Class resolveClass(java.lang.String program)
                                throws java.lang.ClassNotFoundException
Resolves the given program as a Class

Tries to resolve the Class to classes in the current Shell's classpath path if the default implementation is not sufficient

Overrides:
resolveClass in class Command
Parameters:
program - the name of the program to be resolved
Returns:
the resolved Class
Throws:
java.lang.ClassNotFoundException - if resolution was unsuccessful

resolveExecutable

protected java.io.File resolveExecutable(java.lang.String program)
                                  throws java.io.FileNotFoundException
Resolves the given program as a File

Tries to resolve the File to files in the current Shell's path

Overrides:
resolveExecutable in class Command
Parameters:
program - the name of the program to be resolved
Returns:
the resolved File
Throws:
java.io.FileNotFoundException - if resolution was unsuccessful