Class JexlScriptEngine
- All Implemented Interfaces:
Compilable
,ScriptEngine
This implementation gives access to both ENGINE_SCOPE and GLOBAL_SCOPE bindings. When a JEXL script accesses a variable for read or write, this implementation checks first ENGINE and then GLOBAL scope. The first one found is used. If no variable is found, and the JEXL script is writing to a variable, it will be stored in the ENGINE scope.
The implementation also creates the "JEXL" script object as an instance of the
class JexlScriptEngine.JexlScriptObject
for access to utility methods and variables.
- Since:
- 2.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Holds singleton JexlScriptEngineFactory (IODH).private final class
Wrapper to help convert a JEXL JexlScript into a JSR-223 CompiledScript.private final class
Wrapper to help convert a JSR-223 ScriptContext into a JexlContext.class
Implements engine and engine context properties for use by JEXL scripts. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final int
The shared expression cache size.static final String
Reserved key for context (mandated by JSR-223).private static Reference<JexlEngine>
The shared engine instance.static final String
Reserved key for JexlScriptObject.(package private) final JexlEngine
The JEXL EL engine.(package private) final JexlScriptEngine.JexlScriptObject
The JexlScriptObject instance.(package private) static final org.apache.commons.logging.Log
The logger.(package private) final ScriptEngineFactory
The factory which created this instance.private static JexlPermissions
The permissions used to create the script engine.Fields inherited from class javax.script.AbstractScriptEngine
context
Fields inherited from interface javax.script.ScriptEngine
ARGV, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.JexlScriptEngine
(ScriptEngineFactory factory) Create a scripting engine using the supplied factory. -
Method Summary
Modifier and TypeMethodDescriptioneval
(Reader reader, ScriptContext context) eval
(String script, ScriptContext context) private static JexlEngine
private static String
readerToString
(Reader scriptReader) Read from a reader into a local buffer and return a String with the contents of the reader.(package private) static ScriptException
static void
setInstance
(JexlEngine engine) Sets the shared instance used for the script engine.static void
setPermissions
(JexlPermissions permissions) Sets the permissions instance used to create the script engine.Methods inherited from class javax.script.AbstractScriptEngine
eval, eval, eval, eval, get, getBindings, getContext, getScriptContext, put, setBindings, setContext
-
Field Details
-
ENGINE
The shared engine instance.A single soft-reference JEXL engine and JexlUberspect is shared by all instances of JexlScriptEngine.
-
PERMISSIONS
The permissions used to create the script engine. -
LOG
static final org.apache.commons.logging.Log LOGThe logger. -
CACHE_SIZE
static final int CACHE_SIZEThe shared expression cache size.- See Also:
-
CONTEXT_KEY
Reserved key for context (mandated by JSR-223).- See Also:
-
JEXL_OBJECT_KEY
Reserved key for JexlScriptObject.- See Also:
-
jexlObject
The JexlScriptObject instance. -
parentFactory
The factory which created this instance. -
jexlEngine
The JEXL EL engine.
-
-
Constructor Details
-
JexlScriptEngine
public JexlScriptEngine()Default constructor.Only intended for use when not using a factory. Sets the factory to
JexlScriptEngineFactory
. -
JexlScriptEngine
Create a scripting engine using the supplied factory.- Parameters:
factory
- the factory which created this instance.- Throws:
NullPointerException
- if factory is null
-
-
Method Details
-
setPermissions
Sets the permissions instance used to create the script engine.Calling this method will force engine instance re-creation.
To restore 3.2 script behavior:
JexlScriptEngine.setPermissions(JexlPermissions.UNRESTRICTED);
- Parameters:
permissions
- the permissions instance to use or null to use theJexlBuilder
default- Since:
- 3.3
-
setInstance
Sets the shared instance used for the script engine.This should be called early enough to have an effect, ie before any
ScriptEngineManager
features.To restore 3.2 script behavior:
JexlScriptEngine.setInstance(new JexlBuilder() .cache(512) .logger(LogFactory.getLog(JexlScriptEngine.class)) .permissions(JexlPermissions.UNRESTRICTED) .create());
- Parameters:
engine
- the JexlEngine instance to use- Since:
- 3.3
-
getEngine
- Returns:
- the shared JexlEngine instance, create it if necessary
-
createBindings
- Specified by:
createBindings
in interfaceScriptEngine
-
eval
- Specified by:
eval
in interfaceScriptEngine
- Throws:
ScriptException
-
eval
- Specified by:
eval
in interfaceScriptEngine
- Throws:
ScriptException
-
getFactory
- Specified by:
getFactory
in interfaceScriptEngine
-
compile
- Specified by:
compile
in interfaceCompilable
- Throws:
ScriptException
-
scriptException
-
compile
- Specified by:
compile
in interfaceCompilable
- Throws:
ScriptException
-
readerToString
Read from a reader into a local buffer and return a String with the contents of the reader.- Parameters:
scriptReader
- to be read.- Returns:
- the contents of the reader as a String.
- Throws:
ScriptException
- on any error reading the reader.
-