Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

ScriptWrapper configuration



The ScriptWrapper has several methods allowing to configure it. For example:
  • Set the Script context which can be used by the scripts
  • Add a Exception listener to handle exceptions thrown during the execution of the scripts
  • Add a logger to log messages echoed during the execution of the scripts
  • Add custom default imports to the scripts
  • Set the ClassLoader to use with the wrapper
  • Configure the optimization level of the compilation for the wrappers which allow it

Setting the Script context

The Script context is available through the context field in your scripts. By default a basic DefaultScriptContext is provided by the wrapper, but you can set another one by ScriptWrapper.setScriptContext(ScriptContext).

Setting the Script logger

The Script logger is an interface which logs informations and errors during the script execution. The default logger logs to the output stream and error stream, but you can set another one by ScriptWrapper.setScriptLogger(ScriptLogger).

Adding an Exception listener

Main Article: Exceptions handling

Exception listeners handle exceptions thrown during the execution of the scripts. You can add an Exception listener by ScriptWrapper.addExceptionListener(ScriptExceptionListener).

Note that you can also avoid to throw exceptions but instead log them to the Script logger by ScriptWrapper.logExceptions(boolean).

Adding custom default imports

Main Article: Adding default imports

By default scripts will have the following default imports: It is possible to add custom default imports to the scripts in the ScriptWrapper interface.

Setting the ClassLoader

It is possible to set the ClassLoader to use with the wrapper with ScriptWrapper.setClassLoader(ClassLoader).

Configuring the optimization level

It is possible to configure the optimization level for scripting languages which allow it by ScriptWrapper.setOptimizationLevel(String). If thhe scripting language does not support optimization levels, the method will do nothing. The value can be one of the following values:
  • "default": the default optimization level
  • "minimum": the minimum optimization level
  • "maximum": the maximum optimization level
  • any int value: a specified optimization level (depend if the scripting library allow them)
  • other value: do nothing
Values which are not allowed will be silently ignored.

Note that currently only the Groovy and Javascript scripting languages implementations support this option. For other languages, it will do nothing.

See also


Categories: api

Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence