public class JexlBuilder extends Object
The setSilent
and setStrict
methods allow to fine-tune an engine instance behavior
according to various error control needs. The strict flag tells the engine when and if null as operand is
considered an error, the silent 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 meaningful 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 and type matching.
Constructor and Description |
---|
JexlBuilder() |
Modifier and Type | Method and Description |
---|---|
boolean |
antish() |
JexlBuilder |
antish(boolean flag)
Sets whether the engine will resolve antish variable names.
|
JexlArithmetic |
arithmetic() |
JexlBuilder |
arithmetic(JexlArithmetic a)
Sets the JexlArithmetic instance the engine will use.
|
int |
cache() |
JexlBuilder |
cache(int size)
Sets the expression cache size the engine will use.
|
int |
cacheThreshold() |
JexlBuilder |
cacheThreshold(int length)
Sets the maximum length for an expression to be cached.
|
Boolean |
cancellable() |
JexlBuilder |
cancellable(boolean flag)
Sets the engine behavior upon interruption: throw an JexlException.Cancel or terminates the current evaluation
and return null.
|
Charset |
charset() |
JexlBuilder |
charset(Charset arg)
Sets the charset to use.
|
boolean |
collectAll() |
JexlBuilder |
collectAll(boolean flag)
Sets whether the engine variable collectors considers all potential forms of variable syntaxes.
|
int |
collectMode() |
JexlBuilder |
collectMode(int mode)
Experimental collector mode setter.
|
JexlEngine |
create() |
Boolean |
debug() |
JexlBuilder |
debug(boolean flag)
Sets whether the engine will report debugging information when error occurs.
|
JexlFeatures |
features() |
JexlBuilder |
features(JexlFeatures f)
Sets the features the engine will use as a base by default.
|
boolean |
lexical() |
JexlBuilder |
lexical(boolean flag)
Sets whether the engine is in lexical mode.
|
boolean |
lexicalShade() |
JexlBuilder |
lexicalShade(boolean flag)
Sets whether the engine is in lexical shading mode.
|
ClassLoader |
loader() |
JexlBuilder |
loader(Charset arg)
Deprecated.
since 3.1 use
charset(Charset) instead |
JexlBuilder |
loader(ClassLoader l)
Sets the class loader to use.
|
org.apache.commons.logging.Log |
logger() |
JexlBuilder |
logger(org.apache.commons.logging.Log log)
Sets the o.a.c.Log instance to use.
|
Map<String,Object> |
namespaces() |
JexlBuilder |
namespaces(Map<String,Object> ns)
Sets the default namespaces map the engine will use.
|
JexlOptions |
options() |
Boolean |
safe() |
JexlBuilder |
safe(boolean flag)
Sets whether the engine considers dereferencing null in navigation expressions
as errors or evaluates them as null.
|
JexlSandbox |
sandbox() |
JexlBuilder |
sandbox(JexlSandbox box)
Sets the sandbox the engine will use.
|
Boolean |
silent() |
JexlBuilder |
silent(boolean flag)
Sets whether the engine will throw JexlException during evaluation when an error is triggered.
|
int |
stackOverflow() |
JexlBuilder |
stackOverflow(int size)
Sets the number of script/expression evaluations that can be stacked.
|
JexlUberspect.ResolverStrategy |
strategy() |
JexlBuilder |
strategy(JexlUberspect.ResolverStrategy rs)
Sets the JexlUberspect strategy strategy the engine will use.
|
Boolean |
strict() |
JexlBuilder |
strict(boolean flag)
Sets whether the engine considers unknown variables, methods, functions and constructors as errors or
evaluates them as null.
|
JexlUberspect |
uberspect() |
JexlBuilder |
uberspect(JexlUberspect u)
Sets the JexlUberspect instance the engine will use.
|
public JexlBuilder uberspect(JexlUberspect u)
u
- the uberspectpublic JexlUberspect uberspect()
public JexlBuilder strategy(JexlUberspect.ResolverStrategy rs)
This is ignored if the uberspect has been set.
rs
- the strategypublic JexlUberspect.ResolverStrategy strategy()
public JexlOptions options()
public JexlBuilder arithmetic(JexlArithmetic a)
a
- the arithmeticpublic JexlArithmetic arithmetic()
public JexlBuilder sandbox(JexlSandbox box)
box
- the sandboxpublic JexlSandbox sandbox()
public JexlBuilder features(JexlFeatures f)
Note that the script flag will be ignored; the engine will be able to parse expressions and scripts.
Note also that these will apply to template expressions and scripts.
As a last remark, if lexical or lexicalShade are set as features, this method will also set the corresponding options.
f
- the featurespublic JexlFeatures features()
public JexlBuilder logger(org.apache.commons.logging.Log log)
log
- the loggerpublic org.apache.commons.logging.Log logger()
public JexlBuilder loader(ClassLoader l)
l
- the class loaderpublic ClassLoader loader()
@Deprecated public JexlBuilder loader(Charset arg)
charset(Charset)
insteadarg
- the charsetpublic JexlBuilder charset(Charset arg)
arg
- the charsetpublic Charset charset()
public JexlBuilder antish(boolean flag)
flag
- true means antish resolution is enabled, false disables itpublic boolean antish()
public JexlBuilder lexical(boolean flag)
flag
- true means lexical function scope is in effect, false implies non-lexical scopingpublic boolean lexical()
public JexlBuilder lexicalShade(boolean flag)
flag
- true means lexical shading is in effect, false implies no lexical shadingpublic boolean lexicalShade()
public JexlBuilder silent(boolean flag)
flag
- true means no JexlException will occur, false allows thempublic Boolean silent()
public JexlBuilder strict(boolean flag)
flag
- true means strict error reporting, false allows them to be evaluated as nullpublic Boolean strict()
public JexlBuilder safe(boolean flag)
x.y()
if x is null throws an exception when not safe,
return null and warns if it is.
flag
- true means safe navigation, false throws exception when dereferencing nullpublic Boolean safe()
public JexlBuilder debug(boolean flag)
flag
- true implies debug is on, false implies debug is off.public Boolean debug()
public JexlBuilder cancellable(boolean flag)
flag
- true implies the engine throws the exception, false makes the engine return null.public Boolean cancellable()
public JexlBuilder collectAll(boolean flag)
flag
- true means var collections considers constant array accesses equivalent to dotted referencespublic JexlBuilder collectMode(int mode)
mode
- 0 or 1 as equivalents to false and true, other values are experimentalpublic boolean collectAll()
public int collectMode()
public JexlBuilder namespaces(Map<String,Object> ns)
Each entry key is used as a prefix, each entry value used as a bean implementing methods; an expression like 'nsx:method(123)' will thus be solved by looking at a registered bean named 'nsx' that implements method 'method' in that map. If all methods are static, you may use the bean class instead of an instance as value.
If the entry value is a class that has one constructor taking a JexlContext as argument, an instance of the namespace will be created at evaluation time. It might be a good idea to derive a JexlContext to carry the information used by the namespace to avoid variable space pollution and strongly type the constructor with this specialized JexlContext.
The key or prefix allows to retrieve the bean that plays the role of the namespace. If the prefix is null, the namespace is the top-level namespace allowing to define top-level user defined namespaces ( ie: myfunc(...) )
Note that the JexlContext is also used to try to solve top-level namespaces. This allows ObjectContext derived instances to call methods on the wrapped object.
ns
- the map of namespacespublic JexlBuilder cache(int size)
The cache will contain at most size
expressions of at most cacheThreshold
length.
Note that all JEXL caches are held through SoftReferences and may be garbage-collected.
size
- if not strictly positive, no cache is used.public int cache()
public JexlBuilder cacheThreshold(int length)
Expression whose length is greater than this expression cache length threshold will bypass the cache.
It is expected that a "long" script will be parsed once and its reference kept around in user-space structures; the jexl expression cache has no added-value in this case.
length
- if not strictly positive, the value is silently replaced by the default value (64).public int cacheThreshold()
public JexlBuilder stackOverflow(int size)
size
- if not strictly positive, limit is reached when java StackOverflow is thrown.public int stackOverflow()
public JexlEngine create()
JexlEngine
instanceCopyright © 2001–2021 The Apache Software Foundation. All rights reserved.