Creates and evaluates Expression and Script objects. Determines the behavior of Expressions & Scripts during their evaluation with respect to:
UberspectJexlArithmeticThe setSilent and setLenient methods allow to fine-tune an engine instance behavior
according to various error control needs. The lenient/strict flag tells the engine when and if null as operand is
considered an error, the silent/verbose flag tells the engine what to do with the error
(log as warning or throw exception).
0 & null should be indicators of "default" values so that even in an case of error, something meaningfull can still be inferred; may be convenient for configurations.
One should probably consider using null as an error case - ie, every object manipulated by JEXL should be valued; the ternary operator, especially the '?:' form can be used to workaround exceptional cases. Use case could be configuration with no implicit values or defaults.
The error control grain is roughly on par with JEXL 1.0
The finest error control grain is obtained; it is the closest to Java code - still augmented by "script" capabilities regarding automated conversions & type matching.
Note that methods that evaluate expressions may throw unchecked exceptions;
The JexlException are thrown in "non-silent" mode but since these are
RuntimeException, user-code should catch them wherever most appropriate.
| Modifier and Type | Class and Description |
|---|---|
| public static class | JexlEngine.Frame
A call frame, created from a scope, stores the arguments and local variables as "registers". |
| public static class | JexlEngine.Scope
A script scope, stores the declaration of parameters and local variables. |
| protected class | JexlEngine.SoftCache<
the cache key entry type K, the cache key value type V>A soft reference on cache. |
| private static class | JexlEngine.UberspectHolder
Gets the default instance of Uberspect. |
| Modifier and Type | Field and Description |
|---|---|
| protected final JexlArithmetic | arithmetic
The JexlArithmetic instance. |
| protected JexlEngine. | cache
The expression cache. |
| protected volatile boolean | debug
Whether error messages will carry debugging information. |
| public static final JexlContext | EMPTY_CONTEXT
An empty/static/non-mutable JexlContext used instead of null context. |
| protected Map | functions
The map of 'prefix:function' to object implementing the functions. |
| private static final float | LOAD_FACTOR
The default cache load factor. |
| protected final Log | logger
The Log to which all JexlEngine messages will be logged. |
| protected final Parser | |
| protected volatile boolean | silent
Whether expressions evaluated by this engine will throw exceptions (false) or return null (true) on errors. |
| protected final Uberspect | uberspect
The Uberspect instance. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | JexlEngine(Uberspect
to allow different introspection behaviour anUberspect, JexlArithmetic to allow different arithmetic behaviour anArithmetic, Map<String, Object> an optional map of functions (@link setFunctions) theFunctions, Log the logger for various messages log)Creates a JEXL engine using the provided |
| Modifier and Type | Method and Description |
|---|---|
| public static String | Returns: trimmed expression ending in a semi-colonexpression to clean str)Trims the expression from front & ending spaces. |
| public void | |
| protected < the key type K, the value type V> Map | Returns: a Map usable as a cache bounded to the given sizethe cache size, must be > 0 cacheSize)Creates a cache. |
| protected Expression | Returns: the script instancethe parse AST tree tree, String the script text text)An overridable through covariant return Expression creator. |
| public Expression | Returns: An Expression object which can be evaluated with a JexlContextA String containing valid JEXL syntax expression)Creates an Expression from a String containing valid JEXL syntax. |
| public Expression | Returns: An Expression object which can be evaluated with a JexlContextA String containing valid JEXL syntax expression, JexlInfo An info structure to carry debugging information if needed info)Creates an Expression from a String containing valid JEXL syntax. |
| protected JexlInfo | Returns: a JexlInfo instanceurl/file name fn, int line number l, int column number c)Creates a JexlInfo instance. |
| protected Interpreter | Returns: an Interpretera JexlContext; if null, the EMPTY_CONTEXT is used instead. context)Creates an interpreter. |
| protected Interpreter | Returns: an Interpretera JexlContext; if null, the EMPTY_CONTEXT is used instead. context, boolean whether the interpreter runs in strict mode strictFlag, boolean whether the interpreter runs in silent mode silentFlag)Creates an interpreter. |
| public Script | createScript(String
A String containing valid JEXL syntax scriptText)Creates a Script from a String containing valid JEXL syntax. |
| public Script | createScript(String
A String containing valid JEXL syntax scriptText, JexlInfo An info structure to carry debugging information if needed info)
Deprecated
Use
Creates a Script from a String containing valid JEXL syntax.
createScript(String, JexlInfo, String[])
|
| public Script | createScript(String
A String containing valid JEXL syntax scriptText, String... the script parameter names names)Creates a Script from a String containing valid JEXL syntax. |
| public Script | createScript(String
A String containing valid JEXL syntax scriptText, JexlInfo An info structure to carry debugging information if needed info, String[] the script parameter names names)Creates a Script from a String containing valid JEXL syntax. |
| protected Script | Returns: the script instancethe parse AST tree tree, String the script text text)An overridable through covariant return Script creator. |
| public Script | createScript(File
A scriptFile)File containing valid JEXL syntax.
Must not be null. Must be a readable file.Creates a Script from a |
| public Script | createScript(URL
A scriptUrl)URL containing valid JEXL syntax.
Must not be null. Must be a readable file.Creates a Script from a |
| protected JexlInfo | Returns: an Info if debug is set, null otherwiseCreates and fills up debugging information. |
| protected Object | Returns: the created object instance or null on failure when silentthe class to instantiate clazz, Object... the constructor arguments args)Creates a new instance of an object using the most appropriate constructor based on the arguments. |
| public JexlArithmetic | |
| public Map | Returns: the map passed in setFunctions or the empty map if the original was null.Retrieves the map of function namespaces. |
| protected String[] | Returns: the local variables array which may be empty (but not null) if no local variables were definedthe script script)Gets the array of local variable from a script. |
| protected String[] | Returns: the parameters which may be empty (but not null) if no parameters were definedthe script script)Gets the array of parameters from a script. |
| public Object | Returns: the value of the propertythe bean to get properties from bean, String the property expression expr)Accesses properties of a bean using an expression. |
| public Object | Returns: the value of the propertythe evaluation context context, Object the bean to get properties from bean, String the property expression expr)Accesses properties of a bean using an expression. |
| public static Uberspect | Returns: Uberspect the default uberspector instance.the logger to use for the underlying Uberspect logger)Gets the default instance of Uberspect. |
| public Uberspect | |
| public Set | Returns: the set of variables, each as a list of strings (ant-ish variables use more than 1 string) or the empty set if no variables are usedthe script script)Gets the list of variables accessed by a script. |
| protected void | |
| public Object | Returns: the method returned value or null if it failed and engine is silentthe method's invoker object obj, String the method's name meth, Object... the method's arguments args)Invokes an object's method by name and arguments. |
| public boolean | |
| public boolean | Returns: true if lenient, false if strictChecks whether this engine considers unknown variables, methods and constructors as errors. |
| public boolean | Returns: true if silent, false (default) otherwiseChecks whether this engine throws JexlException during evaluation. |
| public final boolean | Returns: true for strict, false for lenientChecks whether this engine behaves in strict or lenient mode. |
| public < the type of object T> T | Returns: the created object instance or null on failure when silentthe class to instantiate clazz, Object... the constructor arguments args)Creates a new instance of an object using the most appropriate constructor based on the arguments. |
| public Object | Returns: the created object instance or null on failure when silentthe name of the class to instantiate resolved through this engine's class loader clazz, Object... the constructor arguments args)Creates a new instance of an object using the most appropriate constructor based on the arguments. |
| protected ASTJexlScript | Returns: the parsed treethe expression to parse expression, JexlInfo debug information structure info)
Deprecated
Use
Parses an expression.
parse(CharSequence, JexlInfo, Scope) instead
|
| protected ASTJexlScript | Returns: the parsed treethe expression to parse expression, JexlInfo debug information structure info, JexlEngine.the script frame to use frameParses an expression. |
| public static String | Returns: the contents of the reader as a String.to be read. scriptReader)Read from a reader into a local buffer and return a String with the contents of the reader. |
| public void | setCache(int
if not strictly positive, no cache is used. size)Sets a cache for expressions of the defined size. |
| public void | setClassLoader(ClassLoader
the class loader to use loader)Sets the class loader used to discover classes in 'new' expressions. |
| public void | setDebug(boolean
true implies debug is on, false implies debug is off. flag)Sets whether this engine reports debugging information when error occurs. |
| public void | setFunctions(Map<String, Object>
the map of functions that should not mutate after the call; if null
is passed, the empty collection is used. funcs)Sets the map of function namespaces. |
| public void | setLenient(boolean
true means no JexlException will occur, false allows them flag)Sets whether this engine considers unknown variables, methods and constructors as errors or evaluates them as null or zero. |
| public void | setProperty(Object
the bean to set properties in bean, String the property expression expr, Object the value of the property value)Assign properties of a bean using an expression. |
| public void | setProperty(JexlContext
the evaluation context context, Object the bean to set properties in bean, String the property expression expr, Object the value of the property value)Assign properties of a bean using an expression. |
| public void | setSilent(boolean
true means no JexlException will occur, false allows them flag)Sets whether this engine throws JexlException during evaluation when an error is triggered. |
| public final void | setStrict(boolean
true for strict, false for lenient flag)Sets whether this engine behaves in strict or lenient mode. |