public abstract class AbstractEnvironment extends AbstractScriptModule implements IEnvironment
Constructor and Description |
---|
AbstractEnvironment() |
Modifier and Type | Method and Description |
---|---|
void |
addModuleListener(IModuleListener listener) |
static IEnvironment |
getEnvironment(IScriptEngine engine) |
Object |
getModule(String name)
Resolves a loaded module and returns the Java instance.
|
<T,U extends Class<T>> |
getModule(U clazz)
Resolves a loaded module by its class.
|
List<Object> |
getModules()
Retrieve a list of loaded modules.
|
void |
initialize(IScriptEngine engine,
IEnvironment environment)
Provides script engine and environment instances.
|
String |
listModules()
List all available (visible) modules.
|
Object |
loadModule(String identifier)
Load a module.
|
void |
print(Object text,
boolean lineFeed)
Write a message to the output stream of the script engine.
|
void |
printError(Object text)
Write a message to the error stream of the script engine.
|
String |
readInput(boolean blocking)
Read a single line of data from the default input stream of the script engine.
|
void |
removeModuleListener(IModuleListener listener) |
getScriptEngine
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getScriptEngine, wrap
public final Object loadModule(String identifier)
loadModule
in interface IEnvironment
name
- name of module to loadpublic void initialize(IScriptEngine engine, IEnvironment environment)
IScriptModule
initialize
in interface IScriptModule
initialize
in class AbstractScriptModule
engine
- script engine this module is loaded inenvironment
- environment module that tracks this modulepublic final String listModules()
public final Object getModule(String name)
getModule
in interface IEnvironment
name
- name of the module to resolvenull
public <T,U extends Class<T>> T getModule(U clazz)
getModule
in interface IEnvironment
clazz
- module class to look resolvenull
public List<Object> getModules()
IEnvironment
getModules
in interface IEnvironment
public final void print(@ScriptParameter(defaultValue="") Object text, @ScriptParameter(defaultValue="true") boolean lineFeed)
print
in interface IEnvironment
text
- message to writelineFeed
- true
to add a line feed after the textpublic final void printError(@ScriptParameter(defaultValue="") Object text)
text
- message to writepublic void addModuleListener(IModuleListener listener)
addModuleListener
in interface IEnvironment
public void removeModuleListener(IModuleListener listener)
removeModuleListener
in interface IEnvironment
public String readInput(@ScriptParameter(defaultValue="true") boolean blocking) throws IOException
blocking
- true
results in a blocking call until data is available, false
returns in any casenull
IOException
- when reading on the input stream failspublic static IEnvironment getEnvironment(IScriptEngine engine)