shell
Class Command

java.lang.Object
  |
  +--shell.Command
All Implemented Interfaces:
Executable, java.lang.Runnable
Direct Known Subclasses:
ShellCommand

public abstract class Command
extends java.lang.Object
implements Executable

Runtime command is a base class that all apps must extend to work inside Freelance. It provides basic functionality for the apps including and output stream and switch handling.

See Also:
TerminalThread

Field Summary
 java.io.Reader in
           
 java.io.PrintStream out
           
 
Constructor Summary
Command()
           
 
Method Summary
 void addActiveSwitch(java.lang.Object obj)
          Functionality will need to be provided in child classes.
 void addSwitch(java.lang.String key, Switch value)
           
 void addThreadListener(ThreadListener threadListener)
           
 boolean containsSwitch(java.lang.String key)
           
protected abstract  void doRun()
           
 boolean equals(Executable executable)
           
 boolean equals(java.lang.String executableName)
           
 boolean getActive()
          Provides external access to the active boolean.
 int getId()
           
 Lock getLock()
           
 java.lang.String getName()
           
 java.io.PrintStream getOutStream()
           
 java.io.Reader getReader()
           
 Switch getSwitch(java.lang.String key)
           
 boolean isPipeable()
          Not all apps will be able to accept data from a piped inputstream.
 boolean lock()
           
 void processSwitches(java.util.Vector args)
          This method takes in a Vector of a broken up command line.
 void removeThreadListener(ThreadListener threadListener)
           
 void run()
           
 void setActive(boolean active)
          Provides external access to the active boolean.
 void setArgs(java.util.Vector args, int threadId)
           
 void setArgs(java.util.Vector args, int threadId, java.io.PrintStream out)
           
 void setId(int id)
           
 void setIncomming(boolean income)
           
 void setInputStream(java.io.InputStream inStream)
           
 void setLock(Lock lock)
           
 void setOutputStream(java.io.OutputStream outStream)
           
 void setOutStream(java.io.PrintStream o)
           
 boolean stillIncomming()
           
 void unlock()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface shell.Executable
setArgs, setArgs
 

Field Detail

out

public java.io.PrintStream out

in

public java.io.Reader in
Constructor Detail

Command

public Command()
Method Detail

setId

public void setId(int id)
Specified by:
setId in interface Executable

getId

public int getId()
Specified by:
getId in interface Executable

isPipeable

public boolean isPipeable()
Not all apps will be able to accept data from a piped inputstream. For a command to be able to be recognised as a pipeable app, they must override this method and return true.

Specified by:
isPipeable in interface Executable
Returns:
Whether the app can accept piped data.
See Also:
Pipe

setActive

public void setActive(boolean active)
Provides external access to the active boolean. This should be called when an app is first run, then set to false when finished. The application's process controller can use the getter and setter for the active variable to terminate a thread prematurely, or just to keep track of what is active and what is not.

Specified by:
setActive in interface Executable
Parameters:
active - - To set the state of the RuntimeCommand.
See Also:

getActive

public boolean getActive()
Provides external access to the active boolean. This should be called when an app is first run, then set to false when finished. The application's process controller can use the getter and setter for the active variable to terminate a thread prematurely, or just to keep track of what is active and what is not.

Specified by:
getActive in interface Executable
Returns:
The current state of the RuntimeCommand.
See Also:

setLock

public void setLock(Lock lock)
Specified by:
setLock in interface Executable

getLock

public Lock getLock()

lock

public boolean lock()
Specified by:
lock in interface Executable

unlock

public void unlock()
Specified by:
unlock in interface Executable

getReader

public java.io.Reader getReader()
Specified by:
getReader in interface Executable

setInputStream

public void setInputStream(java.io.InputStream inStream)
Specified by:
setInputStream in interface Executable

getOutStream

public java.io.PrintStream getOutStream()
Specified by:
getOutStream in interface Executable

setOutStream

public void setOutStream(java.io.PrintStream o)
Specified by:
setOutStream in interface Executable

setOutputStream

public void setOutputStream(java.io.OutputStream outStream)
Specified by:
setOutputStream in interface Executable

setArgs

public void setArgs(java.util.Vector args,
                    int threadId)

setArgs

public void setArgs(java.util.Vector args,
                    int threadId,
                    java.io.PrintStream out)

addSwitch

public void addSwitch(java.lang.String key,
                      Switch value)
Specified by:
addSwitch in interface Executable

getSwitch

public Switch getSwitch(java.lang.String key)
Specified by:
getSwitch in interface Executable

containsSwitch

public boolean containsSwitch(java.lang.String key)
Specified by:
containsSwitch in interface Executable

getName

public java.lang.String getName()
Specified by:
getName in interface Executable

stillIncomming

public boolean stillIncomming()
Specified by:
stillIncomming in interface Executable

setIncomming

public void setIncomming(boolean income)
Specified by:
setIncomming in interface Executable

addActiveSwitch

public void addActiveSwitch(java.lang.Object obj)
Functionality will need to be provided in child classes. Will takes an object and add it to an ArrayList of currently active switches.

Specified by:
addActiveSwitch in interface Executable
Parameters:
obj - - Object to add to activeSwitches ArrayList.

processSwitches

public void processSwitches(java.util.Vector args)
                     throws java.io.IOException
This method takes in a Vector of a broken up command line. It checks each element to see if it is a switch, then checks the switch against the switches HashMap, setting it's values where necessary, then adding the switch id ("-f","-r", etc) into the activeSwitches ArrayList.

Specified by:
processSwitches in interface Executable
Parameters:
args - - A vector of arguments to process
java.io.IOException

addThreadListener

public void addThreadListener(ThreadListener threadListener)
Specified by:
addThreadListener in interface Executable

removeThreadListener

public void removeThreadListener(ThreadListener threadListener)
Specified by:
removeThreadListener in interface Executable

doRun

protected abstract void doRun()
                       throws java.lang.Exception
java.lang.Exception

run

public final void run()
Specified by:
run in interface Executable

equals

public boolean equals(Executable executable)
Specified by:
equals in interface Executable

equals

public boolean equals(java.lang.String executableName)
Specified by:
equals in interface Executable