##### Commons SCXML Resources

- Overview
- User Guide
  - SCXML documents
  - Using Commons SCXML
  - Standalone Testing
  - SCXML Digester
  - SCXML datamodel
  - Contexts and Evaluators
  - SCXML Engine
  - Triggering Events
  - Custom Actions
  - Custom Semantics
  - Side Effect - EL
- Javadoc
- FAQ
- Usecases
- Building
- Dependencies
- Mailing lists
- Team
- SVN repository
- Nightly snapshots

##### Project Documentation

- About
- Project Info
- Project Reports
- Development Process

##### Commons

- Home
- Components
- Sandbox
- Dormant
- Volunteering
- Contributing Patches
- Building Components
- Releasing Components
- Wiki

##### Legend

- External Link
- Opens in a new window

## Commons SCXML - Pluggable expression languages

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 `Context` and `Evaluator` interfaces 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.

### What is a Context?

The `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.

### What is a root context?

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 Javadoc.

### What is an Evaluator?

The `Evaluator` is a component with the capability of parsing and evaluating expressions. It is the "expression language engine".

## Available expression languages

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.
Check out the engine API docs on how to plug in the suitable root context and evaluator tuple.

### Commons JEXL

See org.apache.commons.scxml.env.jexl package summary for the relevant root context and evaluator tuple to use.

### Commons EL (JSP 2.0 EL)

See org.apache.commons.scxml.env.jsp package summary for the relevant root context and evaluator tuple to use.

## Method invocation in expressions

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:

### Commons JEXL

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 under name `foo` which has an accessible method `bar()`, then the JEXL expression for calling the method is `foo.bar()`

### Commons EL (JSP 2.0 EL)

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.