org.apache.commons.el
Class ExpressionEvaluatorImpl

java.lang.Object
  |
  +--javax.servlet.jsp.el.ExpressionEvaluator
        |
        +--org.apache.commons.el.ExpressionEvaluatorImpl

public class ExpressionEvaluatorImpl
extends javax.servlet.jsp.el.ExpressionEvaluator

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: luehe $
Author:
Nathan Abramson - Art Technology Group
, Shawn Bayern

Nested Class Summary
private  class ExpressionEvaluatorImpl.JSTLExpression
          An object that encapsulates an expression to be evaluated by the JSTL evaluator.
 
Field Summary
(package private)  boolean mBypassCache
          Flag if the cache should be bypassed
(package private) static java.util.Map sCachedExpectedTypes
          The mapping from ExpectedType to Maps mapping literal String to parsed value
(package private) static java.util.Map sCachedExpressionStrings
          The mapping from expression String to its parsed form (String, Expression, or ExpressionString)
(package private) static Logger sLogger
          The static Logger
 
Constructor Summary
ExpressionEvaluatorImpl()
          Constructor
ExpressionEvaluatorImpl(boolean pBypassCache)
          Constructor
 
Method Summary
(package private) static java.lang.String addEscapes(java.lang.String str)
          Used to convert raw characters to their escaped version when these raw version cannot be used as part of an ASCII string literal.
(package private)  java.lang.Object convertStaticValueToExpectedType(java.lang.String pValue, java.lang.Class pExpectedType, Logger pLogger)
          Converts the given String, specified as a static expression string, to the given expected type.
(package private)  java.lang.Object convertToExpectedType(java.lang.Object pValue, java.lang.Class pExpectedType, Logger pLogger)
          Converts the given value to the specified expected type.
 java.lang.Object evaluate(java.lang.String pExpressionString, java.lang.Class pExpectedType, javax.servlet.jsp.el.VariableResolver pResolver, javax.servlet.jsp.el.FunctionMapper functions)
          Evaluates the given expression String
(package private)  java.lang.Object evaluate(java.lang.String pExpressionString, java.lang.Class pExpectedType, javax.servlet.jsp.el.VariableResolver pResolver, javax.servlet.jsp.el.FunctionMapper functions, Logger pLogger)
          Evaluates the given expression string
(package private) static java.lang.String formatParseException(java.lang.String pExpressionString, ParseException pExc)
          Formats a ParseException into an error message suitable for displaying on a web page
(package private) static java.util.Map getOrCreateExpectedTypeMap(java.lang.Class pExpectedType)
          Creates or returns the Map that maps string literals to parsed values for the specified expected type.
 java.lang.String parseAndRender(java.lang.String pExpressionString)
          Parses the given expression string, then converts it back to a String in its canonical form.
 javax.servlet.jsp.el.Expression parseExpression(java.lang.String expression, java.lang.Class expectedType, javax.servlet.jsp.el.FunctionMapper fMapper)
          Prepare an expression for later evaluation.
 java.lang.Object parseExpressionString(java.lang.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
 

Field Detail

sCachedExpressionStrings

static java.util.Map sCachedExpressionStrings
The mapping from expression String to its parsed form (String, Expression, or ExpressionString)


sCachedExpectedTypes

static java.util.Map sCachedExpectedTypes
The mapping from ExpectedType to Maps mapping literal String to parsed value


sLogger

static Logger sLogger
The static Logger


mBypassCache

boolean mBypassCache
Flag if the cache should be bypassed

Constructor Detail

ExpressionEvaluatorImpl

public ExpressionEvaluatorImpl()
Constructor


ExpressionEvaluatorImpl

public ExpressionEvaluatorImpl(boolean pBypassCache)
Constructor

Parameters:
pBypassCache - flag indicating if the cache should be bypassed
Method Detail

evaluate

public java.lang.Object evaluate(java.lang.String pExpressionString,
                                 java.lang.Class pExpectedType,
                                 javax.servlet.jsp.el.VariableResolver pResolver,
                                 javax.servlet.jsp.el.FunctionMapper functions)
                          throws javax.servlet.jsp.el.ELException
Evaluates the given expression String

Specified by:
evaluate in class javax.servlet.jsp.el.ExpressionEvaluator
Parameters:
pExpressionString - The expression to be evaluated.
pExpectedType - The expected type of the result of the evaluation
pResolver - A VariableResolver instance that can be used at runtime to resolve the name of implicit objects into Objects.
functions - A FunctionMapper to resolve functions found in the expression. It can be null, in which case no functions are supported for this invocation.
Returns:
the expression String evaluated to the given expected type
javax.servlet.jsp.el.ELException

parseExpression

public javax.servlet.jsp.el.Expression parseExpression(java.lang.String expression,
                                                       java.lang.Class expectedType,
                                                       javax.servlet.jsp.el.FunctionMapper fMapper)
                                                throws javax.servlet.jsp.el.ELException
Prepare an expression for later evaluation. This method should perform syntactic validation of the expression; if in doing so it detects errors, it should raise an ELParseException.

Specified by:
parseExpression in class javax.servlet.jsp.el.ExpressionEvaluator
Parameters:
expression - The expression to be evaluated.
expectedType - The expected type of the result of the evaluation
fMapper - A FunctionMapper to resolve functions found in the expression. It can be null, in which case no functions are supported for this invocation. The ExpressionEvaluator must not hold on to the FunctionMapper reference after returning from parseExpression(). The Expression object returned must invoke the same functions regardless of whether the mappings in the provided FunctionMapper instance change between calling ExpressionEvaluator.parseExpression() and Expression.evaluate().
Returns:
The Expression object encapsulating the arguments.
Throws:
javax.servlet.jsp.el.ELException - Thrown if parsing errors were found.

evaluate

java.lang.Object evaluate(java.lang.String pExpressionString,
                          java.lang.Class pExpectedType,
                          javax.servlet.jsp.el.VariableResolver pResolver,
                          javax.servlet.jsp.el.FunctionMapper functions,
                          Logger pLogger)
                    throws javax.servlet.jsp.el.ELException
Evaluates the given expression string

javax.servlet.jsp.el.ELException

parseExpressionString

public java.lang.Object parseExpressionString(java.lang.String pExpressionString)
                                       throws javax.servlet.jsp.el.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.

javax.servlet.jsp.el.ELException

convertToExpectedType

java.lang.Object convertToExpectedType(java.lang.Object pValue,
                                       java.lang.Class pExpectedType,
                                       Logger pLogger)
                                 throws javax.servlet.jsp.el.ELException
Converts the given value to the specified expected type.

javax.servlet.jsp.el.ELException

convertStaticValueToExpectedType

java.lang.Object convertStaticValueToExpectedType(java.lang.String pValue,
                                                  java.lang.Class pExpectedType,
                                                  Logger pLogger)
                                            throws javax.servlet.jsp.el.ELException
Converts the given String, specified as a static expression string, to the given expected type. The conversion is cached.

javax.servlet.jsp.el.ELException

getOrCreateExpectedTypeMap

static java.util.Map getOrCreateExpectedTypeMap(java.lang.Class pExpectedType)
Creates or returns the Map that maps string literals to parsed values for the specified expected type.


formatParseException

static java.lang.String formatParseException(java.lang.String pExpressionString,
                                             ParseException pExc)
Formats a ParseException into an error message suitable for displaying on a web page


addEscapes

static java.lang.String addEscapes(java.lang.String str)
Used to convert raw characters to their escaped version when these raw version cannot be used as part of an ASCII string literal.


parseAndRender

public java.lang.String parseAndRender(java.lang.String pExpressionString)
                                throws javax.servlet.jsp.el.ELException
Parses the given expression string, then converts it back to a String in its canonical form. This is used to test parsing.

javax.servlet.jsp.el.ELException


Copyright (c) 2001-2002 - Apache Software Foundation