Class JexlEngine
- Introspection, see JexlUberspect
- Arithmetic and comparison, see JexlArithmetic
- Error reporting
- Logging
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.
- Since:
- 2.0
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic final classThe empty context class, public for instrospection.static final classThe empty/static/non-mutable JexlNamespace class, public for instrospection.static interfaceDeprecated.3.2
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected static final ThreadLocal<JexlContext.ThreadLocal> The thread local context.static final JexlFeaturesDefault features.static final JexlContextAn empty/static/non-mutable JexlContext singleton used instead of null context.static final JexlContext.NamespaceResolverAn empty/static/non-mutable JexlNamespace singleton used instead of null namespace.protected static final ThreadLocal<JexlEngine> The thread local engine.static final ObjectA marker singleton for invocation failures in tryInvoke.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionabstract voidClears the expression cache.final JexlExpressioncreateExpression(String expression) Creates a JexlExpression from a String containing valid JEXL syntax.abstract JexlExpressioncreateExpression(JexlInfo info, String expression) Creates an JexlExpression from a String containing valid JEXL syntax.Create an information structure for dynamic set/get/invoke/new.createInfo(String fn, int l, int c) Creates a JexlInfo instance.Creates a newJxltEngineinstance using this engine.createJxltEngine(boolean noScript) Creates a newJxltEngineinstance using this engine.abstract JxltEnginecreateJxltEngine(boolean noScript, int cacheSize, char immediate, char deferred) Creates a new instance ofJxltEngineusing this engine.final JexlScriptcreateScript(File scriptFile) Creates a Script from aFilecontaining valid JEXL syntax.final JexlScriptcreateScript(File scriptFile, String... names) Creates a Script from aFilecontaining valid JEXL syntax.final JexlScriptcreateScript(String scriptText) Creates a Script from a String containing valid JEXL syntax.final JexlScriptcreateScript(String source, String... names) Creates a Script from a String containing valid JEXL syntax.final JexlScriptcreateScript(URL scriptUrl) Creates a Script from aURLcontaining valid JEXL syntax.final JexlScriptcreateScript(URL scriptUrl, String... names) Creates a Script from aURLcontaining valid JEXL syntax.abstract JexlScriptcreateScript(JexlFeatures features, JexlInfo info, String source, String... names) Creates a JexlScript from a String containing valid JEXL syntax.final JexlScriptcreateScript(JexlInfo info, File scriptFile, String... names) Creates a Script from aFilecontaining valid JEXL syntax.final JexlScriptcreateScript(JexlInfo info, String source, String... names) Creates a JexlScript from a String containing valid JEXL syntax.final JexlScriptcreateScript(JexlInfo info, URL scriptUrl, String... names) Creates a Script from aURLcontaining valid JEXL syntax.abstract JexlArithmeticGets this engine underlyingJexlArithmetic.abstract CharsetGets the charset used for parsing.abstract ObjectgetProperty(Object bean, String expr) Accesses properties of a bean using an expression.abstract ObjectgetProperty(JexlContext context, Object bean, String expr) Accesses properties of a bean using an expression.static JexlContext.ThreadLocalAccesses the current thread local context.static JexlEngineAccesses the current thread local engine.abstract JexlUberspectGets this engine underlyingJexlUberspect.abstract ObjectinvokeMethod(Object obj, String meth, Object... args) Invokes an object's method by name and arguments.abstract booleanChecks whether this engine will throw JexlException.Cancel (true) or return null (false) when interrupted during an execution.abstract booleanisDebug()Checks whether this engine is in debug mode.abstract booleanisSilent()Checks whether this engine throws JexlException during evaluation.abstract booleanisStrict()Checks whether this engine considers unknown variables, methods, functions and constructors as errors.abstract <T> TnewInstance(Class<? extends T> clazz, Object... args) Creates a new instance of an object using the most appropriate constructor based on the arguments.abstract ObjectnewInstance(String clazz, Object... args) Creates a new instance of an object using the most appropriate constructor based on the arguments.protected StringreadSource(File file) Reads a JEXL source from a File.protected StringreadSource(URL url) Reads a JEXL source from an URL.abstract voidsetClassLoader(ClassLoader loader) Sets the class loader used to discover classes in 'new' expressions.abstract voidsetProperty(Object bean, String expr, Object value) Assign properties of a bean using an expression.abstract voidsetProperty(JexlContext context, Object bean, String expr, Object value) Assign properties of a bean using an expression.static voidSets the current thread local context.protected static StringtoString(BufferedReader reader) Creates a string from a reader.
- 
Field Details- 
TRY_FAILEDA marker singleton for invocation failures in tryInvoke.
- 
CONTEXTThe thread local context.
- 
ENGINEThe thread local engine.
- 
DEFAULT_FEATURESDefault features.
- 
EMPTY_CONTEXTAn empty/static/non-mutable JexlContext singleton used instead of null context.
- 
EMPTY_NSAn empty/static/non-mutable JexlNamespace singleton used instead of null namespace.
 
- 
- 
Constructor Details- 
JexlEnginepublic JexlEngine()Default constructor
 
- 
- 
Method Details- 
getThreadContextAccesses the current thread local context.- Returns:
- the context or null
 
- 
getThreadEngineAccesses the current thread local engine.Advanced: you should only use this to retrieve the engine within a method/ctor called through the evaluation of a script/expression. - Returns:
- the engine or null
 
- 
setThreadContextSets the current thread local context.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. - Parameters:
- tls- the thread local context to set
 
- 
toStringCreates a string from a reader.- Parameters:
- reader- to be read.
- Returns:
- the contents of the reader as a String.
- Throws:
- IOException- on any error reading the reader.
 
- 
clearCacheClears the expression cache.
- 
createExpressionCreates an JexlExpression from a String containing valid JEXL syntax. This method parses the expression which must contain either a reference or an expression.- Parameters:
- info- An info structure to carry debugging information if needed
- expression- A String containing valid JEXL syntax
- Returns:
- An JexlExpressionwhich can be evaluated using aJexlContext
- Throws:
- JexlException- if there is a problem parsing the script
 
- 
createExpressionCreates a JexlExpression from a String containing valid JEXL syntax. This method parses the expression which must contain either a reference or an expression.- Parameters:
- expression- A String containing valid JEXL syntax
- Returns:
- An JexlExpressionwhich can be evaluated using aJexlContext
- Throws:
- JexlException- if there is a problem parsing the script
 
- 
createInfoCreate an information structure for dynamic set/get/invoke/new.This gathers the class, method and line number of the first calling method outside of o.a.c.jexl3. - Returns:
- a JexlInfo instance
 
- 
createInfoCreates a JexlInfo instance.- Parameters:
- fn- url/file/template/script user given name
- l- line number
- c- column number
- Returns:
- a JexlInfo instance
 
- 
createJxltEngineCreates a newJxltEngineinstance using this engine.- Returns:
- a JEXL Template engine
 
- 
createJxltEngineCreates a newJxltEngineinstance using this engine.- Parameters:
- noScript- whether the JxltEngine only allows Jexl expressions or scripts
- Returns:
- a JEXL Template engine
 
- 
createJxltEnginepublic abstract JxltEngine createJxltEngine(boolean noScript, int cacheSize, char immediate, char deferred) Creates a new instance ofJxltEngineusing this engine.- Parameters:
- noScript- whether the JxltEngine only allows JEXL expressions or scripts
- cacheSize- the number of expressions in this cache, default is 256
- immediate- the immediate template expression character, default is '$'
- deferred- the deferred template expression character, default is '#'
- Returns:
- a JEXL Template engine
 
- 
createScriptCreates a Script from aFilecontaining valid JEXL syntax. This method parses the script and validates the syntax.- Parameters:
- scriptFile- A- Filecontaining valid JEXL syntax. Must not be null. Must be a readable file.
- Returns:
- A JexlScriptwhich can be executed with aJexlContext.
- Throws:
- JexlException- if there is a problem reading or parsing the script.
 
- 
createScriptCreates a Script from aFilecontaining valid JEXL syntax. This method parses the script and validates the syntax.- Parameters:
- scriptFile- A- Filecontaining 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.
- Returns:
- A JexlScriptwhich can be executed with aJexlContext.
- Throws:
- JexlException- if there is a problem reading or parsing the script.
 
- 
createScriptpublic abstract JexlScript createScript(JexlFeatures features, JexlInfo info, String source, String... names) Creates a JexlScript from a String containing valid JEXL syntax. This method parses the script and validates the syntax.- Parameters:
- features- A set of features that will be enforced during parsing
- info- An info structure to carry debugging information if needed
- source- A string containing valid JEXL syntax
- names- The script parameter names used during parsing; a corresponding array of arguments containing values should be used during evaluation
- Returns:
- A JexlScriptwhich can be executed using aJexlContext
- Throws:
- JexlException- if there is a problem parsing the script
 
- 
createScriptCreates a Script from aFilecontaining valid JEXL syntax. This method parses the script and validates the syntax.- Parameters:
- info- An info structure to carry debugging information if needed
- scriptFile- A- Filecontaining 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.
- Returns:
- A JexlScriptwhich can be executed with aJexlContext.
- Throws:
- JexlException- if there is a problem reading or parsing the script.
 
- 
createScriptCreates a JexlScript from a String containing valid JEXL syntax. This method parses the script and validates the syntax.- Parameters:
- info- An info structure to carry debugging information if needed
- source- A string containing valid JEXL syntax
- names- The script parameter names used during parsing; a corresponding array of arguments containing values should be used during evaluation
- Returns:
- A JexlScriptwhich can be executed using aJexlContext
- Throws:
- JexlException- if there is a problem parsing the script
 
- 
createScriptCreates a Script from aURLcontaining valid JEXL syntax. This method parses the script and validates the syntax.- Parameters:
- info- An info structure to carry debugging information if needed
- scriptUrl- A- URLcontaining 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.
- Returns:
- A JexlScriptwhich can be executed with aJexlContext.
- Throws:
- JexlException- if there is a problem reading or parsing the script.
 
- 
createScriptCreates a Script from a String containing valid JEXL syntax. This method parses the script and validates the syntax.- Parameters:
- scriptText- A String containing valid JEXL syntax
- Returns:
- A JexlScriptwhich can be executed using aJexlContext
- Throws:
- JexlException- if there is a problem parsing the script.
 
- 
createScriptCreates a Script from a String containing valid JEXL syntax. This method parses the script and validates the syntax.- Parameters:
- source- A String containing valid JEXL syntax
- names- The script parameter names used during parsing; a corresponding array of arguments containing values should be used during evaluation
- Returns:
- A JexlScriptwhich can be executed using aJexlContext
- Throws:
- JexlException- if there is a problem parsing the script
 
- 
createScriptCreates a Script from aURLcontaining valid JEXL syntax. This method parses the script and validates the syntax.- Parameters:
- scriptUrl- A- URLcontaining valid JEXL syntax. Must not be null.
- Returns:
- A JexlScriptwhich can be executed with aJexlContext.
- Throws:
- JexlException- if there is a problem reading or parsing the script.
 
- 
createScriptCreates a Script from aURLcontaining valid JEXL syntax. This method parses the script and validates the syntax.- Parameters:
- scriptUrl- A- URLcontaining 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.
- Returns:
- A JexlScriptwhich can be executed with aJexlContext.
- Throws:
- JexlException- if there is a problem reading or parsing the script.
 
- 
getArithmeticGets this engine underlyingJexlArithmetic.- Returns:
- the arithmetic
 
- 
getCharsetGets the charset used for parsing.- Returns:
- the charset
 
- 
getPropertyAccesses properties of a bean using an expression.If the JEXL engine is silent, errors will be logged through its logger as warning. - Parameters:
- context- the evaluation context
- bean- the bean to get properties from
- expr- the property expression
- Returns:
- the value of the property
- Throws:
- JexlException- if there is an error parsing the expression or during evaluation
 
- 
getPropertyAccesses properties of a bean using an expression.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. - Parameters:
- bean- the bean to get properties from
- expr- the property expression
- Returns:
- the value of the property
- Throws:
- JexlException- if there is an error parsing the expression or during evaluation
 
- 
getUberspectGets this engine underlyingJexlUberspect.- Returns:
- the uberspect
 
- 
invokeMethodInvokes an object's method by name and arguments.- Parameters:
- obj- the method's invoker object
- meth- the method's name
- args- the method's arguments
- Returns:
- the method returned value or null if it failed and engine is silent
- Throws:
- JexlException- if method could not be found or failed and engine is not silent
 
- 
isCancellableChecks whether this engine will throw JexlException.Cancel (true) or return null (false) when interrupted during an execution.- Returns:
- true if cancellable, false otherwise
 
- 
isDebugChecks whether this engine is in debug mode.- Returns:
- true if debug is on, false otherwise
 
- 
isSilentChecks whether this engine throws JexlException during evaluation.- Returns:
- true if silent, false (default) otherwise
 
- 
isStrictChecks whether this engine considers unknown variables, methods, functions and constructors as errors.- Returns:
- true if strict, false otherwise
 
- 
newInstanceCreates a new instance of an object using the most appropriate constructor based on the arguments.- Type Parameters:
- T- the type of object
- Parameters:
- clazz- the class to instantiate
- args- the constructor arguments
- Returns:
- the created object instance or null on failure when silent
 
- 
newInstanceCreates a new instance of an object using the most appropriate constructor based on the arguments.- Parameters:
- clazz- the name of the class to instantiate resolved through this engine's class loader
- args- the constructor arguments
- Returns:
- the created object instance or null on failure when silent
 
- 
readSourceReads a JEXL source from a File.- Parameters:
- file- the script file
- Returns:
- the source
 
- 
readSourceReads a JEXL source from an URL.- Parameters:
- url- the script url
- Returns:
- the source
 
- 
setClassLoaderSets the class loader used to discover classes in 'new' expressions.This method is not thread safe; it may be called after JexlEngine initialization and allow scripts to use new classes definitions. - Parameters:
- loader- the class loader to use
 
- 
setPropertyAssign properties of a bean using an expression.If the JEXL engine is silent, errors will be logged through its logger as warning. - Parameters:
- context- the evaluation context
- bean- the bean to set properties in
- expr- the property expression
- value- the value of the property
- Throws:
- JexlException- if there is an error parsing the expression or during evaluation
 
- 
setPropertyAssign properties of a bean using an expression.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. - Parameters:
- bean- the bean to set properties in
- expr- the property expression
- value- the value of the property
- Throws:
- JexlException- if there is an error parsing the expression or during evaluation
 
 
-