The org.bzdev.scripting package
This package provides several classes shown in the following UML diagram:
- ScriptingContext provides protected methods for specifying a script
engine,the default bindings to use (the scope is the one specified
the
javax.script.ScriptContext
fieldENGINE_SCOPE
),the script language (which should be the official name such as ECMAScript for JavaScript). Subclasses should implement these methods unless configured to use a parent ScriptingContext, in which case the parent's script and bindings are used. A ScriptingContext can have a parent scripting context. The parent will provide the actual scripting operations, but may have a different trust level (see below). Scripting
is a class containing only static methods and allows one to look up information about the scripting languages that a Java implementation supports (this may depend on the class path or module path).
The class ScriptingContext itself does not directly enable scripting: several methods need to be implemented to enable it. This can be done by the class DefaultScriptingContext, which allows one to create a ScriptingContext given just the scripting-language name. A second class, ExtendedScriptingContext, provides methods for creating Java arrays and for calling Java constructors (a bug/feature in at least one older scripting-language implementation prevented a script from creating an instance of a class that is a subclass of ScriptingContext, so a work-around was needed for this case).