public class Engine extends JexlEngine
| Modifier and Type | Class and Description |
|---|---|
protected class |
Engine.SoftCache<K,V>
A soft referenced cache.
|
protected static class |
Engine.VarCollector
Utility class to collect variables.
|
JexlEngine.Options| Modifier and Type | Field and Description |
|---|---|
protected JexlArithmetic |
arithmetic
The
JexlArithmetic instance. |
protected Engine.SoftCache<String,ASTJexlScript> |
cache
The expression cache.
|
protected int |
cacheThreshold
The expression max length to hit the cache.
|
protected Charset |
charset
The default charset.
|
protected boolean |
debug
Whether error messages will carry debugging information.
|
protected Map<String,Object> |
functions
The map of 'prefix:function' to object implementing the namespaces.
|
protected TemplateEngine |
jxlt
The default jxlt engine.
|
protected org.apache.commons.logging.Log |
logger
The Log to which all JexlEngine messages will be logged.
|
protected Parser |
parser
The
Parser; when parsing expressions, this engine synchronizes on the parser. |
protected boolean |
silent
Whether expressions evaluated by this engine will throw exceptions (false) or return null (true) on errors.
|
protected boolean |
strict
Whether this engine considers unknown variables, methods and constructors as errors.
|
protected JexlUberspect |
uberspect
The JexlUberspect instance.
|
CONTEXT, EMPTY_CONTEXT, EMPTY_NS, TRY_FAILED| Constructor and Description |
|---|
Engine()
Creates an engine with default arguments.
|
Engine(JexlBuilder conf)
Creates a JEXL engine using the provided
JexlBuilder. |
| Modifier and Type | Method and Description |
|---|---|
void |
clearCache()
Clears the expression cache.
|
protected <K,V> Map<K,V> |
createCache(int cacheSize)
Creates a cache.
|
Script |
createExpression(JexlInfo info,
String expression)
Creates an JexlExpression from a String containing valid JEXL syntax.
|
protected Interpreter |
createInterpreter(JexlContext context,
Scope.Frame frame)
Creates an interpreter.
|
TemplateEngine |
createJxltEngine(boolean noScript,
int cacheSize,
char immediate,
char deferred)
Creates a new instance of
JxltEngine using this engine. |
Script |
createScript(JexlInfo info,
String scriptText,
String[] names)
Creates a JexlScript from a String containing valid JEXL syntax.
|
protected Object |
doCreateInstance(Object clazz,
Object... args)
Creates a new instance of an object using the most appropriate constructor
based on the arguments.
|
JexlArithmetic |
getArithmetic()
Gets this engine underlying
JexlArithmetic. |
Charset |
getCharset()
Gets the charset used for parsing.
|
protected String[] |
getLocalVariables(JexlScript script)
Gets the array of local variable from a script.
|
protected String[] |
getParameters(JexlScript script)
Gets the array of parameters from a script.
|
Object |
getProperty(JexlContext context,
Object bean,
String expr)
Accesses properties of a bean using an expression.
|
Object |
getProperty(Object bean,
String expr)
Accesses properties of a bean using an expression.
|
JexlUberspect |
getUberspect()
Gets this engine underlying
JexlUberspect. |
static Uberspect |
getUberspect(org.apache.commons.logging.Log logger,
JexlUberspect.ResolverStrategy strategy)
Gets the default instance of Uberspect.
|
protected Set<List<String>> |
getVariables(ASTJexlScript script)
Gets the list of variables accessed by a script.
|
protected void |
getVariables(ASTJexlScript script,
JexlNode node,
Engine.VarCollector collector)
Fills up the list of variables accessed by a node.
|
Object |
invokeMethod(Object obj,
String meth,
Object... args)
Invokes an object's method by name and arguments.
|
boolean |
isDebug()
Checks whether this engine is in debug mode.
|
boolean |
isSilent()
Checks whether this engine throws JexlException during evaluation.
|
boolean |
isStrict()
Checks whether the engine considers unknown variables, methods, functions and constructors as errors.
|
protected TemplateEngine |
jxlt()
Gets and/or creates a default template engine.
|
<T> T |
newInstance(Class<? extends T> clazz,
Object... args)
Creates a new instance of an object using the most appropriate constructor based on the arguments.
|
Object |
newInstance(String clazz,
Object... args)
Creates a new instance of an object using the most appropriate constructor based on the arguments.
|
protected ASTJexlScript |
parse(JexlInfo info,
String src,
Scope scope,
boolean registers,
boolean expression)
Parses an expression.
|
protected JexlContext.ThreadLocal |
putThreadLocal(JexlContext.ThreadLocal tls)
Swaps the current thread local context.
|
void |
setClassLoader(ClassLoader loader)
Sets the class loader used to discover classes in 'new' expressions.
|
void |
setProperty(JexlContext context,
Object bean,
String expr,
Object value)
Assign properties of a bean using an expression.
|
void |
setProperty(Object bean,
String expr,
Object value)
Assign properties of a bean using an expression.
|
protected String |
trimSource(CharSequence str)
Trims the source from front and ending spaces.
|
createExpression, createInfo, createInfo, createJxltEngine, createJxltEngine, createScript, createScript, createScript, createScript, createScript, createScript, createScript, createScript, getThreadContext, readSource, readSource, setThreadContext, toStringprotected final JexlUberspect uberspect
protected final JexlArithmetic arithmetic
JexlArithmetic instance.protected final org.apache.commons.logging.Log logger
protected final Parser parser
Parser; when parsing expressions, this engine synchronizes on the parser.protected final boolean strict
protected final boolean silent
protected final boolean debug
protected final Map<String,Object> functions
protected final Engine.SoftCache<String,ASTJexlScript> cache
protected final int cacheThreshold
protected final Charset charset
protected volatile TemplateEngine jxlt
public Engine()
public Engine(JexlBuilder conf)
JexlBuilder.conf - the builderpublic static Uberspect getUberspect(org.apache.commons.logging.Log logger, JexlUberspect.ResolverStrategy strategy)
This is lazily initialized to avoid building a default instance if there is no use for it. The main reason for not using the default Uberspect instance is to be able to use a (low level) introspector created with a given logger instead of the default one.
logger - the logger to use for the underlying Uberspectstrategy - the property resolver strategypublic JexlUberspect getUberspect()
JexlEngineJexlUberspect.getUberspect in class JexlEnginepublic JexlArithmetic getArithmetic()
JexlEngineJexlArithmetic.getArithmetic in class JexlEnginepublic boolean isDebug()
JexlEngineisDebug in class JexlEnginepublic boolean isSilent()
JexlEngineisSilent in class JexlEnginepublic boolean isStrict()
JexlEngineisStrict in class JexlEnginepublic void setClassLoader(ClassLoader loader)
JexlEngineThis method is not thread safe; it should be called as an optional step of the JexlEngine initialization code before expression creation & evaluation.
setClassLoader in class JexlEngineloader - the class loader to usepublic Charset getCharset()
JexlEnginegetCharset in class JexlEnginepublic TemplateEngine createJxltEngine(boolean noScript, int cacheSize, char immediate, char deferred)
JexlEngineJxltEngine using this engine.createJxltEngine in class JexlEnginenoScript - whether the JxltEngine only allows JEXL expressions or scriptscacheSize - the number of expressions in this cache, default is 256immediate - the immediate template expression character, default is '$'deferred - the deferred template expression character, default is '#'protected JexlContext.ThreadLocal putThreadLocal(JexlContext.ThreadLocal tls)
tls - the context or nullprotected <K,V> Map<K,V> createCache(int cacheSize)
K - the key typeV - the value typecacheSize - the cache size, must be > 0public void clearCache()
JexlEngineclearCache in class JexlEngineprotected Interpreter createInterpreter(JexlContext context, Scope.Frame frame)
context - a JexlContext; if null, the empty context is used instead.frame - the interpreter framepublic Script createScript(JexlInfo info, String scriptText, String[] names)
JexlEnginecreateScript in class JexlEngineinfo - An info structure to carry debugging information if neededscriptText - A string containing valid JEXL syntaxnames - The script parameter names used during parsing; a corresponding array of arguments containing
values should be used during evaluationJexlScript which can be executed using a JexlContextpublic Script createExpression(JexlInfo info, String expression)
JexlEnginecreateExpression in class JexlEngineinfo - An info structure to carry debugging information if neededexpression - A String containing valid JEXL syntaxJexlExpression which can be evaluated using a JexlContextpublic Object getProperty(Object bean, String expr)
JexlEnginejexl.get(myobject, "foo.bar"); should equate to myobject.getFoo().getBar(); (or myobject.getFoo().get("bar"))
If the JEXL engine is silent, errors will be logged through its logger as warning.
getProperty in class JexlEnginebean - the bean to get properties fromexpr - the property expressionpublic Object getProperty(JexlContext context, Object bean, String expr)
JexlEngineIf the JEXL engine is silent, errors will be logged through its logger as warning.
getProperty in class JexlEnginecontext - the evaluation contextbean - the bean to get properties fromexpr - the property expressionpublic void setProperty(Object bean, String expr, Object value)
JexlEnginejexl.set(myobject, "foo.bar", 10); should equate to myobject.getFoo().setBar(10); (or myobject.getFoo().put("bar", 10) )
If the JEXL engine is silent, errors will be logged through its logger as warning.
setProperty in class JexlEnginebean - the bean to set properties inexpr - the property expressionvalue - the value of the propertypublic void setProperty(JexlContext context, Object bean, String expr, Object value)
JexlEngineIf the JEXL engine is silent, errors will be logged through its logger as warning.
setProperty in class JexlEnginecontext - the evaluation contextbean - the bean to set properties inexpr - the property expressionvalue - the value of the propertypublic Object invokeMethod(Object obj, String meth, Object... args)
JexlEngineinvokeMethod in class JexlEngineobj - the method's invoker objectmeth - the method's nameargs - the method's argumentspublic <T> T newInstance(Class<? extends T> clazz, Object... args)
JexlEnginenewInstance in class JexlEngineT - the type of objectclazz - the class to instantiateargs - the constructor argumentspublic Object newInstance(String clazz, Object... args)
JexlEnginenewInstance in class JexlEngineclazz - the name of the class to instantiate resolved through this engine's class loaderargs - the constructor argumentsprotected Object doCreateInstance(Object clazz, Object... args)
clazz - the class to instantiateargs - the constructor argumentsprotected Set<List<String>> getVariables(ASTJexlScript script)
This method will visit all nodes of a script and extract all variables whether they are written in 'dot' or 'bracketed' notation. (a.b is equivalent to a['b']).
script - the scriptprotected void getVariables(ASTJexlScript script, JexlNode node, Engine.VarCollector collector)
script - the owning scriptnode - the nodecollector - the variable collectorprotected String[] getParameters(JexlScript script)
script - the scriptprotected String[] getLocalVariables(JexlScript script)
script - the scriptprotected ASTJexlScript parse(JexlInfo info, String src, Scope scope, boolean registers, boolean expression)
info - information structuresrc - the expression to parsescope - the script frameregisters - whether the parser should allow the unnamed '#number' syntax for 'registers'expression - whether the parser allows scripts or only expressionsJexlException - if any error occurred during parsingprotected String trimSource(CharSequence str)
str - expression to cleanprotected TemplateEngine jxlt()
Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.