Simple Context

Class de.odysseus.el.util.SimpleContext is a simple context implementation. It can be used at creation time as well as evaluation time.

For use at creation time, it provides the following methods.

The following example defines function math:sin and variable pi and uses them in an expression.

import javax.el.*;
import de.odysseus.el.util.SimpleContext;
import de.odysseus.el.ExpressionFactoryImpl;
ExpressionFactory factory = new ExpressionFactoryImpl();
SimpleContext context = new SimpleContext();
context.setFunction("math", "sin", Math.class.getMethod("sin", double.class));
context.setVariable("pi", factory.createValueExpression(Math.PI, double.class));
ValueExpression expr = factory.createValueExpression(context, "${math:sin(pi/2)}", double.class);
System.out.println("math:sin(pi/2) = " + expr.getValue(context)); // 1.0

At evaluation time, a javax.el.ELResolver is required for property resolution and to resolve identifiers, that have not been bound to a variable. The getELResolver() method is used at evaluation time to access the context's resolver instance.

A resolver may be passed to a SimpleContext at construction time. If the default constructor is used, calling getELResolver() will lazily create an instance of de.odysseus.el.util.SimpleResolver.