org.apache.beehive.netui.script
Interface ExpressionEvaluator


public interface ExpressionEvaluator

Interface for implementing a runtime for evaluating expressions. An ExpressionEvaluator is used to execute read and update expressions. It also provides a set of methods for performing utility type operations on expressions.


Method Summary
 String changeContext(String expression, String oldContext, String newContext, int lookupIndex)
          Change the evaluation context of an expression.
 boolean containsExpression(String expression)
          Checks to see if a particular expression contains an expression.
 Object evaluateStrict(String expression, VariableResolver variableResolver)
          Evaluate an expression and return the result.
 boolean isExpression(String expression)
          Checks to see if a particular String is exactly an expression.
 Expression parseExpression(String expression)
          Parse an expression into its object representation as a Expression.
 String qualify(String implicitObjectName, String expression)
          Qualify the expression into the given context.
 void update(String expression, Object value, VariableResolver variableResolver, boolean requestParameter)
          Update an expression with the given value.
 

Method Detail

evaluateStrict

Object evaluateStrict(String expression,
                      VariableResolver variableResolver)
                      throws ExpressionEvaluationException
Evaluate an expression and return the result.

Parameters:
expression - the expression to evaluate
variableResolver - the set of contexts that may be used in expression evaluation. This set is not necessarily complete as some objects that can be used as top-level expression contexts may be contained within an object available in this JavaBean.
Throws:
ExpressionEvaluationException - when an error occurs

update

void update(String expression,
            Object value,
            VariableResolver variableResolver,
            boolean requestParameter)
            throws ExpressionUpdateException
Update an expression with the given value. This will apply the parameter value to the object referenced by the expression expression. The requestParameter flag is used by a caller to restrict the set of contexts into which an update can occur on the request.

Parameters:
expression - the expression whose value to update
value - the new value for the update
variableResolver - the set of contexts that may be used in expression evaluation. This set is not necessarily complete as some objects that can be used as top-level expression contexts may be contained within an object available in this JavaBean.
requestParameter - a boolean that marks this update as occurring from data in the request, if true or simply as a regular update.
Throws:
ExpressionUpdateException - when an exception occurs updating a value

changeContext

String changeContext(String expression,
                     String oldContext,
                     String newContext,
                     int lookupIndex)
                     throws ExpressionEvaluationException
Change the evaluation context of an expression. This is used to rewrite some expressions that need to be qualified into a different context for evaluation. The context of an expression is its first identifier, up to the first delimiter.

Parameters:
expression - the expression whose context to change
oldContext - the old context to replace, if present
newContext - the new context to replace if the expression starts with the oldContext
lookupIndex - an index used to qualify an expression into an array look-up.
Throws:
ExpressionEvaluationException

qualify

String qualify(String implicitObjectName,
               String expression)
               throws ExpressionEvaluationException
Qualify the expression into the given context. This will take the expression and simply qualify it into the new context implicitObjectName.

Parameters:
implicitObjectName - the new context
expression - the expression to qualify
Returns:
the new expression created by adding the implicit object name implicitObjectName to the expression string expression
Throws:
ExpressionEvaluationException - if an exception occurs qualifying the expression with the implict object name

isExpression

boolean isExpression(String expression)
Checks to see if a particular String is exactly an expression.

Parameters:
expression - the expression to check
Returns:
true if the expression is exactly an expression; false otherwise.
Throws:
IllegalExpressionException - if the given expression expression is not legal.

containsExpression

boolean containsExpression(String expression)
Checks to see if a particular expression contains an expression. This method will return true if there is an expression surrounded by whitespace, other expressions, or literal text.

Parameters:
expression - the expression to check
Returns:
true if the expression contains an expression; false otherwise.

parseExpression

Expression parseExpression(String expression)
Parse an expression into its object representation as a Expression.

Parameters:
expression - the String expression to parse
Returns:
the parsed expression