public class JexlScriptEngine extends AbstractScriptEngine implements Compilable
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.
Modifier and Type | Class and Description |
---|---|
class |
JexlScriptEngine.JexlScriptObject
Implements engine and engine context properties for use by JEXL scripts.
|
Modifier and Type | Field and Description |
---|---|
static String |
CONTEXT_KEY
Reserved key for context (mandated by JSR-223).
|
static String |
JEXL_OBJECT_KEY
Reserved key for JexlScriptObject.
|
context
ARGV, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
Constructor and Description |
---|
JexlScriptEngine()
Default constructor.
|
JexlScriptEngine(ScriptEngineFactory factory)
Create a scripting engine using the supplied factory.
|
Modifier and Type | Method and Description |
---|---|
CompiledScript |
compile(Reader script) |
CompiledScript |
compile(String script) |
Bindings |
createBindings() |
Object |
eval(Reader reader,
ScriptContext context) |
Object |
eval(String script,
ScriptContext context) |
ScriptEngineFactory |
getFactory() |
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.
|
eval, eval, eval, eval, get, getBindings, getContext, getScriptContext, put, setBindings, setContext
public static final String CONTEXT_KEY
public static final String JEXL_OBJECT_KEY
public JexlScriptEngine()
Only intended for use when not using a factory.
Sets the factory to JexlScriptEngineFactory
.
public JexlScriptEngine(ScriptEngineFactory factory)
factory
- the factory which created this instance.NullPointerException
- if factory is nullpublic static void setPermissions(JexlPermissions permissions)
Calling this method will force engine instance re-creation.
To restore 3.2 script behavior:
JexlScriptEngine.setPermissions(JexlPermissions.UNRESTRICTED);
permissions
- the permissions instance to use or null to use the JexlBuilder
defaultpublic static void setInstance(JexlEngine 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());
engine
- the JexlEngine instance to usepublic Bindings createBindings()
createBindings
in interface ScriptEngine
public Object eval(Reader reader, ScriptContext context) throws ScriptException
eval
in interface ScriptEngine
ScriptException
public Object eval(String script, ScriptContext context) throws ScriptException
eval
in interface ScriptEngine
ScriptException
public ScriptEngineFactory getFactory()
getFactory
in interface ScriptEngine
public CompiledScript compile(String script) throws ScriptException
compile
in interface Compilable
ScriptException
public CompiledScript compile(Reader script) throws ScriptException
compile
in interface Compilable
ScriptException
Copyright © 2001–2022 The Apache Software Foundation. All rights reserved.