Simple Resolver

JUEL provides the de.odysseus.el.util.SimpleResolver class for use as a simple resolver, suitable to resolve top-level identifiers and to delegate to another resolver provided at construction time.

If no resolver delegate is supplied, a composite resolver will be used as default, capable of resolving bean properties, array values, list values, resource values and map values.

A resolver is made to resolve properties. It operates on a pair of objects, called base and property. JUEL's simple resolver maintains a map to directly resolve top-level properties, that is base == null. Resolution for base/property pairs with base != null is delegated.

Finally, a simple resolver may also be flagged as "read-only". In this case, invoking the setValue(ELContext, Object, Object, Object) method will throw an exception.

import java.util.Date;
import javax.el.*;
import de.odysseus.el.util.SimpleContext;
import de.odysseus.el.util.SimpleResolver;
import de.odysseus.el.ExpressionFactoryImpl;
ExpressionFactory factory = new ExpressionFactoryImpl();
SimpleContext context = new SimpleContext(new SimpleResolver());

// resolve top-level property
factory.createValueExpression(context, "#{pi}", double.class).setValue(context, Math.PI);
ValueExpression expr1 = factory.createValueExpression(context, "${pi/2}", double.class);
System.out.println("pi/2 = " + expr1.getValue(context)); // 1.5707963...

// resolve bean property
factory.createValueExpression(context, "#{current}", Date.class).setValue(context, new Date());
ValueExpression expr2 = factory.createValueExpression(context, "${current.time}", long.class);
System.out.println("current.time = " + expr2.getValue(context));