Class ConsoleImplementation
- java.lang.Object
-
- sleep.console.ConsoleImplementation
-
- All Implemented Interfaces:
ConsoleProxy
,RuntimeWarningWatcher
,Loadable
public class ConsoleImplementation extends java.lang.Object implements RuntimeWarningWatcher, Loadable, ConsoleProxy
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
When embedding the console reusing the object of an already quitted console is not only allowed but it is also recommended. When a user quits the console with the quit command the console proxy is set to a dummy console that does not output anything. To restart a quitted console just set the appropriate proxy again and call the
rppl()
method.- See Also:
ConsoleProxy
,ScriptLoader
,Variable
-
-
Constructor Summary
Constructors Constructor Description ConsoleImplementation()
Creates an implementation of the sleep console.ConsoleImplementation(java.util.Hashtable _sharedEnvironment, Variable _sharedVariables, ScriptLoader _loader)
Creates an implementation of the sleep console that shares what your application is already using.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
consolePrint(java.lang.String m)
Dummy implementation, does nothing really.void
consolePrintln(java.lang.Object m)
Dummy implementation, does nothing.java.lang.String
consoleReadln()
Dummy implementation, always returns null.ConsoleProxy
getProxy()
Returns the current console proxy being usedvoid
processScriptErrors(YourCodeSucksException ex)
a convienence method that formats and writes each syntax error to the proxy outputvoid
processScriptWarning(ScriptWarning warning)
fired when a runtime warning has occured.void
rppl()
starts the consolevoid
scriptLoaded(ScriptInstance script)
called when a script is loadedvoid
scriptUnloaded(ScriptInstance script)
called when a script is unloadedvoid
setProxy(ConsoleProxy p)
Sets up the implementation of the consoles input/output facilities
-
-
-
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(java.util.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.Warning! If you choose to use the Sleep console in your application with this constructor, be aware that even if you don't specify a set of variables or an environment for scripts to share that they will all end up sharing something as the sleep console will create and install its own environment or variables if you don't specify something.
- 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()
Returns the current console proxy being used
-
setProxy
public void setProxy(ConsoleProxy p)
Sets up the implementation of the consoles input/output facilities
-
consolePrint
public void consolePrint(java.lang.String m)
Dummy implementation, does nothing really.- Specified by:
consolePrint
in interfaceConsoleProxy
- Parameters:
m
- the message to print
-
consoleReadln
public java.lang.String consoleReadln()
Dummy implementation, always returns null.- Specified by:
consoleReadln
in interfaceConsoleProxy
-
consolePrintln
public void consolePrintln(java.lang.Object m)
Dummy implementation, does nothing.- Specified by:
consolePrintln
in interfaceConsoleProxy
- Parameters:
m
- the message to print
-
rppl
public void rppl() throws java.io.IOException
starts the console- Throws:
java.io.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 interfaceRuntimeWarningWatcher
-
scriptLoaded
public void scriptLoaded(ScriptInstance script)
Description copied from interface:Loadable
called when a script is loaded- Specified by:
scriptLoaded
in interfaceLoadable
-
scriptUnloaded
public void scriptUnloaded(ScriptInstance script)
Description copied from interface:Loadable
called when a script is unloaded- Specified by:
scriptUnloaded
in interfaceLoadable
-
-