com.gentics.api.lib.expressionparser.functions
Interface Function


public interface Function

Interface for functions. All parts of a parsed expression are implemented as "functions" ("and", "or", "==", ...), not only the named expression functions. A "named" function is something like "concat(...), isempty(...), ..." in the expression.
Any implementation of this interface must be stateless and threadsafe.


Field Summary
static String[] FUNCTIONTYPE_NAMES
          constant of the function type names
static int[] NAMEDFUNCTION
          type constant for a namedfunction.
static int TYPE_ADD
          constant for binary "+" operations
static int TYPE_AND
          constant for boolean "and" operation
static int TYPE_CONTAINSALL
          constant for "containsall" comparisons
static int TYPE_CONTAINSNONE
          constant for "containsnone" comparisons
static int TYPE_CONTAINSONEOF
          constant for "containsoneof" comparisons
static int TYPE_DIV
          constant for binary "/" operations
static int TYPE_EQUAL
          constant for "equals" comparisons
static int TYPE_GREATER
          constant for "greater" comparisons
static int TYPE_GREATEROREQUAL
          constant for "greater or equal" comparisons
static int TYPE_LIKE
          constant for "like" comparisons
static int TYPE_MINUS
          constant for unary "-" operations
static int TYPE_MOD
          constant for binary "%" operations
static int TYPE_MULT
          constant for binary "*" operations
static int TYPE_NAMEDFUNCTION
          constant for "named functions"
static int TYPE_NOT
          constant for unary "!" operations
static int TYPE_OR
          constant for boolean "and" operation
static int TYPE_PLUS
          constant for unary "+" operations
static int TYPE_SMALLER
          constant for "smaller" comparisons
static int TYPE_SMALLEROREQUAL
          constant for "smaller or equal" comparisons
static int TYPE_SUB
          constant for binary "-" operations
static int TYPE_UNEQUAL
          constant for "unequal" comparisons
static int TYPE_UNKNOWN
          constant for unknown function type (this must always be the highest index)
static int UNBOUNDED
          constant for unbounded number of operands
 
Method Summary
 Object evaluate(int functionType, ExpressionQueryRequest request, EvaluableExpression[] operand, int expectedValueType)
          Static evaluation of the function.
The functionType is one of (TYPE_ADD, TYPE_AND, TYPE_CONTAINSNONE, TYPE_CONTAINSNONE, TYPE_DIV, TYPE_EQUAL, TYPE_GREATER, TYPE_GREATEROREQUAL, TYPE_LIKE, TYPE_MINUS, TYPE_MOD, TYPE_MULT, TYPE_NAMEDFUNCTION, TYPE_NOT, TYPE_OR, TYPE_PLUS, TYPE_SMALLER, TYPE_SMALLEROREQUAL, TYPE_SUB, TYPE_UNEQUAL) and will always be one of the types returned by getTypes().
The expectedValueType is one of (ExpressionEvaluator.OBJECTTYPE_ANY, ExpressionEvaluator.OBJECTTYPE_BOOLEAN, ExpressionEvaluator.OBJECTTYPE_COLLECTION, ExpressionEvaluator.OBJECTTYPE_DATE, ExpressionEvaluator.OBJECTTYPE_NULL, ExpressionEvaluator.OBJECTTYPE_NUMBER, ExpressionEvaluator.OBJECTTYPE_STRING), where ExpressionEvaluator.OBJECTTYPE_ANY shall be used when any value type is acceptable.
Implementations must respect the expected value type and must throw a EvaluationException when it cannot generate a value of this type.
 void generateFilterPart(int functionType, ExpressionQueryRequest request, FilterPart filterPart, EvaluableExpression[] operand, int expectedValueType)
          Generate the filter part for the function.
The functionType is one of (TYPE_ADD, TYPE_AND, TYPE_CONTAINSNONE, TYPE_CONTAINSNONE, TYPE_DIV, TYPE_EQUAL, TYPE_GREATER, TYPE_GREATEROREQUAL, TYPE_LIKE, TYPE_MINUS, TYPE_MOD, TYPE_MULT, TYPE_NAMEDFUNCTION, TYPE_NOT, TYPE_OR, TYPE_PLUS, TYPE_SMALLER, TYPE_SMALLEROREQUAL, TYPE_SUB, TYPE_UNEQUAL) and will always be one of the types returned by getTypes().
The expectedValueType is one of (ExpressionEvaluator.OBJECTTYPE_ANY, ExpressionEvaluator.OBJECTTYPE_BOOLEAN, ExpressionEvaluator.OBJECTTYPE_COLLECTION, ExpressionEvaluator.OBJECTTYPE_DATE, ExpressionEvaluator.OBJECTTYPE_NULL, ExpressionEvaluator.OBJECTTYPE_NUMBER, ExpressionEvaluator.OBJECTTYPE_STRING), where ExpressionEvaluator.OBJECTTYPE_ANY shall be used when any value type is acceptable.
Implementations must respect the expected value type and must throw a FilterGeneratorException when it cannot generate a value of this type.
 int getExpectedValueType(int functionType)
          Get the value type which this expression is expected to return
 int getMaxParameters()
          Get maximum number of parameters.
 int getMinParameters()
          Get minimum number of parameters.
 String getName()
          Get the name of the function.
 Class[] getSupportedDatasourceClasses()
          Get the array of supported datasource classes for this function.
 int[] getTypes()
          Get the types of the function.
 boolean supportStaticEvaluation()
          Check whether the function supports static evaluation (calls to evaluate(int, ExpressionQueryRequest, EvaluableExpression[], int) without a given datasource).
 

Field Detail

NAMEDFUNCTION

static final int[] NAMEDFUNCTION
type constant for a namedfunction.


UNBOUNDED

static final int UNBOUNDED
constant for unbounded number of operands

See Also:
Constant Field Values

TYPE_NAMEDFUNCTION

static final int TYPE_NAMEDFUNCTION
constant for "named functions"

See Also:
Constant Field Values

TYPE_AND

static final int TYPE_AND
constant for boolean "and" operation

See Also:
Constant Field Values

TYPE_OR

static final int TYPE_OR
constant for boolean "and" operation

See Also:
Constant Field Values

TYPE_EQUAL

static final int TYPE_EQUAL
constant for "equals" comparisons

See Also:
Constant Field Values

TYPE_SMALLER

static final int TYPE_SMALLER
constant for "smaller" comparisons

See Also:
Constant Field Values

TYPE_SMALLEROREQUAL

static final int TYPE_SMALLEROREQUAL
constant for "smaller or equal" comparisons

See Also:
Constant Field Values

TYPE_GREATEROREQUAL

static final int TYPE_GREATEROREQUAL
constant for "greater or equal" comparisons

See Also:
Constant Field Values

TYPE_GREATER

static final int TYPE_GREATER
constant for "greater" comparisons

See Also:
Constant Field Values

TYPE_UNEQUAL

static final int TYPE_UNEQUAL
constant for "unequal" comparisons

See Also:
Constant Field Values

TYPE_CONTAINSONEOF

static final int TYPE_CONTAINSONEOF
constant for "containsoneof" comparisons

See Also:
Constant Field Values

TYPE_CONTAINSNONE

static final int TYPE_CONTAINSNONE
constant for "containsnone" comparisons

See Also:
Constant Field Values

TYPE_LIKE

static final int TYPE_LIKE
constant for "like" comparisons

See Also:
Constant Field Values

TYPE_ADD

static final int TYPE_ADD
constant for binary "+" operations

See Also:
Constant Field Values

TYPE_SUB

static final int TYPE_SUB
constant for binary "-" operations

See Also:
Constant Field Values

TYPE_MULT

static final int TYPE_MULT
constant for binary "*" operations

See Also:
Constant Field Values

TYPE_DIV

static final int TYPE_DIV
constant for binary "/" operations

See Also:
Constant Field Values

TYPE_MOD

static final int TYPE_MOD
constant for binary "%" operations

See Also:
Constant Field Values

TYPE_MINUS

static final int TYPE_MINUS
constant for unary "-" operations

See Also:
Constant Field Values

TYPE_PLUS

static final int TYPE_PLUS
constant for unary "+" operations

See Also:
Constant Field Values

TYPE_NOT

static final int TYPE_NOT
constant for unary "!" operations

See Also:
Constant Field Values

TYPE_CONTAINSALL

static final int TYPE_CONTAINSALL
constant for "containsall" comparisons

See Also:
Constant Field Values

TYPE_UNKNOWN

static final int TYPE_UNKNOWN
constant for unknown function type (this must always be the highest index)

See Also:
Constant Field Values

FUNCTIONTYPE_NAMES

static final String[] FUNCTIONTYPE_NAMES
constant of the function type names

Method Detail

evaluate

Object evaluate(int functionType,
                ExpressionQueryRequest request,
                EvaluableExpression[] operand,
                int expectedValueType)
                throws ExpressionParserException
Static evaluation of the function.
The functionType is one of (TYPE_ADD, TYPE_AND, TYPE_CONTAINSNONE, TYPE_CONTAINSNONE, TYPE_DIV, TYPE_EQUAL, TYPE_GREATER, TYPE_GREATEROREQUAL, TYPE_LIKE, TYPE_MINUS, TYPE_MOD, TYPE_MULT, TYPE_NAMEDFUNCTION, TYPE_NOT, TYPE_OR, TYPE_PLUS, TYPE_SMALLER, TYPE_SMALLEROREQUAL, TYPE_SUB, TYPE_UNEQUAL) and will always be one of the types returned by getTypes().
The expectedValueType is one of (ExpressionEvaluator.OBJECTTYPE_ANY, ExpressionEvaluator.OBJECTTYPE_BOOLEAN, ExpressionEvaluator.OBJECTTYPE_COLLECTION, ExpressionEvaluator.OBJECTTYPE_DATE, ExpressionEvaluator.OBJECTTYPE_NULL, ExpressionEvaluator.OBJECTTYPE_NUMBER, ExpressionEvaluator.OBJECTTYPE_STRING), where ExpressionEvaluator.OBJECTTYPE_ANY shall be used when any value type is acceptable.
Implementations must respect the expected value type and must throw a EvaluationException when it cannot generate a value of this type.

Parameters:
functionType - type of the function
request - expression request
operand - array of function operands
expectedValueType - expected value type for the result.
Returns:
value of the evaluated function
Throws:
ExpressionParserException - when evaluation of the function fails
See Also:
ExpressionEvaluator

generateFilterPart

void generateFilterPart(int functionType,
                        ExpressionQueryRequest request,
                        FilterPart filterPart,
                        EvaluableExpression[] operand,
                        int expectedValueType)
                        throws ExpressionParserException
Generate the filter part for the function.
The functionType is one of (TYPE_ADD, TYPE_AND, TYPE_CONTAINSNONE, TYPE_CONTAINSNONE, TYPE_DIV, TYPE_EQUAL, TYPE_GREATER, TYPE_GREATEROREQUAL, TYPE_LIKE, TYPE_MINUS, TYPE_MOD, TYPE_MULT, TYPE_NAMEDFUNCTION, TYPE_NOT, TYPE_OR, TYPE_PLUS, TYPE_SMALLER, TYPE_SMALLEROREQUAL, TYPE_SUB, TYPE_UNEQUAL) and will always be one of the types returned by getTypes().
The expectedValueType is one of (ExpressionEvaluator.OBJECTTYPE_ANY, ExpressionEvaluator.OBJECTTYPE_BOOLEAN, ExpressionEvaluator.OBJECTTYPE_COLLECTION, ExpressionEvaluator.OBJECTTYPE_DATE, ExpressionEvaluator.OBJECTTYPE_NULL, ExpressionEvaluator.OBJECTTYPE_NUMBER, ExpressionEvaluator.OBJECTTYPE_STRING), where ExpressionEvaluator.OBJECTTYPE_ANY shall be used when any value type is acceptable.
Implementations must respect the expected value type and must throw a FilterGeneratorException when it cannot generate a value of this type.

Parameters:
functionType - type of the function
request - expression request
filterPart - filterpart that is generated
operand - array of function operands
expectedValueType - expected value type for the result
Throws:
ExpressionParserException - when generation of the filter part fails
See Also:
ExpressionEvaluator

getName

String getName()
Get the name of the function. This is ignored if the type of the function is not TYPE_NAMEDFUNCTION.

Returns:
name of the function
See Also:
getTypes(), TYPE_NAMEDFUNCTION

getTypes

int[] getTypes()
Get the types of the function. The array may only contain values of (TYPE_ADD, TYPE_AND, TYPE_CONTAINSNONE, TYPE_CONTAINSNONE, TYPE_DIV, TYPE_EQUAL, TYPE_GREATER, TYPE_GREATEROREQUAL, TYPE_LIKE, TYPE_MINUS, TYPE_MOD, TYPE_MULT, TYPE_NAMEDFUNCTION, TYPE_NOT, TYPE_OR, TYPE_PLUS, TYPE_SMALLER, TYPE_SMALLEROREQUAL, TYPE_SUB, TYPE_UNEQUAL). The function is registered to implement the returned function types and will be called for only those types.

Returns:
types of the function

getMinParameters

int getMinParameters()
Get minimum number of parameters.

Returns:
minimum number of parameters

getMaxParameters

int getMaxParameters()
Get maximum number of parameters. Must be either UNBOUNDED (for unlimited number of parameters) or <= getMinParameters().

Returns:
maximum number of parameters
See Also:
getMinParameters()

getSupportedDatasourceClasses

Class[] getSupportedDatasourceClasses()
Get the array of supported datasource classes for this function. This may also include the interface ExpressionEvaluator for functions that implement the evaluation of expression parts.

Returns:
array of classes for which this function can generate a part of the datasource filter
See Also:
ExpressionEvaluator

supportStaticEvaluation

boolean supportStaticEvaluation()
Check whether the function supports static evaluation (calls to evaluate(int, ExpressionQueryRequest, EvaluableExpression[], int) without a given datasource).

Returns:
true when the function supports static evaluation, false if not

getExpectedValueType

int getExpectedValueType(int functionType)
                         throws ExpressionParserException
Get the value type which this expression is expected to return

Parameters:
functionType - function type
Returns:
expected value type (ExpressionEvaluator.OBJECTTYPE_ANY if no specific value type can be expected)
Throws:
ExpressionParserException


Copyright © 2013 Gentics Software GmbH. All Rights Reserved.