Top Description Inners Fields Constructors Methods
org.apache.commons.jexl2

public final Class UnifiedJEXL

extends Object
Class Inheritance
Imports
java.io.BufferedReader, .IOException, .Reader, .StringReader, .Writer, java.util.ArrayList, .Collections, .LinkedHashSet, .List, .Set, org.apache.commons.jexl2.introspection.JexlMethod, .Uberspect, org.apache.commons.jexl2.parser.ASTJexlScript, .JexlNode, .StringParser

An evaluator similar to the Unified EL evaluator used in JSP/JSF based on JEXL. It is intended to be used in configuration modules, XML based frameworks or JSP taglibs and facilitate the implementation of expression evaluation.

An expression can mix immediate, deferred and nested sub-expressions as well as string constants;

Deferred & immediate expression carry different intentions:

For instance: "Hello ${name}, now is #{time}" is a composite "deferred" expression since one of its subexpressions is deferred. Furthermore, this (composite) expression intent is to perform two evaluations; one close to its definition and another one in a later phase.

The API reflects this feature in 2 methods, prepare and evaluate. The prepare method will evaluate the immediate subexpression and return an expression that contains only the deferred subexpressions (& constants), a prepared expression. Such a prepared expression is suitable for a later phase evaluation that may occur with a different JexlContext. Note that it is valid to call evaluate without prepare in which case the same JexlContext is used for the 2 evaluation phases.

In the most common use-case where deferred expressions are to be kept around as properties of objects, one should parse & prepare an expression before storing it and evaluate it each time the property storing it is accessed.

Note that nested expression use the JEXL syntax as in: "#{${bar}+'.charAt(2)'}" The most common mistake leading to an invalid expression being the following: "#{${bar}charAt(2)}"

Also note that methods that parse evaluate expressions may throw unchecked exceptions; The UnifiedJEXL.Exception are thrown when the engine instance is in "non-silent" mode but since these are RuntimeException, user-code should catch them where appropriate.

Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
UnifiedJEXL.BlockType

The enum capturing the difference between verbatim and code source fragments.

private class
UnifiedJEXL.CompositeExpression

A composite expression: "...

private class
UnifiedJEXL.ConstantExpression

A constant expression.

private class
UnifiedJEXL.DeferredExpression

A deferred expression: #{jexl}.

public static class
UnifiedJEXL.Exception

The sole type of (runtime) exception the UnifiedJEXL can throw.

public abstract class
UnifiedJEXL.Expression

The abstract base class for all expressions, immediate '${...}' and deferred '#{...}'.

private static class
UnifiedJEXL.ExpressionBuilder

A helper class to build expressions.

private static enum
UnifiedJEXL.ExpressionType

Types of expressions.

private class
UnifiedJEXL.ImmediateExpression

An immediate expression: ${jexl}.

private abstract class
UnifiedJEXL.JexlBasedExpression

The base for Jexl based expressions.

private class
UnifiedJEXL.NestedExpression

An immediate expression nested into a deferred expression.

private static enum
UnifiedJEXL.ParseState

The different parsing states.

public class
UnifiedJEXL.Template

A Template is a script that evaluates by writing its content through a Writer.

private static class
UnifiedJEXL.TemplateBlock

Abstract the source fragments, verbatim or immediate typed text blocks.

public class
UnifiedJEXL.TemplateContext

The type of context to use during evaluation of templates.

Field Summary

Modifier and TypeField and Description
private final JexlEngine.SoftCache<String, UnifiedJEXL.Expression>
cache

The expression cache.

private static final int
CACHE_SIZE

The default cache size.

private static final char
DEF_CHAR

The first character for deferred expressions.

private static final char
IMM_CHAR

The first character for immediate expressions.

private final JexlEngine
jexl

The JEXL engine instance.

Constructor Summary

AccessConstructor and Description
public
UnifiedJEXL(JexlEngine
the JexlEngine to use.
aJexl
)

Creates a new instance of UnifiedJEXL with a default size cache.

public
UnifiedJEXL(JexlEngine
the JexlEngine to use.
aJexl
,
int
the number of expressions in this cache
cacheSize
)

Creates a new instance of UnifiedJEXL creating a local cache.

Method Summary

Modifier and TypeMethod and Description
public void
clearCache()

Clears the cache.

private UnifiedJEXL.Exception

Returns:

an exception containing an explicit error message
createException
(String
parse, prepare, evaluate
action
,
UnifiedJEXL.Expression
the expression
expr
,
Exception
the exception
xany
)

Creates a UnifiedJEXL.Exception from a JexlException.

public UnifiedJEXL.Template

Returns:

the template
createTemplate
(String
the directive prefix
prefix
,
Reader
the source
source
,
String...
the parameter names
parms
)

Creates a new template.

public UnifiedJEXL.Template

Returns:

the template
createTemplate
(String
the source
source
,
String...
the parameter names
parms
)

Creates a new template.

public UnifiedJEXL.Template

Returns:

the template
createTemplate
(String
the source
source
)

Creates a new template.

public JexlEngine

Returns:

the JexlEngine
getEngine
()

Gets the JexlEngine underlying the UnifiedJEXL.

public UnifiedJEXL.Expression

Returns:

the UnifiedJEXL object expression, null if silent and an error occured
parse
(String
the UnifiedJEXL string expression
expression
)

Creates a a UnifiedJEXL.Expression from an expression string.

private UnifiedJEXL.Expression

Returns:

the expression instance
parseExpression
(String
the string expression
expr
,
JexlEngine.Scope
the expression scope
scope
)

Parses a unified expression.

protected List<UnifiedJEXL.TemplateBlock>

Returns:

the list of blocks
readTemplate
(final String
the directive prefix
prefix
,
Reader
the source reader
source
)

Reads lines of a template grouping them by typed blocks.

protected int

Returns:

the first position after end of pattern if it matches, -1 otherwise
startsWith
(CharSequence
the sequence
sequence
,
CharSequence
the pattern to match at start of sequence
pattern
)

Whether a sequence starts with a given set of characters (following spaces).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait