public abstract class JexlEngine extends Object
JexlUberspect
JexlArithmetic
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 |
---|---|
static class |
JexlEngine.EmptyContext
The empty context class, public for instrospection.
|
static class |
JexlEngine.EmptyNamespaceResolver
The empty/static/non-mutable JexlNamespace class, public for instrospection.
|
static interface |
JexlEngine.Options
Deprecated.
3.2
|
Modifier and Type | Field and Description |
---|---|
protected static ThreadLocal<JexlContext.ThreadLocal> |
CONTEXT
The thread local context.
|
static JexlFeatures |
DEFAULT_FEATURES
Default features.
|
static JexlContext |
EMPTY_CONTEXT
An empty/static/non-mutable JexlContext singleton used instead of null context.
|
static JexlContext.NamespaceResolver |
EMPTY_NS
An empty/static/non-mutable JexlNamespace singleton used instead of null namespace.
|
protected static ThreadLocal<JexlEngine> |
ENGINE
The thread local engine.
|
static Object |
TRY_FAILED
A marker singleton for invocation failures in tryInvoke.
|
Constructor and Description |
---|
JexlEngine() |
Modifier and Type | Method and Description |
---|---|
abstract void |
clearCache()
Clears the expression cache.
|
abstract JexlExpression |
createExpression(JexlInfo info,
String expression)
Creates an JexlExpression from a String containing valid JEXL syntax.
|
JexlExpression |
createExpression(String expression)
Creates a JexlExpression from a String containing valid JEXL syntax.
|
JexlInfo |
createInfo()
Create an information structure for dynamic set/get/invoke/new.
|
JexlInfo |
createInfo(String fn,
int l,
int c)
Creates a JexlInfo instance.
|
JxltEngine |
createJxltEngine()
Creates a new
JxltEngine instance using this engine. |
JxltEngine |
createJxltEngine(boolean noScript)
Creates a new
JxltEngine instance using this engine. |
abstract JxltEngine |
createJxltEngine(boolean noScript,
int cacheSize,
char immediate,
char deferred)
Creates a new instance of
JxltEngine using this engine. |
JexlScript |
createScript(File scriptFile)
Creates a Script from a
File containing valid JEXL syntax. |
JexlScript |
createScript(File scriptFile,
String... names)
Creates a Script from a
File containing valid JEXL syntax. |
abstract JexlScript |
createScript(JexlFeatures features,
JexlInfo info,
String source,
String... names)
Creates a JexlScript from a String containing valid JEXL syntax.
|
JexlScript |
createScript(JexlInfo info,
File scriptFile,
String... names)
Creates a Script from a
File containing valid JEXL syntax. |
JexlScript |
createScript(JexlInfo info,
String source,
String... names)
Creates a JexlScript from a String containing valid JEXL syntax.
|
JexlScript |
createScript(JexlInfo info,
URL scriptUrl,
String... names)
Creates a Script from a
URL containing valid JEXL syntax. |
JexlScript |
createScript(String scriptText)
Creates a Script from a String containing valid JEXL syntax.
|
JexlScript |
createScript(String source,
String... names)
Creates a Script from a String containing valid JEXL syntax.
|
JexlScript |
createScript(URL scriptUrl)
Creates a Script from a
URL containing valid JEXL syntax. |
JexlScript |
createScript(URL scriptUrl,
String... names)
Creates a Script from a
URL containing valid JEXL syntax. |
abstract JexlArithmetic |
getArithmetic()
Gets this engine underlying
JexlArithmetic . |
abstract Charset |
getCharset()
Gets the charset used for parsing.
|
abstract Object |
getProperty(JexlContext context,
Object bean,
String expr)
Accesses properties of a bean using an expression.
|
abstract Object |
getProperty(Object bean,
String expr)
Accesses properties of a bean using an expression.
|
static JexlContext.ThreadLocal |
getThreadContext()
Accesses the current thread local context.
|
static JexlEngine |
getThreadEngine()
Accesses the current thread local engine.
|
abstract JexlUberspect |
getUberspect()
Gets this engine underlying
JexlUberspect . |
abstract Object |
invokeMethod(Object obj,
String meth,
Object... args)
Invokes an object's method by name and arguments.
|
abstract boolean |
isCancellable()
Checks whether this engine will throw JexlException.Cancel (true) or return null (false) when interrupted
during an execution.
|
abstract boolean |
isDebug()
Checks whether this engine is in debug mode.
|
abstract boolean |
isSilent()
Checks whether this engine throws JexlException during evaluation.
|
abstract boolean |
isStrict()
Checks whether this engine considers unknown variables, methods, functions and constructors as errors.
|
abstract <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.
|
abstract Object |
newInstance(String clazz,
Object... args)
Creates a new instance of an object using the most appropriate constructor based on the arguments.
|
protected String |
readSource(File file)
Reads a JEXL source from a File.
|
protected String |
readSource(URL url)
Reads a JEXL source from an URL.
|
abstract void |
setClassLoader(ClassLoader loader)
Sets the class loader used to discover classes in 'new' expressions.
|
abstract void |
setProperty(JexlContext context,
Object bean,
String expr,
Object value)
Assign properties of a bean using an expression.
|
abstract void |
setProperty(Object bean,
String expr,
Object value)
Assign properties of a bean using an expression.
|
static void |
setThreadContext(JexlContext.ThreadLocal tls)
Sets the current thread local context.
|
protected static String |
toString(BufferedReader reader)
Creates a string from a reader.
|
public static final Object TRY_FAILED
protected static final ThreadLocal<JexlContext.ThreadLocal> CONTEXT
protected static final ThreadLocal<JexlEngine> ENGINE
public static final JexlFeatures DEFAULT_FEATURES
public static final JexlContext EMPTY_CONTEXT
public static final JexlContext.NamespaceResolver EMPTY_NS
public JexlEngine()
public static JexlContext.ThreadLocal getThreadContext()
public static JexlEngine getThreadEngine()
Advanced: you should only use this to retrieve the engine within a method/ctor called through the evaluation of a script/expression.
public static void setThreadContext(JexlContext.ThreadLocal tls)
This should only be used carefully, for instance when re-evaluating a "stored" script that requires a given Namespace resolver. Remember to synchronize access if context is shared between threads.
tls
- the thread local context to setpublic abstract Charset getCharset()
public abstract JexlUberspect getUberspect()
JexlUberspect
.public abstract JexlArithmetic getArithmetic()
JexlArithmetic
.public abstract boolean isDebug()
public abstract boolean isSilent()
public abstract boolean isStrict()
public abstract boolean isCancellable()
public abstract void setClassLoader(ClassLoader loader)
This method is not thread safe; it may be called after JexlEngine initialization and allow scripts to use new classes definitions.
loader
- the class loader to usepublic JxltEngine createJxltEngine()
JxltEngine
instance using this engine.public JxltEngine createJxltEngine(boolean noScript)
JxltEngine
instance using this engine.noScript
- whether the JxltEngine only allows Jexl expressions or scriptspublic abstract JxltEngine createJxltEngine(boolean noScript, int cacheSize, char immediate, char deferred)
JxltEngine
using this engine.noScript
- 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 '#'public abstract void clearCache()
public abstract JexlExpression createExpression(JexlInfo info, String expression)
info
- An info structure to carry debugging information if neededexpression
- A String containing valid JEXL syntaxJexlExpression
which can be evaluated using a JexlContext
JexlException
- if there is a problem parsing the scriptpublic final JexlExpression createExpression(String expression)
expression
- A String containing valid JEXL syntaxJexlExpression
which can be evaluated using a JexlContext
JexlException
- if there is a problem parsing the scriptpublic abstract JexlScript createScript(JexlFeatures features, JexlInfo info, String source, String... names)
features
- A set of features that will be enforced during parsinginfo
- An info structure to carry debugging information if neededsource
- 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 JexlContext
JexlException
- if there is a problem parsing the scriptpublic final JexlScript createScript(JexlInfo info, String source, String... names)
info
- An info structure to carry debugging information if neededsource
- 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 JexlContext
JexlException
- if there is a problem parsing the scriptpublic final JexlScript createScript(String scriptText)
scriptText
- A String containing valid JEXL syntaxJexlScript
which can be executed using a JexlContext
JexlException
- if there is a problem parsing the script.public final JexlScript createScript(String source, String... names)
source
- 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 JexlContext
JexlException
- if there is a problem parsing the scriptpublic final JexlScript createScript(File scriptFile)
File
containing valid JEXL syntax.
This method parses the script and validates the syntax.scriptFile
- A File
containing valid JEXL syntax. Must not be null. Must be a readable file.JexlScript
which can be executed with a JexlContext
.JexlException
- if there is a problem reading or parsing the script.public final JexlScript createScript(File scriptFile, String... names)
File
containing valid JEXL syntax.
This method parses the script and validates the syntax.scriptFile
- A File
containing valid JEXL syntax. Must not be null. Must be a readable file.names
- The script parameter names used during parsing; a corresponding array of arguments containing
values should be used during evaluation.JexlScript
which can be executed with a JexlContext
.JexlException
- if there is a problem reading or parsing the script.public final JexlScript createScript(JexlInfo info, File scriptFile, String... names)
File
containing valid JEXL syntax.
This method parses the script and validates the syntax.info
- An info structure to carry debugging information if neededscriptFile
- A File
containing valid JEXL syntax. Must not be null. Must be a readable file.names
- The script parameter names used during parsing; a corresponding array of arguments containing
values should be used during evaluation.JexlScript
which can be executed with a JexlContext
.JexlException
- if there is a problem reading or parsing the script.public final JexlScript createScript(URL scriptUrl)
URL
containing valid JEXL syntax.
This method parses the script and validates the syntax.scriptUrl
- A URL
containing valid JEXL syntax. Must not be null.JexlScript
which can be executed with a JexlContext
.JexlException
- if there is a problem reading or parsing the script.public final JexlScript createScript(URL scriptUrl, String... names)
URL
containing valid JEXL syntax.
This method parses the script and validates the syntax.scriptUrl
- A URL
containing valid JEXL syntax. Must not be null.names
- The script parameter names used during parsing; a corresponding array of arguments containing
values should be used during evaluation.JexlScript
which can be executed with a JexlContext
.JexlException
- if there is a problem reading or parsing the script.public final JexlScript createScript(JexlInfo info, URL scriptUrl, String... names)
URL
containing valid JEXL syntax.
This method parses the script and validates the syntax.info
- An info structure to carry debugging information if neededscriptUrl
- A URL
containing valid JEXL syntax. Must not be null.names
- The script parameter names used during parsing; a corresponding array of arguments containing
values should be used during evaluation.JexlScript
which can be executed with a JexlContext
.JexlException
- if there is a problem reading or parsing the script.public abstract Object getProperty(Object bean, String expr)
jexl.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.
bean
- the bean to get properties fromexpr
- the property expressionJexlException
- if there is an error parsing the expression or during evaluationpublic abstract Object getProperty(JexlContext context, Object bean, String expr)
If the JEXL engine is silent, errors will be logged through its logger as warning.
context
- the evaluation contextbean
- the bean to get properties fromexpr
- the property expressionJexlException
- if there is an error parsing the expression or during evaluationpublic abstract void setProperty(Object bean, String expr, Object value)
jexl.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.
bean
- the bean to set properties inexpr
- the property expressionvalue
- the value of the propertyJexlException
- if there is an error parsing the expression or during evaluationpublic abstract void setProperty(JexlContext context, Object bean, String expr, Object value)
If the JEXL engine is silent, errors will be logged through its logger as warning.
context
- the evaluation contextbean
- the bean to set properties inexpr
- the property expressionvalue
- the value of the propertyJexlException
- if there is an error parsing the expression or during evaluationpublic abstract Object invokeMethod(Object obj, String meth, Object... args)
obj
- the method's invoker objectmeth
- the method's nameargs
- the method's argumentsJexlException
- if method could not be found or failed and engine is not silentpublic abstract <T> T newInstance(Class<? extends T> clazz, Object... args)
T
- the type of objectclazz
- the class to instantiateargs
- the constructor argumentspublic abstract Object newInstance(String clazz, Object... args)
clazz
- the name of the class to instantiate resolved through this engine's class loaderargs
- the constructor argumentspublic JexlInfo createInfo(String fn, int l, int c)
fn
- url/file/template/script user given namel
- line numberc
- column numberpublic JexlInfo createInfo()
This gathers the class, method and line number of the first calling method outside of o.a.c.jexl3.
protected static String toString(BufferedReader reader) throws IOException
reader
- to be read.IOException
- on any error reading the reader.protected String readSource(File file)
file
- the script fileprotected String readSource(URL url)
url
- the script urlCopyright © 2001–2022 The Apache Software Foundation. All rights reserved.