The SCXML specification allows implementations to support multiple expression languages to enable using SCXML documents in varying environments. These expressions become part of attribute values for executable content, such as:
<var name="foo" expr="1 + 2 + bar" />or are used to evaluate the boolean guard conditions that decide whether or not a particular transition is followed once its associated trigger event is received, such as:
<transition event="day.close" cond="day eq 'Friday'" target="weekend" />To that end, the
Evaluatorinterfaces serve as adapters to the particular expression language APIs for a given usecase.
Variable resolution bubbles up from the current state up to the document root, similar to variable shadowing via blocks in a procedural language.
Context is a collection of variables that defines
a variable "scope". Each <state> element within an SCXML
document gets its own Context or variable scope.
The root context is the context that may be supplied to the
Commons SCXML engine as representing the variables in the
"host environment". See
SCXMLExecutor#setRootContext(Context) from the
Commons SCXML currently supports using Commons JEXL and Commons EL (JSP 2.0 EL) as the expression language. The expressions throughout the document must be homogeneous. This also applies to any external documents that may be refered by this document, for example via "src" attributes, like so:
<state id="foo" src="foo.xml"> <!-- Something, possibly very interesting, here --> </state>Here, foo.xml must use the same expression language as the document above that hosts the state foo.
See org.apache.commons.scxml.env.jexl package summary for the relevant root context and evaluator tuple to use.
See org.apache.commons.scxml.env.jsp package summary for the relevant root context and evaluator tuple to use.
Commons SCXML uses the mechanisms provided by the expression language chosen for the document to support method invocation. Commons JEXL and Commons EL allow for method invocations as follows:
See Commons JEXL reference for
builtin JEXL functions and the calling methods section of the
examples page. As a summary, if the context contains an object
foo which has an accessible method
bar(), then the JEXL expression for calling the method is
It is possible to register "namespaced" functions with the
ELEvaluator to enable method invocation. The methods need to be
static accessible methods in the class(es) that implement(s) them,
and a suitable
FunctionMapper is passed in via the
ELEvaluator constructor. For further details, see the JSP 2.0 EL API.