sleep.console
Class ConsoleImplementation

java.lang.Object
  extended bysleep.console.ConsoleImplementation
All Implemented Interfaces:
Loadable, RuntimeWarningWatcher

public class ConsoleImplementation
extends Object
implements RuntimeWarningWatcher, Loadable

The ConsoleImplementation is the "engine" behind the sleep console. To use the sleep console in your application use the following steps:

1. Instantiate the console implementation

ConsoleImplementation console;
console = new ConsoleImplementation(environment, variables, loader);

2. Install your implementation of sleep.console.ConsoleProxy into the console

console.setProxy(new MyConsoleProxy());

3. Start the Read, Parse, Print Loop in the console

console.rppl(); // starts the console

See Also:
ConsoleProxy, ScriptLoader, Variable

Field Summary
protected  StringBuffer code
          current code loaded into the console so far
static int DEFAULT
           
static int INPUT_CODE
           
static int INTERACT
           
protected  int lineCount
           
protected  int mode
          the mode the console is currently in, DEFAULT, INPUT_CODE, or QUIT
protected  ConsoleProxy myProxy
          the user installed console proxy, defining all input/output for the console
static int QUIT
           
protected  ScriptInstance script
          the *active* script...
protected  ScriptLoader scriptLoader
          the script loader
protected  Hashtable sharedEnvironment
          the script environment with all of the installed functions, predicates, and environments
protected  Variable sharedVariables
          the shared variable container for all scripts, assuming variables are being shared
protected  boolean showLines
           
 
Constructor Summary
ConsoleImplementation()
          Creates an implementation of the sleep console.
ConsoleImplementation(Hashtable _sharedEnvironment, Variable _sharedVariables, ScriptLoader _loader)
          Creates an implementation of the sleep console that shares what your application is already using.
 
Method Summary
 void append(String text)
           
 boolean canContinue()
           
 void clear()
           
 String getCode()
           
 int getMode()
           
 ConsoleProxy getProxy()
           
 void handleCommand(String inputstr)
           
 void processScriptErrors(YourCodeSucksException ex)
          a convienence method that formats and writes each syntax error to the proxy output
 void processScriptWarning(ScriptWarning warning)
          fired when a runtime warning has occured.
 void prompt()
           
 void quickExecute(String command)
           
 void rppl()
          starts the console
 boolean scriptLoaded(ScriptInstance script)
          called when a script is loaded
 boolean scriptUnloaded(ScriptInstance script)
          called when a script is unloaded
 void setMode(int m)
           
 void setProxy(ConsoleProxy p)
          Sets up the implementation of the consoles input/output facilities
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

public static final int DEFAULT
See Also:
Constant Field Values

INPUT_CODE

public static final int INPUT_CODE
See Also:
Constant Field Values

QUIT

public static final int QUIT
See Also:
Constant Field Values

INTERACT

public static final int INTERACT
See Also:
Constant Field Values

mode

protected int mode
the mode the console is currently in, DEFAULT, INPUT_CODE, or QUIT


script

protected ScriptInstance script
the *active* script...


myProxy

protected ConsoleProxy myProxy
the user installed console proxy, defining all input/output for the console


sharedEnvironment

protected Hashtable sharedEnvironment
the script environment with all of the installed functions, predicates, and environments


sharedVariables

protected Variable sharedVariables
the shared variable container for all scripts, assuming variables are being shared


scriptLoader

protected ScriptLoader scriptLoader
the script loader


code

protected StringBuffer code
current code loaded into the console so far


lineCount

protected int lineCount

showLines

protected boolean showLines
Constructor Detail

ConsoleImplementation

public ConsoleImplementation()
Creates an implementation of the sleep console. The implementation created by this constructor is isolated from your applications environment. Any scripts loaded via this console will have only the default bridges.


ConsoleImplementation

public ConsoleImplementation(Hashtable _sharedEnvironment,
                             Variable _sharedVariables,
                             ScriptLoader _loader)
Creates an implementation of the sleep console that shares what your application is already using. Any of the parameters can be null.

Parameters:
_sharedEnvironment - the environment contains all of the bridges (functions, predicates, and environments)
_sharedVariables - the Variable class is a container for Scalar variables with global, local, and script specific scope
_loader - the Script Loader is a container for managing all of the currently loaded scripts
Method Detail

getProxy

public ConsoleProxy getProxy()

setProxy

public void setProxy(ConsoleProxy p)
Sets up the implementation of the consoles input/output facilities


append

public void append(String text)

getCode

public String getCode()

clear

public void clear()

getMode

public int getMode()

canContinue

public boolean canContinue()

setMode

public void setMode(int m)

prompt

public void prompt()

quickExecute

public void quickExecute(String command)

handleCommand

public void handleCommand(String inputstr)

rppl

public void rppl()
          throws IOException
starts the console

Throws:
IOException

processScriptErrors

public void processScriptErrors(YourCodeSucksException ex)
a convienence method that formats and writes each syntax error to the proxy output


processScriptWarning

public void processScriptWarning(ScriptWarning warning)
Description copied from interface: RuntimeWarningWatcher
fired when a runtime warning has occured. You might want to display this information to the user in some manner as it may contain valuable information as to why something isn't working as it should

Specified by:
processScriptWarning in interface RuntimeWarningWatcher

scriptLoaded

public boolean scriptLoaded(ScriptInstance script)
Description copied from interface: Loadable
called when a script is loaded

Specified by:
scriptLoaded in interface Loadable

scriptUnloaded

public boolean scriptUnloaded(ScriptInstance script)
Description copied from interface: Loadable
called when a script is unloaded

Specified by:
scriptUnloaded in interface Loadable