## org.apache.taglibs.standard.lang.jstl
Class ELEvaluator

    java.lang.Object
      org.apache.taglibs.standard.lang.jstl.ELEvaluator

    public class ELEvaluator

extends Object

This is the main class for evaluating expression Strings. An expression String is a String that may contain expressions of the form ${...}. Multiple expressions may appear in the same expression String. In such a case, the expression String's value is computed by concatenating the String values of those evaluated expressions and any intervening non-expression text, then converting the resulting String to the expected type using the PropertyEditor mechanism.

In the special case where the expression String is a single expression, the value of the expression String is determined by evaluating the expression, without any intervening conversion to a String.

The evaluator maintains a cache mapping expression Strings to their parsed results. For expression Strings containing no expression elements, it maintains a cache mapping ExpectedType/ExpressionString to parsed value, so that static expression Strings won't have to go through a conversion step every time they are used. All instances of the evaluator share the same cache. The cache may be bypassed by setting a flag on the evaluator's constructor.

The evaluator must be passed a VariableResolver in its constructor. The VariableResolver is used to resolve variable names encountered in expressions, and can also be used to implement "implicit objects" that are always present in the namespace. Different applications will have different policies for variable lookups and implicit objects - these differences can be encapsulated in the VariableResolver passed to the evaluator's constructor.

Most VariableResolvers will need to perform their resolution against some context. For example, a JSP environment needs a PageContext to resolve variables. The evaluate() method takes a generic Object context which is eventually passed to the VariableResolver - the VariableResolver is responsible for casting the context to the proper type.

Once an evaluator instance has been constructed, it may be used multiple times, and may be used by multiple simultaneous Threads. In other words, an evaluator instance is well-suited for use as a singleton.

Version:
  $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: tcfujii $
Author:
  Nathan Abramson - Art Technology Group, Shawn Bayern

Constructor Summary
`ELEvaluator(VariableResolver pResolver)` Constructor
`ELEvaluator(VariableResolver pResolver, boolean pBypassCache)` Constructor

Method Summary
`Object` `evaluate(String pExpressionString, Object pContext, Class pExpectedType, Map functions, String defaultPrefix)` Evaluates the given expression String
`String` `parseAndRender(String pExpressionString)` Parses the given expression string, then converts it back to a String in its canonical form.
`Object` `parseExpressionString(String pExpressionString)` Gets the parsed form of the given expression string.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ELEvaluator

    public ELEvaluator(VariableResolver pResolver)

  Constructor

  Parameters:
    `pResolver` - the object that should be used to resolve variable names encountered in expressions. If null, all variable references will resolve to null.

### ELEvaluator

    public ELEvaluator(VariableResolver pResolver,
                       boolean pBypassCache)

  Constructor

  Parameters:
    `pResolver` - the object that should be used to resolve variable names encountered in expressions. If null, all variable references will resolve to null.
    `pBypassCache` - flag indicating if the cache should be bypassed

Method Detail

### evaluate

    public Object evaluate(String pExpressionString,
                           Object pContext,
                           Class pExpectedType,
                           Map functions,
                           String defaultPrefix)
                    throws ELException

  Evaluates the given expression String

  Parameters:
    `pExpressionString` - the expression String to be evaluated
    `pContext` - the context passed to the VariableResolver for resolving variable names
    `pExpectedType` - the type to which the evaluated expression should be coerced
  Returns:
    the expression String evaluated to the given expected type
  Throws:
    `ELException`

### parseExpressionString

    public Object parseExpressionString(String pExpressionString)
                                 throws ELException

  Gets the parsed form of the given expression string. If the parsed form is cached (and caching is not bypassed), return the cached form, otherwise parse and cache the value. Returns either a String, Expression, or ExpressionString.

  Throws:
    `ELException`

### parseAndRender

    public String parseAndRender(String pExpressionString)
                          throws ELException

  Parses the given expression string, then converts it back to a String in its canonical form. This is used to test parsing.

  Throws:
    `ELException`

Copyright © 2008 Mort Bay Consulting. All Rights Reserved.