com.plotnix.jex
Class Interpreter

java.lang.Object
  |
  +--com.plotnix.jex.Interpreter
Direct Known Subclasses:
CompilingInterpreter, Interpreter, MultilingualInterpreter

public abstract class Interpreter
extends java.lang.Object

An interpreter directly evaluates an expression string. It validates the syntax of the expression and throws an exception if the syntax is invalid.

In order to introduce a new interpreter, create a class called "com.plotnix.jex.language-prefix.Interpreter" that inherits from this class. Jex will find the class by the language prefix and invoke it to interpret expressions in that language.

Version:
$Revision$
Author:
Dmitri Plotnikov

Constructor Summary
Interpreter()
           
 
Method Summary
abstract  void assign(Context context, java.lang.String expression, java.lang.Object value, java.lang.Object[] arguments)
          Modifies a value in the specified context according to the expression and the supplied arguments.
abstract  java.lang.Object evaluate(Context context, java.lang.String expression, java.lang.Object[] arguments)
          Evaluates the expression in the supplied context.
abstract  java.lang.Object evaluate(Context context, java.lang.String expression, java.lang.Object[] arguments, java.lang.Class valueType)
          Evaluates the expression and casts the result to the supplied type.
static Interpreter getInterpreter(java.lang.String language)
          Locates and returns an Interpreter for the specified language.
protected static Interpreter getInterpreterImplementation(java.lang.String language)
          Locates and returns an Interpreter for the specified language.
abstract  java.util.Iterator iterate(Context context, java.lang.String expression, java.lang.Object[] arguments)
          Produces the iterator described by the expression in the specified context.
 void validateExpression(java.lang.String expression)
          Checks the syntax of an expression intended for evaluation with evaluate and throws an exception if there is an error.
 void validateIterationExpression(java.lang.String expression)
          Checks the syntax of an expression intended for evaluation with iterate and throws an exception if there is an error.
 void validateVariableExpression(java.lang.String expression)
          Checks the syntax of an expression intended for evaluation with assign and throws an exception if there is an error.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Interpreter

public Interpreter()
Method Detail

getInterpreter

public static final Interpreter getInterpreter(java.lang.String language)
Locates and returns an Interpreter for the specified language. If there is not such interpreter, looks up a Compiler for this language. If one is found, returns an adapter Interpreter that makes a compiler look like an Interpreter. If neither an Interpreter nor a Compiler exist for the specified language, returns null.
Parameters:
language - is the name of an expression language (no colon at the end)
Returns:
the Interpreter for that language

getInterpreterImplementation

protected static final Interpreter getInterpreterImplementation(java.lang.String language)
Locates and returns an Interpreter for the specified language. If no Interpreter exists for the specified language, returns null.
Parameters:
language - is the name of an expression language (no colon at the end)
Returns:
the Interpreter for that language

evaluate

public abstract java.lang.Object evaluate(Context context,
                                          java.lang.String expression,
                                          java.lang.Object[] arguments)
Evaluates the expression in the supplied context.
Parameters:
context - is an evaluation context.
expression - is the expression to be evaluated
arguments - are argument of the expression. Can be null if the expression does not take any arguments.
Returns:
the result of the evaluation of this expression

evaluate

public abstract java.lang.Object evaluate(Context context,
                                          java.lang.String expression,
                                          java.lang.Object[] arguments,
                                          java.lang.Class valueType)
Evaluates the expression and casts the result to the supplied type.
See Also:
evaluate(Context, String, Object[])

iterate

public abstract java.util.Iterator iterate(Context context,
                                           java.lang.String expression,
                                           java.lang.Object[] arguments)
Produces the iterator described by the expression in the specified context.
Parameters:
context - is an evaluation context.
expression - is the expression to be evaluated
arguments - are argument of the expression. Can be null if the expression does not take any arguments.
Returns:
the result of the evaluation of this expression

assign

public abstract void assign(Context context,
                            java.lang.String expression,
                            java.lang.Object value,
                            java.lang.Object[] arguments)
Modifies a value in the specified context according to the expression and the supplied arguments. Casts the type of the value if necessary.
Parameters:
context - is an evaluation context.
expression - is the expression to be evaluated
value - is the new value
arguments - are argument of the expression. Can be null if the expression does not take any arguments.

validateExpression

public void validateExpression(java.lang.String expression)
Checks the syntax of an expression intended for evaluation with evaluate and throws an exception if there is an error.
Parameters:
expression - is the expression to be checked

validateIterationExpression

public void validateIterationExpression(java.lang.String expression)
Checks the syntax of an expression intended for evaluation with iterate and throws an exception if there is an error.
Parameters:
expression - is the expression to be checked

validateVariableExpression

public void validateVariableExpression(java.lang.String expression)
Checks the syntax of an expression intended for evaluation with assign and throws an exception if there is an error.
Parameters:
expression - is the expression to be checked


Copyright (c) 2002 - Plotnix, Inc