org.apache.commons.jexl
Class ExpressionImpl

java.lang.Object
  extended by org.apache.commons.jexl.ExpressionImpl
All Implemented Interfaces:
Expression

 class ExpressionImpl
extends java.lang.Object
implements Expression

Instances of ExpressionImpl are created by the ExpressionFactory, and this is the default implementation of the Expression interface.

Since:
1.0
Version:
$Id: ExpressionImpl.java 397111 2006-04-26 06:47:52Z dion $
Author:
Geir Magnusson Jr.

Field Summary
protected  java.lang.String expression
          Original expression.
protected  SimpleNode node
          The resulting AST we can call value() on.
protected  java.util.List postResolvers
          resolvers called after expression evaluation.
protected  java.util.List preResolvers
          resolvers called before expression evaluation.
 
Constructor Summary
ExpressionImpl(java.lang.String expr, SimpleNode ref)
          do not let this be generally instantiated with a 'new'.
 
Method Summary
 void addPostResolver(JexlExprResolver resolver)
          Allows addition of a resolver to allow custom interdiction of expression evaluation.
 void addPreResolver(JexlExprResolver resolver)
          Allows addition of a resolver to allow custom interdiction of expression evaluation.
 java.lang.Object evaluate(JexlContext context)
          Evaluates the expression with the variables contained in the supplied JexlContext.
 java.lang.String getExpression()
          Returns the JEXL expression this Expression was created with.
 java.lang.String toString()
          Provide a string representation of the expression.
protected  java.lang.Object tryResolver(java.util.List resolverList, JexlContext context)
          Tries the resolvers in the given resolverlist against the context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

preResolvers

protected java.util.List preResolvers
resolvers called before expression evaluation.


postResolvers

protected java.util.List postResolvers
resolvers called after expression evaluation.


expression

protected java.lang.String expression
Original expression. This is just a 'snippet', not a valid statement (i.e. foo.bar() vs foo.bar();


node

protected SimpleNode node
The resulting AST we can call value() on.

Constructor Detail

ExpressionImpl

ExpressionImpl(java.lang.String expr,
               SimpleNode ref)
do not let this be generally instantiated with a 'new'.

Parameters:
expr - the expression.
ref - the parsed expression.
Method Detail

evaluate

public java.lang.Object evaluate(JexlContext context)
                          throws java.lang.Exception
Evaluates the expression with the variables contained in the supplied JexlContext.

Specified by:
evaluate in interface Expression
Parameters:
context - A JexlContext containing variables.
Returns:
The result of this evaluation
Throws:
java.lang.Exception - on any error

tryResolver

protected java.lang.Object tryResolver(java.util.List resolverList,
                                       JexlContext context)
Tries the resolvers in the given resolverlist against the context.

Parameters:
resolverList - list of JexlExprResolvers
context - JexlContext to use for evauluation
Returns:
value (including null) or JexlExprResolver.NO_VALUE

getExpression

public java.lang.String getExpression()
Returns the JEXL expression this Expression was created with.

Specified by:
getExpression in interface Expression
Returns:
The JEXL expression to be evaluated

addPreResolver

public void addPreResolver(JexlExprResolver resolver)
Allows addition of a resolver to allow custom interdiction of expression evaluation.

Specified by:
addPreResolver in interface Expression
Parameters:
resolver - resolver to be called before Jexl expression evaluated

addPostResolver

public void addPostResolver(JexlExprResolver resolver)
Allows addition of a resolver to allow custom interdiction of expression evaluation.

Specified by:
addPostResolver in interface Expression
Parameters:
resolver - resolver to be called if Jexl expression evaluated to null.

toString

public java.lang.String toString()
Provide a string representation of the expression.

Overrides:
toString in class java.lang.Object
Returns:
the expression or blank if it's null.