Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.jexl3.internal
Class Script

    java.lang.Object
      org.apache.commons.jexl3.internal.Script

All Implemented Interfaces:
  JexlExpression, JexlScript

Direct Known Subclasses:
  Closure, Script.Curried

    public class Script

extends Object
implements JexlScript, JexlExpression

A JexlScript implementation.

Since:
  1.1

Nested Class Summary
`class` | `Script.Callable` Implements the Future and Callable interfaces to help delegation.
`static class` | `Script.Curried` A script whose parameters are (partially) bound.

Field Summary
`protected Engine` | `jexl` The engine for this expression.
`protected ASTJexlScript` | `script` The resulting AST we can interpret.
`protected String` | `source` Original expression stripped from leading and trailing spaces.
`protected int` | `version` The engine version (as class loader change count) that last evaluated this script.

Constructor Summary
`protected` | `Script(Engine engine, String expr, ASTJexlScript ref)` Do not let this be generally instantiated with a 'new'.

Method Summary
`Script.Callable` | `callable(JexlContext context)` Creates a Callable from this script.
`Script.Callable` | `callable(JexlContext context, Object... args)` Creates a Callable from this script.
`protected void` | `checkCacheVersion()` Checks that this script cached methods (wrt introspection) matches the engine version.
`protected Scope.Frame` | `createFrame(Object[] args)` Creates this script frame for evaluation.
`protected Interpreter` | `createInterpreter(JexlContext context, Scope.Frame frame)` Creates this script interpreter.
`JexlScript` | `curry(Object... args)` Curries this script, returning a script with bound arguments.
`boolean` | `equals(Object obj)`
`Object` | `evaluate(JexlContext context)` Evaluates the expression with the variables contained in the supplied `JexlContext`.
`Object` | `execute(JexlContext context)` Executes the script with the variables contained in the supplied `JexlContext`.
`Object` | `execute(JexlContext context, Object... args)` Executes the script with the variables contained in the supplied `JexlContext` and a set of arguments corresponding to the parameters used during parsing.
`JexlEngine` | `getEngine()`
`String[]` | `getLocalVariables()` Gets this script local variables.
`String[]` | `getParameters()` Gets this script parameters.
`String` | `getParsedText()` Recreates the source text of this expression from the internal syntactic tree.
`String` | `getParsedText(int indent)` Recreates the source text of this expression from the internal syntactic tree.
`Map<String,Object>` | `getPragmas()` Get this script pragmas
`String` | `getSourceText()` Returns the source text of this expression.
`Set<List<String>>` | `getVariables()` Gets this script variables.
`int` | `hashCode()`
`String` | `toString()`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### jexl

    protected final Engine jexl

  The engine for this expression.

### source

    protected final String source

  Original expression stripped from leading and trailing spaces.

### script

    protected final ASTJexlScript script

  The resulting AST we can interpret.

### version

    protected int version

  The engine version (as class loader change count) that last evaluated this script.

Constructor Detail

### Script

    protected Script(Engine engine,
                     String expr,
                     ASTJexlScript ref)

  Do not let this be generally instantiated with a 'new'.

  Parameters:
    `engine` - the interpreter to evaluate the expression
    `expr` - the expression source.
    `ref` - the parsed expression.

Method Detail

### checkCacheVersion

    protected void checkCacheVersion()

  Checks that this script cached methods (wrt introspection) matches the engine version.

  If the engine class loader has changed since we last evaluated this script, the script local cache is invalidated to drop references to obsolete methods. It is not strictly necessary since the tryExecute will fail because the class wont match but it seems cleaner nevertheless.

### createFrame

    protected Scope.Frame createFrame(Object[] args)

  Creates this script frame for evaluation.

  Parameters:
    `args` - the arguments to bind to parameters
  Returns:
    the frame (may be null)

### createInterpreter

    protected Interpreter createInterpreter(JexlContext context,
                                            Scope.Frame frame)

  Creates this script interpreter.

  Parameters:
    `context` - the context
    `frame` - the calling frame
  Returns:
    the interpreter

### getEngine

    public JexlEngine getEngine()

  Returns:
    the engine that created this script

### getSourceText

    public String getSourceText()

  Description copied from interface: `JexlScript`
  Returns the source text of this expression.

  Specified by:
    `getSourceText` in interface `JexlExpression`
  Specified by:
    `getSourceText` in interface `JexlScript`
  Returns:
    the source text

### getParsedText

    public String getParsedText()

  Description copied from interface: `JexlScript`
  Recreates the source text of this expression from the internal syntactic tree.

  Specified by:
    `getParsedText` in interface `JexlExpression`
  Specified by:
    `getParsedText` in interface `JexlScript`
  Returns:
    the source text

### getParsedText

    public String getParsedText(int indent)

  Description copied from interface: `JexlScript`
  Recreates the source text of this expression from the internal syntactic tree.

  Specified by:
    `getParsedText` in interface `JexlScript`
  Parameters:
    `indent` - the number of spaces for indentation, 0 meaning no indentation
  Returns:
    the source text

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `Object`

### equals

    public boolean equals(Object obj)

  Overrides:
    `equals` in class `Object`

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

### evaluate

    public Object evaluate(JexlContext context)

  Description copied from interface: `JexlExpression`
  Evaluates the expression with the variables contained in the supplied `JexlContext`.

  Specified by:
    `evaluate` in interface `JexlExpression`
  Parameters:
    `context` - A JexlContext containing variables.
  Returns:
    The result of this evaluation

### execute

    public Object execute(JexlContext context)

  Description copied from interface: `JexlScript`
  Executes the script with the variables contained in the supplied `JexlContext`.

  Specified by:
    `execute` in interface `JexlScript`
  Parameters:
    `context` - A JexlContext containing variables.
  Returns:
    The result of this script, usually the result of the last statement.

### execute

    public Object execute(JexlContext context,
                          Object... args)

  Description copied from interface: `JexlScript`
  Executes the script with the variables contained in the supplied `JexlContext` and a set of arguments corresponding to the parameters used during parsing.

  Specified by:
    `execute` in interface `JexlScript`
  Parameters:
    `context` - A JexlContext containing variables.
    `args` - the arguments
  Returns:
    The result of this script, usually the result of the last statement.

### curry

    public JexlScript curry(Object... args)

  Description copied from interface: `JexlScript`
  Curries this script, returning a script with bound arguments.

  If this script does not declare parameters or if all of them are already bound, no error is generated and this script is returned.

  Specified by:
    `curry` in interface `JexlScript`
  Parameters:
    `args` - the arguments to bind
  Returns:
    the curried script or this script if no binding can occur

### getParameters

    public String[] getParameters()

  Gets this script parameters.

  Specified by:
    `getParameters` in interface `JexlScript`
  Returns:
    the parameters or null
  Since:
    3.0

### getLocalVariables

    public String[] getLocalVariables()

  Gets this script local variables.

  Specified by:
    `getLocalVariables` in interface `JexlScript`
  Returns:
    the local variables or null

### getVariables

    public Set<List<String>> getVariables()

  Gets this script variables.

  Note that since variables can be in an ant-ish form (ie foo.bar.quux), each variable is returned as a list of strings where each entry is a fragment of the variable ({"foo", "bar", "quux"} in the example.

  Specified by:
    `getVariables` in interface `JexlScript`
  Returns:
    the variables or null

### getPragmas

    public Map<String,Object> getPragmas()

  Get this script pragmas

  Pragma keys are ant-ish variables, their values are scalar literals..

  Specified by:
    `getPragmas` in interface `JexlScript`
  Returns:
    the pragmas

### callable

    public Script.Callable callable(JexlContext context)

  Creates a Callable from this script.

  This allows to submit it to an executor pool and provides support for asynchronous calls.

  The interpreter will handle interruption/cancellation gracefully if needed.

  Specified by:
    `callable` in interface `JexlExpression`
  Specified by:
    `callable` in interface `JexlScript`
  Parameters:
    `context` - the context
  Returns:
    the callable

### callable

    public Script.Callable callable(JexlContext context,
                                    Object... args)

  Creates a Callable from this script.

  This allows to submit it to an executor pool and provides support for asynchronous calls.

  The interpreter will handle interruption/cancellation gracefully if needed.

  Specified by:
    `callable` in interface `JexlScript`
  Parameters:
    `context` - the context
    `args` - the script arguments
  Returns:
    the callable

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001–2017 The Apache Software Foundation. All rights reserved.