org.ujac.util.exi
Class ExpressionInterpreter

java.lang.Object
  extended by org.ujac.util.exi.ExpressionInterpreter
All Implemented Interfaces:
Cloneable

public class ExpressionInterpreter
extends Object
implements Cloneable

Title: ExpressionInterpreter
Description: Interpreter for expressions fitting into the following syntax.
Basically an expression consists of an object, an operation and an operand: ${object operation operand}
The operation and the operand are optional.
The object can be an expression itself, so encapsulation of expressions is possible.
Example: ${${today decrYear 1} getYear} produces a String containing the value of last year (currently 2001).

Operations can be operators as well. Supported operators are +, -, / and * for mathematical operations.
Additional there are two operators '.' and '->' which can be used to reference a property on an object.
The special thing about operators is, that they do not need to be separated from the object and the operand. So is for example the expression ${test+10} valid, in case the object test contains a numeric object.

List of currently supported operations for Date values:
incrYear: used to increment the refering date by an amount of years.
incrMonth: used to increment the refering date by an amount of months.
incrDay: used to increment the refering date by an amount of days.
decrYear: used to decrement the refering date by an amount of years.
decrMonth: used to decrement the refering date by an amount of months.
decrDay: used to decrement the refering date by an amount of days.
min: used to determine the minimum value of object and operand.
max: used to determine the maximum value of object and operand.
prevUltimo: used to determine the previous ultimo date of the refering date.
nextUltimo: used to determine the next ultimo date of the refering date.
getYear: used to fetch the year from the refering date.
getMonth: used to fetch the month from the refering date.
getDay: used to fetch the day from the refering date.
properties, accessible by reference operator:
 year: Same as getYear
 month: Same as getMonth
 day: Same as getDay

List of currently supported operations for String values:
length: used to fetch the length from the refering string.

List of currently supported operations for Integer values:
min: used to determine the minimum value of object and operand.
max: used to determine the maximum value of object and operand.
add or +: used to add the value of the operand to the object.
sub or -: used to substract the value of the operand from the object.
mul or *: used to multiply the value of the operand with the object.
div or /: used to divide the operand value from the object's value.

List of currently supported operations for Long values:
min: used to determine the minimum value of object and operand.
max: used to determine the maximum value of object and operand.
add or +: used to add the value of the operand to the object.
sub or -: used to substract the value of the operand from the object.
mul or *: used to multiply the value of the operand with the object.
div or /: used to divide the operand value from the object's value.

List of currently supported operations for Double values:
min: used to determine the minimum value of object and operand.
max: used to determine the maximum value of object and operand.
add or +: used to add the value of the operand to the object.
sub or -: used to substract the value of the operand from the object.
mul or *: used to multiply the value of the operand with the object.
div or /: used to divide the operand value from the object's value.

Author:
lauerc

Field Summary
static String ATTRIBUTE_NAME
          The attribute name to use to storer expression interpreter instances.
static Class DEFAULT_TYPE
          The name of the default type handler.
static Class[] GETTER_ARG_TYPES
          The argument type list for a getter method.
static Object[] GETTER_ARGS
          The argument list for a getter method.
static Class NULL_VALUE_TYPE
          The name of the null value type handler.
static int PS_OBJECT
          Constant for the parse state 'object'.
static int PS_OPERAND
          Constant for the parse state 'operand'.
static int PS_OPERATION
          Constant for the parse state 'operation'.
 
Constructor Summary
ExpressionInterpreter()
          Constructs an ExpressionInterpreter instance with no specific attributes.
 
Method Summary
 Object clone()
           
static ExpressionInterpreter createInstance()
          Creates an ExpressionInterpreter instance according to the registered prototype.
 boolean evalBoolean(String text, ExpressionContext ctx)
          Evaluates a text, which is likely to contain expressions as a Boolean.
 boolean evalBoolean(String text, Map params, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as a Boolean.
 boolean evalBoolean(String text, Map params, Object bean, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as a Boolean.
 boolean evalBooleanOperand(Operand operand, ExpressionContext ctx)
          Evaluates an expression as a boolean value.
 byte evalByteOperand(Operand operand, ExpressionContext ctx)
          Evaluates an expression as a byte value.
 char evalCharOperand(Operand operand, ExpressionContext ctx)
          Evaluates an expression as a char value.
 Date evalDate(String text, ExpressionContext ctx)
          Evaluates a text, which is likely to contain expressions as a Date.
 Date evalDate(String text, Map params, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as a Date.
 Date evalDate(String text, Map params, Object bean, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as a Date.
 Date evalDateOperand(Operand operand, ExpressionContext ctx, boolean useFormat)
          Evaluates an expression as a Date value.
 double evalDouble(String text, ExpressionContext ctx)
          Evaluates a text, which is likely to contain expressions as a double.
 double evalDouble(String text, Map params, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as a double.
 double evalDouble(String text, Map params, Object bean, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as a double.
 double evalDoubleOperand(Operand operand, ExpressionContext ctx, boolean useFormat)
          Evaluates an expression as a double value.
 Object evalExpr(ExpressionTuple expr, ExpressionContext ctx)
          Evaluates an expression.
 Object evalExpr(ExpressionTuple expr, Map params, Object bean, FormatHelper formatHelper)
          Evaluates an expression.
 float evalFloat(String text, ExpressionContext ctx)
          Evaluates a text, which is likely to contain expressions as a double.
 float evalFloat(String text, Map params, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as a float.
 float evalFloat(String text, Map params, Object bean, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as a double.
 float evalFloatOperand(Operand operand, ExpressionContext ctx, boolean useFormat)
          Evaluates an expression as a float value.
 int evalInt(String text, ExpressionContext ctx)
          Evaluates a text, which is likely to contain expressions as an int.
 int evalInt(String text, Map params, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as an integer.
 int evalInt(String text, Map params, Object bean, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as an int.
 int evalIntOperand(Operand operand, ExpressionContext ctx, boolean useFormat)
          Evaluates an expression as an integer value.
 long evalLong(String text, ExpressionContext ctx)
          Evaluates a text, which is likely to contain expressions as an long.
 long evalLong(String text, Map params, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as a long.
 long evalLong(String text, Map params, Object bean, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as an long.
 long evalLongOperand(Operand operand, ExpressionContext ctx, boolean useFormat)
          Evaluates an expression as a long value.
 Object evalObject(String text, ExpressionContext ctx)
          Evaluates a text, which is likely to contain expressions as an Object.
 Object evalObject(String text, Map params, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as an Object.
 Object evalObject(String text, Map params, Object bean, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as an Object.
 Object evalOperand(Operand operand, ExpressionContext ctx)
          Evaluates an operand.
 short evalShortOperand(Operand operand, ExpressionContext ctx, boolean useFormat)
          Evaluates an expression as a short value.
 String evalString(String text, ExpressionContext ctx)
          Evaluates a text, which is likely to contain expressions as a String.
 String evalString(String text, Map params, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as a String.
 String evalString(String text, Map params, Object bean, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as a String.
 String evalStringOperand(Operand operand, ExpressionContext ctx)
          Evaluates an expression as a String value.
 Time evalTime(String text, ExpressionContext ctx)
          Evaluates a text, which is likely to contain expressions as a Time.
 Time evalTime(String text, Map params, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as a Time.
 Time evalTime(String text, Map params, Object bean, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as a Time.
 Time evalTimeOperand(Operand operand, ExpressionContext ctx, boolean useFormat)
          Evaluates an expression as a Time value.
 Timestamp evalTimestamp(String text, ExpressionContext ctx)
          Evaluates a text, which is likely to contain expressions as a Time.
 Timestamp evalTimestamp(String text, Map params, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as a Timestamp.
 Timestamp evalTimestamp(String text, Map params, Object bean, FormatHelper formatHelper)
          Evaluates a text, which is likely to contain expressions as a Time.
 Timestamp evalTimestampOperand(Operand operand, ExpressionContext ctx, boolean useFormat)
          Evaluates an expression a an Timestamp value.
 String getConstantValue(String constant)
          Parses constant from given text.
 Object getParameterValue(String paramName, ExpressionContext ctx)
          Retrieves the value for the given parameter name.
protected  ExpressionType getTypeByName(String name)
          Gets the handler for the object's type by its name.
protected  ExpressionType getTypeHandler(Object object)
          Gets the handler for the object's type
protected  Collection getTypeHandlers()
          Gets all currently registered type handlers.
static void main(String[] args)
          Provides a command line tool for testing purposes.
 ExpressionTuple parseExpr(char[] expression, int offset, int lastPos)
          Parses a text, which is likely to contain expressions.
 ExpressionTuple parseExpr(String expression)
          Parses a text, which is likely to contain expressions.
 Operand parseOperand(char[] source, int position, int lastPos, boolean forceConstant)
          Parses an operand
 void registerDefaultTypeHandlers()
          Registers the default type handlers.
 void registerTypeHandler(Class typeClass, ExpressionType type)
          Registers an expression type
 void registerTypeHandler(ExpressionType type)
          Registers an expression type
static void setPrototype(ExpressionInterpreter prototype)
          Defines the expression interpreter prototype.
 void unregisterAllTypeHandlers()
          Unregisters all expression types
 void unregisterTypeHandler(Class typeClass)
          Unregisters an expression type
 void unregisterTypeHandler(ExpressionType type)
          Unregisters an expression type
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTRIBUTE_NAME

public static final String ATTRIBUTE_NAME
The attribute name to use to storer expression interpreter instances.

See Also:
Constant Field Values

PS_OBJECT

public static final int PS_OBJECT
Constant for the parse state 'object'.

See Also:
Constant Field Values

PS_OPERATION

public static final int PS_OPERATION
Constant for the parse state 'operation'.

See Also:
Constant Field Values

PS_OPERAND

public static final int PS_OPERAND
Constant for the parse state 'operand'.

See Also:
Constant Field Values

DEFAULT_TYPE

public static final Class DEFAULT_TYPE
The name of the default type handler.


NULL_VALUE_TYPE

public static final Class NULL_VALUE_TYPE
The name of the null value type handler.


GETTER_ARG_TYPES

public static final Class[] GETTER_ARG_TYPES
The argument type list for a getter method.


GETTER_ARGS

public static final Object[] GETTER_ARGS
The argument list for a getter method.

Constructor Detail

ExpressionInterpreter

public ExpressionInterpreter()
Constructs an ExpressionInterpreter instance with no specific attributes.

Method Detail

createInstance

public static ExpressionInterpreter createInstance()
Creates an ExpressionInterpreter instance according to the registered prototype.

Returns:
The created ExpressionInterpreter instance.

setPrototype

public static void setPrototype(ExpressionInterpreter prototype)
Defines the expression interpreter prototype.

Parameters:
prototype - The prototype to define.

registerTypeHandler

public void registerTypeHandler(ExpressionType type)
Registers an expression type

Parameters:
type - The new expression type.

registerTypeHandler

public void registerTypeHandler(Class typeClass,
                                ExpressionType type)
Registers an expression type

Parameters:
typeClass - The type class.
type - The new expression type.

unregisterTypeHandler

public void unregisterTypeHandler(ExpressionType type)
Unregisters an expression type

Parameters:
type - The expression type to unregister.

unregisterTypeHandler

public void unregisterTypeHandler(Class typeClass)
Unregisters an expression type

Parameters:
typeClass - The class of the expression type to unregister.

unregisterAllTypeHandlers

public void unregisterAllTypeHandlers()
Unregisters all expression types


registerDefaultTypeHandlers

public void registerDefaultTypeHandlers()
Registers the default type handlers. This method is called by the constructor.


getParameterValue

public Object getParameterValue(String paramName,
                                ExpressionContext ctx)
                         throws ExpressionException
Retrieves the value for the given parameter name.

Parameters:
paramName - The parameter name.
ctx - The expression context.
Returns:
The value that's found or null.
Throws:
ExpressionException - If the parameter could not be successfuly evaluated.

getConstantValue

public String getConstantValue(String constant)
                        throws ExpressionException
Parses constant from given text.

Parameters:
constant - The constant text.
Returns:
The extracted text.
Throws:
ExpressionException - In case a syntax error was detected.

evalString

public String evalString(String text,
                         Map params,
                         FormatHelper formatHelper)
                  throws ExpressionException
Evaluates a text, which is likely to contain expressions as a String.

Parameters:
text - The text to evaluate.
params - The parameters.
formatHelper - The format helper to use.
Returns:
The computed boolean value.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalString

public String evalString(String text,
                         Map params,
                         Object bean,
                         FormatHelper formatHelper)
                  throws ExpressionException
Evaluates a text, which is likely to contain expressions as a String.

Parameters:
text - The text to evaluate.
params - The parameters.
bean - The bean used to retrieve parameter values, if the parameter value didn't exist in the params map.
formatHelper - The format helper to use.
Returns:
The computed boolean value.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalString

public String evalString(String text,
                         ExpressionContext ctx)
                  throws ExpressionException
Evaluates a text, which is likely to contain expressions as a String.

Parameters:
text - The text to evaluate.
ctx - The expression context.
Returns:
The computed boolean value.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalBoolean

public boolean evalBoolean(String text,
                           Map params,
                           FormatHelper formatHelper)
                    throws ExpressionException
Evaluates a text, which is likely to contain expressions as a Boolean.

Parameters:
text - The text to evaluate.
params - The parameters.
formatHelper - The format helper to use.
Returns:
The computed boolean value.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalBoolean

public boolean evalBoolean(String text,
                           Map params,
                           Object bean,
                           FormatHelper formatHelper)
                    throws ExpressionException
Evaluates a text, which is likely to contain expressions as a Boolean.

Parameters:
text - The text to evaluate.
params - The parameters.
bean - The bean used to retrieve parameter values, if the parameter value didn't exist in the params map.
formatHelper - The format helper to use.
Returns:
The computed boolean value.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalBoolean

public boolean evalBoolean(String text,
                           ExpressionContext ctx)
                    throws ExpressionException
Evaluates a text, which is likely to contain expressions as a Boolean.

Parameters:
text - The text to evaluate.
ctx - The expression context.
Returns:
The computed boolean value.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalDate

public Date evalDate(String text,
                     Map params,
                     FormatHelper formatHelper)
              throws ExpressionException
Evaluates a text, which is likely to contain expressions as a Date.

Parameters:
text - The text to evaluate.
params - The parameters.
formatHelper - The format helper to use.
Returns:
The computed Date value.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalDate

public Date evalDate(String text,
                     Map params,
                     Object bean,
                     FormatHelper formatHelper)
              throws ExpressionException
Evaluates a text, which is likely to contain expressions as a Date.

Parameters:
text - The text to evaluate.
params - The parameters.
bean - The bean used to retrieve parameter values, if the parameter value didn't exist in the params map.
formatHelper - The format helper to use.
Returns:
The computed Date.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalDate

public Date evalDate(String text,
                     ExpressionContext ctx)
              throws ExpressionException
Evaluates a text, which is likely to contain expressions as a Date.

Parameters:
text - The text to evaluate.
ctx - The expression context.
Returns:
The computed Date.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalTime

public Time evalTime(String text,
                     Map params,
                     FormatHelper formatHelper)
              throws ExpressionException
Evaluates a text, which is likely to contain expressions as a Time.

Parameters:
text - The text to evaluate.
params - The parameters.
formatHelper - The format helper to use.
Returns:
The computed Time value.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalTime

public Time evalTime(String text,
                     Map params,
                     Object bean,
                     FormatHelper formatHelper)
              throws ExpressionException
Evaluates a text, which is likely to contain expressions as a Time.

Parameters:
text - The text to evaluate.
params - The parameters.
bean - The bean used to retrieve parameter values, if the parameter value didn't exist in the params map.
formatHelper - The format helper to use.
Returns:
The computed Time.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalTime

public Time evalTime(String text,
                     ExpressionContext ctx)
              throws ExpressionException
Evaluates a text, which is likely to contain expressions as a Time.

Parameters:
text - The text to evaluate.
ctx - The expression context.
Returns:
The computed Time.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalTimestamp

public Timestamp evalTimestamp(String text,
                               Map params,
                               FormatHelper formatHelper)
                        throws ExpressionException
Evaluates a text, which is likely to contain expressions as a Timestamp.

Parameters:
text - The text to evaluate.
params - The parameters.
formatHelper - The format helper to use.
Returns:
The computed Timestamp value.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalTimestamp

public Timestamp evalTimestamp(String text,
                               Map params,
                               Object bean,
                               FormatHelper formatHelper)
                        throws ExpressionException
Evaluates a text, which is likely to contain expressions as a Time.

Parameters:
text - The text to evaluate.
params - The parameters.
bean - The bean used to retrieve parameter values, if the parameter value didn't exist in the params map.
formatHelper - The format helper to use.
Returns:
The computed Timestamp.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalTimestamp

public Timestamp evalTimestamp(String text,
                               ExpressionContext ctx)
                        throws ExpressionException
Evaluates a text, which is likely to contain expressions as a Time.

Parameters:
text - The text to evaluate.
ctx - The expression context.
Returns:
The computed Timestamp.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalInt

public int evalInt(String text,
                   Map params,
                   FormatHelper formatHelper)
            throws ExpressionException
Evaluates a text, which is likely to contain expressions as an integer.

Parameters:
text - The text to evaluate.
params - The parameters.
formatHelper - The format helper to use.
Returns:
The computed integer value.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalInt

public int evalInt(String text,
                   Map params,
                   Object bean,
                   FormatHelper formatHelper)
            throws ExpressionException
Evaluates a text, which is likely to contain expressions as an int.

Parameters:
text - The text to evaluate.
params - The parameters.
bean - The bean used to retrieve parameter values, if the parameter value didn't exist in the params map.
formatHelper - The format helper to use.
Returns:
The computed int.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalInt

public int evalInt(String text,
                   ExpressionContext ctx)
            throws ExpressionException
Evaluates a text, which is likely to contain expressions as an int.

Parameters:
text - The text to evaluate.
ctx - The expression context.
Returns:
The computed int.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalLong

public long evalLong(String text,
                     Map params,
                     FormatHelper formatHelper)
              throws ExpressionException
Evaluates a text, which is likely to contain expressions as a long.

Parameters:
text - The text to evaluate.
params - The parameters.
formatHelper - The format helper to use.
Returns:
The computed long value.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalLong

public long evalLong(String text,
                     Map params,
                     Object bean,
                     FormatHelper formatHelper)
              throws ExpressionException
Evaluates a text, which is likely to contain expressions as an long.

Parameters:
text - The text to evaluate.
params - The parameters.
bean - The bean used to retrieve parameter values, if the parameter value didn't exist in the params map.
formatHelper - The format helper to use.
Returns:
The computed long.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalLong

public long evalLong(String text,
                     ExpressionContext ctx)
              throws ExpressionException
Evaluates a text, which is likely to contain expressions as an long.

Parameters:
text - The text to evaluate.
ctx - The expression context.
Returns:
The computed long.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalDouble

public double evalDouble(String text,
                         Map params,
                         FormatHelper formatHelper)
                  throws ExpressionException
Evaluates a text, which is likely to contain expressions as a double.

Parameters:
text - The text to evaluate.
params - The parameters.
formatHelper - The format helper to use.
Returns:
The computed double value.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalDouble

public double evalDouble(String text,
                         Map params,
                         Object bean,
                         FormatHelper formatHelper)
                  throws ExpressionException
Evaluates a text, which is likely to contain expressions as a double.

Parameters:
text - The text to evaluate.
params - The parameters.
bean - The bean used to retrieve parameter values, if the parameter value didn't exist in the params map.
formatHelper - The format helper to use.
Returns:
The computed double.
Throws:
ExpressionException - If the expression could not besuccessfuly resolved

evalDouble

public double evalDouble(String text,
                         ExpressionContext ctx)
                  throws ExpressionException
Evaluates a text, which is likely to contain expressions as a double.

Parameters:
text - The text to evaluate.
ctx - The expression context.
Returns:
The computed double.
Throws:
ExpressionException - If the expression could not besuccessfuly resolved

evalFloat

public float evalFloat(String text,
                       Map params,
                       FormatHelper formatHelper)
                throws ExpressionException
Evaluates a text, which is likely to contain expressions as a float.

Parameters:
text - The text to evaluate.
params - The parameters.
formatHelper - The format helper to use.
Returns:
The computed double value.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalFloat

public float evalFloat(String text,
                       Map params,
                       Object bean,
                       FormatHelper formatHelper)
                throws ExpressionException
Evaluates a text, which is likely to contain expressions as a double.

Parameters:
text - The text to evaluate.
params - The parameters.
bean - The bean used to retrieve parameter values, if the parameter value didn't exist in the params map.
formatHelper - The format helper to use.
Returns:
The computed double.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalFloat

public float evalFloat(String text,
                       ExpressionContext ctx)
                throws ExpressionException
Evaluates a text, which is likely to contain expressions as a double.

Parameters:
text - The text to evaluate.
ctx - The expression context.
Returns:
The computed double.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalObject

public Object evalObject(String text,
                         Map params,
                         FormatHelper formatHelper)
                  throws ExpressionException
Evaluates a text, which is likely to contain expressions as an Object.

Parameters:
text - The text to evaluate.
params - The parameters.
formatHelper - The format helper to use.
Returns:
The computed Object.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalObject

public Object evalObject(String text,
                         Map params,
                         Object bean,
                         FormatHelper formatHelper)
                  throws ExpressionException
Evaluates a text, which is likely to contain expressions as an Object.

Parameters:
text - The text to evaluate.
params - The parameters.
bean - The bean used to retrieve parameter values, if the parameter value didn't exist in the params map.
formatHelper - The format helper to use.
Returns:
The computed Object.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalObject

public Object evalObject(String text,
                         ExpressionContext ctx)
                  throws ExpressionException
Evaluates a text, which is likely to contain expressions as an Object.

Parameters:
text - The text to evaluate.
ctx - The expression context.
Returns:
The computed Object.
Throws:
ExpressionException - If the expression could not be successfuly resolved

parseExpr

public ExpressionTuple parseExpr(String expression)
                          throws ExpressionException
Parses a text, which is likely to contain expressions.

Parameters:
expression - The expression, to be parsed.
Returns:
The produced expression.
Throws:
ExpressionException - If the expression could not be successfuly resolved

parseExpr

public ExpressionTuple parseExpr(char[] expression,
                                 int offset,
                                 int lastPos)
                          throws ExpressionException
Parses a text, which is likely to contain expressions.

Parameters:
expression - The expression, to be parsed.
offset - The offset from which to parse the expression string.
lastPos - The last position to which to parse the expression string.
Returns:
The produced expression.
Throws:
ExpressionException - If the expression could not be successfuly resolved

parseOperand

public Operand parseOperand(char[] source,
                            int position,
                            int lastPos,
                            boolean forceConstant)
                     throws ExpressionException
Parses an operand

Parameters:
source - The source code to parse.
position - The current parse posittion.
lastPos - The last valid parse posittion.
forceConstant - In case the parsed item might be a variable name, forces the treatment as a constant.
Returns:
The position, where to continue parsing.
Throws:
ExpressionException - if the parsing failed.

evalStringOperand

public String evalStringOperand(Operand operand,
                                ExpressionContext ctx)
                         throws ExpressionException
Evaluates an expression as a String value.

Parameters:
operand - The operand to evaluate.
ctx - The expression context.
Returns:
The produced text.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalCharOperand

public char evalCharOperand(Operand operand,
                            ExpressionContext ctx)
                     throws ExpressionException
Evaluates an expression as a char value.

Parameters:
operand - The operand to evaluate.
ctx - The expression context.
Returns:
The produced result.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalBooleanOperand

public boolean evalBooleanOperand(Operand operand,
                                  ExpressionContext ctx)
                           throws ExpressionException
Evaluates an expression as a boolean value.

Parameters:
operand - The operand to evaluate.
ctx - The expression context.
Returns:
The produced result.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalByteOperand

public byte evalByteOperand(Operand operand,
                            ExpressionContext ctx)
                     throws ExpressionException
Evaluates an expression as a byte value.

Parameters:
operand - The operand to evaluate.
ctx - The expression context.
Returns:
The produced result.
Throws:
ExpressionException - If the expression could not besuccessfuly resolved

evalIntOperand

public int evalIntOperand(Operand operand,
                          ExpressionContext ctx,
                          boolean useFormat)
                   throws ExpressionException
Evaluates an expression as an integer value.

Parameters:
operand - The operand to evaluate.
ctx - The expression context.
useFormat - Tells whether the user format from the format helper shall be considered or not.
Returns:
The produced result.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalShortOperand

public short evalShortOperand(Operand operand,
                              ExpressionContext ctx,
                              boolean useFormat)
                       throws ExpressionException
Evaluates an expression as a short value.

Parameters:
operand - The operand to evaluate.
ctx - The expression context.
useFormat - Tells whether the user format from the format helper shall be considered or not.
Returns:
The produced result.
Throws:
ExpressionException - If the expression could not besuccessfuly resolved

evalLongOperand

public long evalLongOperand(Operand operand,
                            ExpressionContext ctx,
                            boolean useFormat)
                     throws ExpressionException
Evaluates an expression as a long value.

Parameters:
operand - The operand to evaluate.
ctx - The expression context.
useFormat - Tells whether the user format from the format helper shall be considered or not.
Returns:
The produced result.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalDoubleOperand

public double evalDoubleOperand(Operand operand,
                                ExpressionContext ctx,
                                boolean useFormat)
                         throws ExpressionException
Evaluates an expression as a double value.

Parameters:
operand - The operand to evaluate.
ctx - The expression context.
useFormat - Tells whether the user format from the format helper shall be considered or not.
Returns:
The produced result.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalFloatOperand

public float evalFloatOperand(Operand operand,
                              ExpressionContext ctx,
                              boolean useFormat)
                       throws ExpressionException
Evaluates an expression as a float value.

Parameters:
operand - The operand to evaluate.
ctx - The expression context.
useFormat - Tells whether the user format from the format helper shall be considered or not.
Returns:
The produced result.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalDateOperand

public Date evalDateOperand(Operand operand,
                            ExpressionContext ctx,
                            boolean useFormat)
                     throws ExpressionException
Evaluates an expression as a Date value.

Parameters:
operand - The operand to evaluate.
ctx - The expression context.
useFormat - Tells whether the user format from the format helper shall be considered or not.
Returns:
The produced result.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalTimeOperand

public Time evalTimeOperand(Operand operand,
                            ExpressionContext ctx,
                            boolean useFormat)
                     throws ExpressionException
Evaluates an expression as a Time value.

Parameters:
operand - The operand to evaluate.
ctx - The expression context.
useFormat - Tells whether the user format from the format helper shall be considered or not.
Returns:
The produced result.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalTimestampOperand

public Timestamp evalTimestampOperand(Operand operand,
                                      ExpressionContext ctx,
                                      boolean useFormat)
                               throws ExpressionException
Evaluates an expression a an Timestamp value.

Parameters:
operand - The operand to evaluate.
ctx - The expression context.
useFormat - Tells whether the user format from the format helper shall be considered or not.
Returns:
The produced result.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalOperand

public Object evalOperand(Operand operand,
                          ExpressionContext ctx)
                   throws ExpressionException
Evaluates an operand.

Parameters:
operand - The operand to evaluate.
ctx - The expression context.
Returns:
The produced text.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalExpr

public Object evalExpr(ExpressionTuple expr,
                       Map params,
                       Object bean,
                       FormatHelper formatHelper)
                throws ExpressionException
Evaluates an expression.

Parameters:
expr - The expression to evaluate.
params - The parameters.
bean - The bean used to retrieve parameter values, if the parameter value didn't exist in the params map.
formatHelper - The format helper to use.
Returns:
The produced result.
Throws:
ExpressionException - If the expression could not be successfuly resolved

evalExpr

public Object evalExpr(ExpressionTuple expr,
                       ExpressionContext ctx)
                throws ExpressionException
Evaluates an expression.

Parameters:
expr - The expression to evaluate.
ctx - The expression context.
Returns:
The produced result.
Throws:
ExpressionException - If the expression could not be successfuly resolved

getTypeHandlers

protected Collection getTypeHandlers()
Gets all currently registered type handlers.

Returns:
The currently registerd type handlers.

getTypeHandler

protected ExpressionType getTypeHandler(Object object)
Gets the handler for the object's type

Parameters:
object - The parameter object.
Returns:
The type handler for the object.

getTypeByName

protected ExpressionType getTypeByName(String name)
                                throws ExpressionException
Gets the handler for the object's type by its name.

Parameters:
name - The type name.
Returns:
The type handler for the type name.
Throws:
ExpressionException - In case no handler was found for the given type name.

main

public static void main(String[] args)
Provides a command line tool for testing purposes.

Parameters:
args - The command line attributes.

clone

public Object clone()
Overrides:
clone in class Object
See Also:
Object.clone()


Copyright © 2003-2004 UJAC.org. All Rights Reserved.