public class JexlEvaluator extends Object implements Evaluator, Serializable
This implementation itself is thread-safe, so you can keep singleton
for efficiency of the internal JexlEngine
member.
Modifier and Type | Class and Description |
---|---|
static class |
JexlEvaluator.JexlEvaluatorProvider |
Evaluator.AssignType
Modifier and Type | Field and Description |
---|---|
static String |
SUPPORTED_DATA_MODEL |
DEFAULT_DATA_MODEL, ECMASCRIPT_DATA_MODEL, NULL_DATA_MODEL, XPATH_DATA_MODEL
Constructor and Description |
---|
JexlEvaluator()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected org.apache.commons.jexl2.JexlEngine |
createJexlEngine()
Create the internal JexlEngine member during the initialization.
|
Object |
eval(Context ctx,
String expr)
Evaluate an expression.
|
void |
evalAssign(Context ctx,
String location,
Object data,
Evaluator.AssignType type,
String attr)
Assigns data to a location
|
Boolean |
evalCond(Context ctx,
String expr)
Evaluate a condition.
|
Object |
evalLocation(Context ctx,
String expr)
Evaluate a location that returns a data assignable reference or list of references.
|
Object |
evalScript(Context ctx,
String script)
Evaluate a script.
|
protected JexlContext |
getEffectiveContext(JexlContext nodeCtx)
Create a new context which is the summation of contexts from the
current state to document root, child has priority over parent
in scoping rules.
|
String |
getSupportedDatamodel()
Get the datamodel type supported by this Evaluator
|
boolean |
isJexlEngineSilent()
Checks whether the internal Jexl engine throws JexlException during evaluation.
|
boolean |
isJexlEngineStrict()
Checks whether the internal Jexl engine behaves in strict or lenient mode.
|
Context |
newContext(Context parent)
Create a new child context.
|
void |
setJexlEngineSilent(boolean silent)
Delegate method for
JexlEngine.setSilent(boolean) to set whether the engine throws JexlException during
evaluation when an error is triggered. |
void |
setJexlEngineStrict(boolean strict)
Delegate method for
JexlEngine.setStrict(boolean) to set whether it behaves in strict or lenient mode. |
public static final String SUPPORTED_DATA_MODEL
public JexlEvaluator()
public boolean isJexlEngineSilent()
public void setJexlEngineSilent(boolean silent)
JexlEngine.setSilent(boolean)
to set whether the engine throws JexlException during
evaluation when an error is triggered.
This method should be called as an optional step of the JexlEngine initialization code before expression creation & evaluation.
silent
- true means no JexlException will occur, false allows thempublic boolean isJexlEngineStrict()
public void setJexlEngineStrict(boolean strict)
JexlEngine.setStrict(boolean)
to set whether it behaves in strict or lenient mode.
This method is should be called as an optional step of the JexlEngine initialization code before expression creation & evaluation.
strict
- true for strict, false for lenientpublic String getSupportedDatamodel()
Evaluator
getSupportedDatamodel
in interface Evaluator
public Object eval(Context ctx, String expr) throws SCXMLExpressionException
eval
in interface Evaluator
ctx
- variable contextexpr
- expressionSCXMLExpressionException
- For a malformed expressionEvaluator.eval(Context, String)
public Boolean evalCond(Context ctx, String expr) throws SCXMLExpressionException
Evaluator
evalCond
in interface Evaluator
ctx
- variable contextexpr
- expressionSCXMLExpressionException
- A malformed expression exceptionEvaluator.evalCond(Context, String)
public Object evalLocation(Context ctx, String expr) throws SCXMLExpressionException
Evaluator
evalLocation
in interface Evaluator
ctx
- variable contextexpr
- expressionSCXMLExpressionException
- A malformed expression exceptionEvaluator.evalLocation(Context, String)
public void evalAssign(Context ctx, String location, Object data, Evaluator.AssignType type, String attr) throws SCXMLExpressionException
Evaluator
evalAssign
in interface Evaluator
ctx
- variable contextlocation
- location expressiondata
- the data to assign.type
- the type of assignment to perform, null assumes Evaluator.AssignType.REPLACE_CHILDREN
attr
- the name of the attribute to add when using type Evaluator.AssignType.ADD_ATTRIBUTE
SCXMLExpressionException
- A malformed expression exceptionEvaluator.evalAssign(Context, String, Object, AssignType, String)
public Object evalScript(Context ctx, String script) throws SCXMLExpressionException
Evaluator
evalScript
in interface Evaluator
ctx
- variable contextscript
- The scriptSCXMLExpressionException
- A malformed scriptEvaluator.evalScript(Context, String)
public Context newContext(Context parent)
newContext
in interface Evaluator
parent
- parent contextEvaluator.newContext(Context)
protected org.apache.commons.jexl2.JexlEngine createJexlEngine()
protected JexlContext getEffectiveContext(JexlContext nodeCtx)
nodeCtx
- The JexlContext for this state.Copyright © 2005–2015 The Apache Software Foundation. All rights reserved.