Package org.eclipse.ease.modules
Interface IEnvironment
- All Superinterfaces:
IScriptModule
- All Known Implementing Classes:
EnvironmentModule
public interface IEnvironment extends IScriptModule
-
Field Summary
Fields Modifier and Type Field Description static StringEASE_CODE_PREFIXstatic StringMODULE_PREFIX -
Method Summary
Modifier and Type Method Description voidaddModuleCallback(IModuleCallbackProvider callbackProvider)Register a callback provider for module functions.voidaddModuleListener(IModuleListener listener)static IEnvironmentgetEnvironment()static IEnvironmentgetEnvironment(IScriptEngine engine)ObjectgetModule(String name)<T, U extends Class<T>>
TgetModule(U clazz)ModuleDefinitiongetModuleDefinition(Object moduleInstance)Retrieve a definition for a given module instance.List<Object>getModules()Retrieve a list of loaded modules.IScriptEnginegetScriptEngine()ObjectloadModule(String moduleIdentifier, boolean useCustomNamespace)Load a module.voidprint(Object text, boolean lineFeed)Print to standard output.StringregisterMethod(Method method)Register a method in the environment to allow for callbacks.voidremoveModuleListener(IModuleListener listener)Objectwrap(Object toBeWrapped, boolean useCustomNamespace)Wrap a java instance.Methods inherited from interface org.eclipse.ease.modules.IScriptModule
initialize
-
Field Details
-
EASE_CODE_PREFIX
- See Also:
- Constant Field Values
-
MODULE_PREFIX
- See Also:
- Constant Field Values
-
-
Method Details
-
getEnvironment
-
getEnvironment
-
getScriptEngine
IScriptEngine getScriptEngine() -
getModule
-
getModule
-
getModules
Retrieve a list of loaded modules. The returned list is read only.- Returns:
- list of modules (might be empty)
-
getModuleDefinition
Retrieve a definition for a given module instance.- Parameters:
moduleInstance- instance of module to retrieve definition for- Returns:
- module definition
- Throws:
IllegalArgumentException- when no definition can be found for moduleInstance
-
print
Print to standard output.- Parameters:
text- message to writelineFeed-trueto add a line feed after the text
-
addModuleListener
-
removeModuleListener
-
loadModule
Object loadModule(String moduleIdentifier, @ScriptParameter(defaultValue="false") boolean useCustomNamespace) throws ExecutionExceptionLoad a module. Loading a module generally enhances the script environment with new functions and variables. If a module was already loaded before, it gets refreshed and moved to the top of the module stack. When a module is loaded, all its dependencies are loaded too. So loading one module might change the whole module stack.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.
- Parameters:
moduleIdentifier- name of module to loaduseCustomNamespace- set totrueif functions and constants should not be stored to the global namespace but to a custom object- Returns:
- loaded module instance
- Throws:
ExecutionException- when execution of wrapped module code fails
-
wrap
Wrap a java instance. Will create accessors in the target language for methods and constants defined by the java instance toBeWrapped. If the instance contains annotations of typeWrapToScriptonly 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.- Parameters:
toBeWrapped- instance to be wrappeduseCustomNamespace- set totrueif functions and constants should not be stored to the global namespace but to the return value only- Returns:
- wrapped object instance or java class when put to global namespace
- Throws:
ExecutionException- when execution of wrapped code fails
-
addModuleCallback
Register a callback provider for module functions.- Parameters:
callbackProvider- callback provider instance
-
registerMethod
Register a method in the environment to allow for callbacks.- Parameters:
method- method to be registered- Returns:
- unique ID identifying the method
-