blob: 9774543d18efa9ea0a79f896074d1a0a85f74b1e [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!--
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<document>
<properties>
<title>Commons SCXML Usage - API notes - EL</title>
<author email="dev@commons.apache.org">Commons Documentation Team</author>
</properties>
<body>
<section name="Commons SCXML - Trying out EL without the servlet container">
<p>Someone asked about Commons EL:<br/>
&quot;<i>Is there no way to test this stuff outside of a Servlet/JSP
container?</i>&quot;</p>
<p>Commons SCXML supports EL as an expression language that may be used
within the expressions in an SCXML document. As a side-effect, a simple
API may be available for anyone who has the need to test without wanting
to deal with a Servlet/JSP container. <i>We understand this has limited
use.</i>
</p>
<p>To test an expression language implementation, one minimally needs a
context of evaluation and an evaluator, which gives us the following
usage:</p>
<pre>
//import org.apache.commons.scxml.Context;
//import org.apache.commons.scxml.Evaluator;
//import org.apache.commons.scxml.SCXMLExpressionException;
//import org.apache.commons.scxml.env.jsp.ELContext;
//import org.apache.commons.scxml.env.jsp.ELEvaluator;
Context context = new ELContext();
// Say we have an instance 'foo' of type Foo which
// has a property 'bar' of type String
context.set("foo", foo);
Evaluator evaluator = new ELEvaluator();
String bar = null;
try {
bar = (String) evaluator.eval(context, "${foo.bar}");
} catch (SCXMLExpressionException see) {
// Commons SCXML wraps the underlying exception,
// in this case, a javax.servlet.jsp.el.ELException
}
</pre>
</section>
</body>
</document>