public class EnvironmentModule extends AbstractScriptModule implements IEnvironment
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
EASE_CODE_PREFIX |
static java.lang.String |
MODULE_NAME |
static java.lang.String |
MODULE_PREFIX |
Constructor and Description |
---|
EnvironmentModule() |
Modifier and Type | Method and Description |
---|---|
void |
addModuleCallback(IModuleCallbackProvider callbackProvider)
Register a callback provider for module functions.
|
void |
addModuleListener(IModuleListener listener) |
static void |
bootstrap() |
java.lang.Object |
execute(java.lang.Object data)
Execute script code.
|
void |
exit(java.lang.Object value)
Terminates script execution immediately.
|
java.lang.Object |
getModule(java.lang.String name)
Resolves a loaded module and returns the Java instance.
|
<T,U extends java.lang.Class<T>> |
getModule(U clazz)
Resolves a loaded module by its class.
|
java.lang.Object |
getModuleInstance(ModuleDefinition definition) |
java.util.List<java.lang.Object> |
getModules()
Retrieve a list of loaded modules.
|
IScriptEngine |
getScriptEngine()
Get the current script engine instance.
|
static java.lang.String |
getWrappedVariableName(java.lang.Object toBeWrapped) |
boolean |
hasMethodCallback(java.lang.String methodToken) |
void |
help(java.lang.String topic)
Open help page on addressed topic.
|
java.lang.Object |
include(java.lang.String filename)
Include and execute a script file.
|
boolean |
loadJar(java.lang.Object location)
Add a jar file to the classpath.
|
java.lang.Object |
loadModule(java.lang.String moduleIdentifier,
boolean useCustomNamespace)
Load a module.
|
void |
postMethodCallback(java.lang.String methodToken,
java.lang.Object result) |
void |
preMethodCallback(java.lang.String methodToken,
java.lang.Object... parameters) |
void |
print(java.lang.Object text,
boolean lineFeed)
Write a message to the output stream of the script engine.
|
void |
printError(java.lang.Object text)
Write a message to the error stream of the script engine.
|
java.lang.String |
readInput(boolean blocking)
Read a single line of data from the default input stream of the script engine.
|
java.lang.String |
registerMethod(java.lang.reflect.Method method) |
void |
removeModuleListener(IModuleListener listener) |
java.lang.Object |
wrap(java.lang.Object toBeWrapped,
boolean useCustomNamespace)
Wrap a java instance.
|
initialize
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getEnvironment, getEnvironment
public static final java.lang.String MODULE_NAME
public static final java.lang.String EASE_CODE_PREFIX
public static final java.lang.String MODULE_PREFIX
public static void bootstrap()
public java.lang.Object getModuleInstance(ModuleDefinition definition)
public final java.lang.Object loadModule(java.lang.String moduleIdentifier, @ScriptParameter(defaultValue="false") boolean useCustomNamespace)
IEnvironment
When not using a custom namespace all variables and functions are loaded to the global namespace, possibly overriding existing functions. In such cases the Java module instance is returned. When useCustomNamespace is used a dynamic script object is created and returned.In such cases the global namespace is not changed. The namespace behavior is also used for loading dependencies.
loadModule
in interface IEnvironment
moduleIdentifier
- name of module to loaduseCustomNamespace
- set to true
if functions and constants should not be stored to the global namespace but to a custom objectpublic final java.lang.Object getModule(java.lang.String name)
getModule
in interface IEnvironment
name
- name of the module to resolvenull
public <T,U extends java.lang.Class<T>> T getModule(U clazz)
getModule
in interface IEnvironment
clazz
- module class to look resolvenull
public java.util.List<java.lang.Object> getModules()
IEnvironment
getModules
in interface IEnvironment
public final void print(@ScriptParameter(defaultValue="") java.lang.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="") java.lang.Object text)
text
- message to writepublic void addModuleListener(IModuleListener listener)
addModuleListener
in interface IEnvironment
public void removeModuleListener(IModuleListener listener)
removeModuleListener
in interface IEnvironment
public java.lang.String readInput(@ScriptParameter(defaultValue="true") boolean blocking) throws java.io.IOException
blocking
- true
results in a blocking call until data is available, false
returns in any casenull
java.io.IOException
- when reading on the input stream failspublic java.lang.Object wrap(java.lang.Object toBeWrapped, @ScriptParameter(defaultValue="false") boolean useCustomNamespace)
IEnvironment
WrapToScript
only these will be wrapped. If no annotation can be found, all public methods/constants will
be wrapped. As some target languages might not support method overloading this might result in some methods not wrapped correctly.wrap
in interface IEnvironment
toBeWrapped
- instance to be wrappeduseCustomNamespace
- set to true
if functions and constants should not be stored to the global namespace but to the return value onlypublic static final java.lang.String getWrappedVariableName(java.lang.Object toBeWrapped)
public final java.lang.Object execute(java.lang.Object data)
data
- code to be interpretedpublic final void exit(@ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.Object value)
value
- return codepublic final java.lang.Object include(java.lang.String filename)
filename
- name of file to be includedjava.lang.Throwable
public IScriptEngine getScriptEngine()
getScriptEngine
in interface IEnvironment
getScriptEngine
in class AbstractScriptModule
IScriptEngine
instancepublic boolean loadJar(java.lang.Object location) throws java.net.MalformedURLException
public void help(@ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.String topic)
topic
- help topic to open (typically a function name)public void addModuleCallback(IModuleCallbackProvider callbackProvider)
IEnvironment
addModuleCallback
in interface IEnvironment
callbackProvider
- callback provider instancepublic boolean hasMethodCallback(java.lang.String methodToken)
public void preMethodCallback(java.lang.String methodToken, java.lang.Object... parameters)
public void postMethodCallback(java.lang.String methodToken, java.lang.Object result)
public java.lang.String registerMethod(java.lang.reflect.Method method)