public class JSEvaluator extends Object implements Evaluator
Mozilla Rhino 1.6.2 does not support E4X so accessing the SCXML data model is implemented in the same way as the JEXL expression evaluator i.e. using the Data() function, for example, <assign location="Data(hotelbooking,'hotel/rooms')" expr="2" />
Modifier and Type | Class and Description |
---|---|
static class |
JSEvaluator.JSEvaluatorProvider |
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 |
---|
JSEvaluator()
Initialises the internal Javascript engine factory.
|
Modifier and Type | Method and Description |
---|---|
Object |
eval(Context context,
String expression)
Evaluates the expression using a new Javascript engine obtained from
factory instantiated in the constructor.
|
void |
evalAssign(Context ctx,
String location,
Object data,
Evaluator.AssignType type,
String attr)
Assigns data to a location
|
Boolean |
evalCond(Context context,
String expression)
Evaluates a conditional expression using the
eval() method and
casting the result to a Boolean. |
Object |
evalLocation(Context context,
String expression)
Evaluates a location expression using a new Javascript engine obtained from
factory instantiated in the constructor.
|
Object |
evalScript(Context ctx,
String script)
Executes the script using a new Javascript engine obtained from
factory instantiated in the constructor.
|
protected JSContext |
getEffectiveContext(JSContext 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
|
Context |
newContext(Context parent)
Creates a child context.
|
public static final String SUPPORTED_DATA_MODEL
public JSEvaluator()
public String getSupportedDatamodel()
Evaluator
getSupportedDatamodel
in interface Evaluator
public Context newContext(Context parent)
newContext
in interface Evaluator
parent
- parent contextpublic Object eval(Context context, String expression) throws SCXMLExpressionException
Data()
functions are replaced with an equivalent internal
Javascript function.eval
in interface Evaluator
context
- SCXML context.expression
- Expression to evaluate.null
.SCXMLExpressionException
- Thrown if the expression was invalid.public Boolean evalCond(Context context, String expression) throws SCXMLExpressionException
eval()
method and
casting the result to a Boolean.evalCond
in interface Evaluator
context
- SCXML context.expression
- Expression to evaluate.null
.SCXMLExpressionException
- Thrown if the expression was invalid or did
not return a boolean.public Object evalLocation(Context context, String expression) throws SCXMLExpressionException
Data()
functions are replaced with an equivalent internal
Javascript function.evalLocation
in interface Evaluator
context
- FSM context.expression
- Expression to evaluate.SCXMLExpressionException
- Thrown if the expression was invalid.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
Data()
functions are replaced with an equivalent internal
Javascript function.evalScript
in interface Evaluator
ctx
- SCXML context.script
- Script to execute.null
.SCXMLExpressionException
- Thrown if the script was invalid.protected JSContext getEffectiveContext(JSContext nodeCtx)
nodeCtx
- The JexlContext for this state.Copyright © 2005–2015 The Apache Software Foundation. All rights reserved.