http://www.eteks.com

com.eteks.jeks
Class JeksExpressionParser

java.lang.Object
  |
  +--com.eteks.parser.Parser
        |
        +--com.eteks.parser.FunctionParser
              |
              +--com.eteks.parser.ExpressionParser
                    |
                    +--com.eteks.jeks.JeksExpressionParser

public class JeksExpressionParser
extends ExpressionParser

Parser for expressions entered in table cells. This parser stores the interpreter used to compute expressions at runtime and the functions entered by user and available for expressions.
This class provides also methods used to shift cells in expressions.

Since:
Jeks 1.0
Version:
1.0
Author:
Emmanuel Puybaret

Constructor Summary
JeksExpressionParser(JeksExpressionSyntax syntax, ExpressionParameter expressionParameter, Interpreter interpreter)
          Creates an expression parser with no user function parser.
JeksExpressionParser(JeksExpressionSyntax syntax, ExpressionParameter expressionParameter, Interpreter interpreter, JeksFunctionParser functionParser, java.util.Vector userFunctions)
          Creates an expression parser.
JeksExpressionParser(javax.swing.table.TableModel tableModel)
          Creates an expression parser from the table model tableModel, using instances of JeksExpressionSyntax and of JeksFunctionSyntax for expression and function syntaxes, an instance of JeksInterpreter as interpreter and an instance of JeksParameter as expression parameter.
 
Method Summary
 void addUserFunction(Function userFunction)
          Add the user function userFunction to the expression and function syntaxes of this parser.
 CompiledExpression compileExpression(java.lang.String expressionDefinition)
          Parses and compiles the expression definition expressionDefinition and returns an instance of JeksExpression.
 java.lang.Object getEditedValue(java.lang.Object value)
          Returns value as an editable object.
 JeksFunctionParser getFunctionParser()
          Returns the parser used to parse user functions.
 Interpreter getInterpreter()
          Returns the interpreter of this parser.
 java.lang.Object getModelValue(java.lang.String data)
          Returns an object of the same wrapping class as the string data.
 java.util.Vector getUserFunctions()
          Returns a copy of the user functions set.
 java.lang.Object parseLitteral(java.lang.String data)
          Returns an object of the same wrapping class as the string data.
 void removeAllUserFunctions()
          Remove all the user functions from the expression and function syntaxes of this parser.
 void removeUserFunction(Function userFunction)
          Remove the user function userFunction from the expression and function syntaxes of this parser.
 java.lang.String shiftExpression(CompiledExpression expression, int rowShift, int columnShift)
          Shifts the cells used in the definition of expression of rowShift rows and columnShift columns and returns the shifted definition.
 java.lang.String shiftExpression(CompiledExpression expression, int rowShift, int columnShift, int cellSetFirstRow, int cellSetFirstColumn, int cellSetLastRow, int cellSetLastColumn)
          Shifts the cells used in the definition of expression of rowShift rows and columnShift columns and returns the shifted expression.
 
Methods inherited from class com.eteks.parser.ExpressionParser
getExpressionParameter
 
Methods inherited from class com.eteks.parser.FunctionParser
compileFunction, getSyntax
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JeksExpressionParser

public JeksExpressionParser(javax.swing.table.TableModel tableModel)
Creates an expression parser from the table model tableModel, using instances of JeksExpressionSyntax and of JeksFunctionSyntax for expression and function syntaxes, an instance of JeksInterpreter as interpreter and an instance of JeksParameter as expression parameter.

JeksExpressionParser

public JeksExpressionParser(JeksExpressionSyntax syntax,
                            ExpressionParameter expressionParameter,
                            Interpreter interpreter)
Creates an expression parser with no user function parser.

JeksExpressionParser

public JeksExpressionParser(JeksExpressionSyntax syntax,
                            ExpressionParameter expressionParameter,
                            Interpreter interpreter,
                            JeksFunctionParser functionParser,
                            java.util.Vector userFunctions)
Creates an expression parser.
Method Detail

compileExpression

public CompiledExpression compileExpression(java.lang.String expressionDefinition)
                                     throws CompilationException
Parses and compiles the expression definition expressionDefinition and returns an instance of JeksExpression.
Overrides:
compileExpression in class ExpressionParser
Following copied from class: com.eteks.parser.ExpressionParser
Parameters:
expressionDefinition - the definition of the expression.
Returns:
an instance of CompiledExpression, with which values can be computed.
Throws:
CompilationException - if the syntax of the expression is incorrect or if some of its elements (literals, constants, operators, functions,...) are not accepted by the syntax of the parser.

getInterpreter

public Interpreter getInterpreter()
Returns the interpreter of this parser.

getFunctionParser

public JeksFunctionParser getFunctionParser()
Returns the parser used to parse user functions.

getUserFunctions

public java.util.Vector getUserFunctions()
Returns a copy of the user functions set.

addUserFunction

public void addUserFunction(Function userFunction)
Add the user function userFunction to the expression and function syntaxes of this parser.

removeUserFunction

public void removeUserFunction(Function userFunction)
Remove the user function userFunction from the expression and function syntaxes of this parser.

removeAllUserFunctions

public void removeAllUserFunctions()
Remove all the user functions from the expression and function syntaxes of this parser.

getEditedValue

public java.lang.Object getEditedValue(java.lang.Object value)
Returns value as an editable object. If value is an instance of JeksExpression the definition of the expression is returned, if value is a number or a date its localized string representation is returned, otherwise the object value itself is returned.
Parameters:
value - a value stored in the table model.

getModelValue

public java.lang.Object getModelValue(java.lang.String data)
                               throws CompilationException
Returns an object of the same wrapping class as the string data. This method tries to create an instance of one of the following classes in this order: Long, Double, Date, Boolean or the string itself. If the string starts with an assignment operator (equal sign =), it tries to compile the expression to create a JeksExpression instance.
Parameters:
data - a string.
Returns:
an instance of either classes : Long, Double, Date, Boolean, String or JeksExpression.

parseLitteral

public java.lang.Object parseLitteral(java.lang.String data)
Returns an object of the same wrapping class as the string data. This method tries to create an instance of one of the following classes in this order: Long, Double, Date, Boolean. If it fails it returns the string itself.
Parameters:
data - a string.
Returns:
an instance of either classes : Long, Double, Date, Boolean or String.

shiftExpression

public java.lang.String shiftExpression(CompiledExpression expression,
                                        int rowShift,
                                        int columnShift)
Shifts the cells used in the definition of expression of rowShift rows and columnShift columns and returns the shifted definition. Columns and rows prefixed by the character returned by the getConstantChar () method are unchanged. The string returned by getCellError (JeksExpressionSyntax.ERROR_ILLEGAL_CELL) of expression syntax replaces any shifted cell with a negative column or row.
This method is used to shift copied expressions during a copy / paste operation.

shiftExpression

public java.lang.String shiftExpression(CompiledExpression expression,
                                        int rowShift,
                                        int columnShift,
                                        int cellSetFirstRow,
                                        int cellSetFirstColumn,
                                        int cellSetLastRow,
                                        int cellSetLastColumn)
Shifts the cells used in the definition of expression of rowShift rows and columnShift columns and returns the shifted expression. The only cells which are shifted in the returned definition are the ones belonging to the cells set defined by the opposite cells (cellSetFirstRow, cellSetFirstColumn) and (cellSetLastRow, cellSetLastColumn). Columns and rows are shifted even if they are prefixed by the constant character. This method is used to shift cut expressions and their referring cells during a cut / paste operation.

&cp; 1998-2003 eTeks - All rights reserved