de.uniba.wiai.lspi.util.console
Class ConsoleThread

java.lang.Object
  extended by java.lang.Thread
      extended by de.uniba.wiai.lspi.util.console.ConsoleThread
All Implemented Interfaces:
java.lang.Runnable

public class ConsoleThread
extends java.lang.Thread

Version:
1.0.5
Author:
sven

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Method Summary
 CommandFactory getCommandFactory()
          Get a reference to the CommandFactory used by this console.
static ConsoleThread getConsole()
          Method to obtain a reference to the console currently active in this JVM.
static ConsoleThread getConsole(java.lang.String name, CommandFactory factory)
          Factory method to get a reference to the console singleton.
static ConsoleThread getConsole(java.lang.String name, CommandFactory factory, java.io.OutputStream systemOut)
          Factory method to create a console.
 java.io.PrintStream getPrintStream()
          Get a reference to the PrintStream this console prints its output to.
 java.io.OutputStream getSystemOutputStream()
          Get a reference to the OutputStream calls to System.out are delegated to.
 void run()
          The run method.
 void setExitCommand(java.lang.String commandName)
          Set the Command that exits this console.
 void setWelcomeText(java.lang.String text)
          Set a costum welcome text for the console.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getConsole

public static ConsoleThread getConsole()
Method to obtain a reference to the console currently active in this JVM. Returns null, if there is none.

Returns:
Reference to the singleton console thread.

getConsole

public static ConsoleThread getConsole(java.lang.String name,
                                       CommandFactory factory)
Factory method to get a reference to the console singleton. Creates a new instance if there is no console in the JVM. If there is currently one console the arguments provided to this method have no effect.

Parameters:
name -
factory -
Returns:
Reference to the singleton console thread.

getConsole

public static ConsoleThread getConsole(java.lang.String name,
                                       CommandFactory factory,
                                       java.io.OutputStream systemOut)
Factory method to create a console. Creates a new instance if there is no console in the JVM. If there is currently one console the arguments provided to this method have no effect.

Parameters:
name -
factory -
systemOut -
Returns:
Reference to the singleton console thread.

getPrintStream

public java.io.PrintStream getPrintStream()
Get a reference to the PrintStream this console prints its output to.

Returns:
Reference to the PrintStream this console prints its output to.

getSystemOutputStream

public java.io.OutputStream getSystemOutputStream()
Get a reference to the OutputStream calls to System.out are delegated to. Returns null if System.out has not been redirected.

Returns:
Reference to the OutputStream calls to System.out are delegated to. Returns null if System.out has not been redirected.

getCommandFactory

public CommandFactory getCommandFactory()
Get a reference to the CommandFactory used by this console.

Returns:
Reference to the CommandFactory used by this console.

setWelcomeText

public void setWelcomeText(java.lang.String text)
Set a costum welcome text for the console.

Parameters:
text - The welcome text to set.

run

public void run()
The run method. Loops until the exitCommand has been invoked.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

setExitCommand

public void setExitCommand(java.lang.String commandName)
                    throws ConsoleException
Set the Command that exits this console. Uses the CommandFactory to create an instance of the Command.

Parameters:
commandName - The name of the command.
Throws:
ConsoleException - Exception during creation of the command.