# Class JexlScriptEngine

java.lang.Object
javax.script.AbstractScriptEngine
org.apache.commons.jexl3.scripting.JexlScriptEngine

All Implemented Interfaces:
  `Compilable, ScriptEngine`

public class JexlScriptEngine extends AbstractScriptEngine implements Compilable
Implements the JEXL ScriptEngine for JSF-223.

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.

See Java Scripting API Javadoc.

Since:
  2.0

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `class`
  `JexlScriptEngine.JexlScriptObject`
  Implements engine and engine context properties for use by JEXL scripts.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `CONTEXT_KEY`
  Reserved key for context (mandated by JSR-223).
  `static final String`
  `JEXL_OBJECT_KEY`
  Reserved key for JexlScriptObject.

  ### Fields inherited from class AbstractScriptEngine

  `context`

  ### Fields inherited from interface ScriptEngine

  `ARGV, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JexlScriptEngine()`
  Default constructor.
  `JexlScriptEngine(ScriptEngineFactory scriptEngineFactory)`
  Create a scripting engine using the supplied factory.

- ## Method Summary

  Modifier and Type
  Method
  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.

  ### Methods inherited from class AbstractScriptEngine

  `eval, eval, eval, eval, get, getBindings, getContext, getScriptContext, put, setBindings, setContext`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### CONTEXT_KEY

    public static final String CONTEXT_KEY
    Reserved key for context (mandated by JSR-223).
    See Also:
      - Constant Field Values

  - ### JEXL_OBJECT_KEY

    public static final String JEXL_OBJECT_KEY
    Reserved key for JexlScriptObject.
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### JexlScriptEngine

    public JexlScriptEngine()
    Default constructor.

    Only intended for use when not using a factory. Sets the factory to `JexlScriptEngineFactory`.

  - ### JexlScriptEngine

    public JexlScriptEngine(ScriptEngineFactory scriptEngineFactory)
    Create a scripting engine using the supplied factory.
    Parameters:
      `scriptEngineFactory` - the factory which created this instance.
    Throws:
      `NullPointerException` - if factory is null

- ## Method Details

  - ### setInstance

    public static void setInstance(JexlEngine engine)
    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

  - ### setPermissions

    public static void setPermissions(JexlPermissions permissions)
    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 the `JexlBuilder` default
    Since:
      3.3

  - ### compile

    public CompiledScript compile(Reader script) throws ScriptException
    Specified by:
      `compile` in interface `Compilable`
    Throws:
      `ScriptException`

  - ### compile

    public CompiledScript compile(String script) throws ScriptException
    Specified by:
      `compile` in interface `Compilable`
    Throws:
      `ScriptException`

  - ### createBindings

    public Bindings createBindings()
    Specified by:
      `createBindings` in interface `ScriptEngine`

  - ### eval

    public Object eval(Reader reader, ScriptContext context) throws ScriptException
    Specified by:
      `eval` in interface `ScriptEngine`
    Throws:
      `ScriptException`

  - ### eval

    public Object eval(String script, ScriptContext context) throws ScriptException
    Specified by:
      `eval` in interface `ScriptEngine`
    Throws:
      `ScriptException`

  - ### getFactory

    public ScriptEngineFactory getFactory()
    Specified by:
      `getFactory` in interface `ScriptEngine`