org.josql.expressions
Class Function

java.lang.Object
  extended by org.josql.expressions.Expression
      extended by org.josql.expressions.ValueExpression
          extended by org.josql.expressions.Function

public class Function
extends ValueExpression

This class represents a Function that can be "called" in JoSQL.


Constructor Summary
Function()
           
 
Method Summary
 Object evaluate(Object o, Query q)
          Evaluate this function on the current object.
 String getAccessor()
           
 Class getExpectedReturnType(Query q)
          Get the expected return type from the function.
 com.gentlyweb.utils.Getter getGetter()
           
 String getName()
           
 List getParameters()
          Return the List of Expression objects that constitute the arguments to the function, no guarantee is made here as to whether they have been inited.
 boolean hasFixedResult(Query q)
          Return whether the function will return a fixed result, this only occurs iff all the arguments to the function also return a fixed result.
 void init(Query q)
          This is a complex method that will initialise the function.
 boolean isTrue(Object o, Query q)
          Return whether the evaluation of this function (see: evaluate(Object,Query)) will result in a true value.
 void setAccessor(String acc)
           
 void setName(String name)
           
 void setParameters(List ps)
           
 String toString()
          Return a string representation of the function.
 
Methods inherited from class org.josql.expressions.ValueExpression
getValue
 
Methods inherited from class org.josql.expressions.Expression
isBracketed, setBracketed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Function

public Function()
Method Detail

getGetter

public com.gentlyweb.utils.Getter getGetter()

getAccessor

public String getAccessor()

setAccessor

public void setAccessor(String acc)

getExpectedReturnType

public Class getExpectedReturnType(Query q)
Get the expected return type from the function. The exact class returned is dependent upon the function (Java method) that is being called.

Specified by:
getExpectedReturnType in class Expression
Parameters:
q - The Query object.
Returns:
The class of the expected return type.

init

public void init(Query q)
          throws QueryParseException
This is a complex method that will initialise the function. Firstly all of the "arguments" to the function are inited and then their expected return types gained from calling: getExpectedReturnType(Query). Then the function handlers, user-defined and then built-in are searched until they find a match for the function name, ensure that it's a public method and that all the arguments match, widening the match where necessary.

Specified by:
init in class Expression
Parameters:
q - The Query object.
Throws:
QueryParseException - If something goes wrong whilst initing the arguments to the function or if the function cannot be found.

getParameters

public List getParameters()
Return the List of Expression objects that constitute the arguments to the function, no guarantee is made here as to whether they have been inited.

Returns:
The List of Expression objects.

setParameters

public void setParameters(List ps)

setName

public void setName(String name)

getName

public String getName()

evaluate

public Object evaluate(Object o,
                       Query q)
                throws QueryExecutionException
Evaluate this function on the current object. It should be noted that not all functions will use the current object in their execution, functions from the GroupingFunctions class are notable exceptions.

Specified by:
evaluate in class ValueExpression
Parameters:
o - The current object.
q - The Query object.
Returns:
The result of evaluating the function.
Throws:
QueryExecutionException - If something goes wrong during execution of the function or gaining the values to be used as arguments.

isTrue

public boolean isTrue(Object o,
                      Query q)
               throws QueryExecutionException
Return whether the evaluation of this function (see: evaluate(Object,Query)) will result in a true value. See: ArithmeticExpression.isTrue(Object,Query) for details of how this is determined.

Specified by:
isTrue in class Expression
Parameters:
o - The current object.
q - The Query object.
Returns:
true if the function return value evaluates to true.
Throws:
QueryExecutionException - If something goes wrong with evaluating the function.

toString

public String toString()
Return a string representation of the function. In the form: Name ( Expression [ , Expression ] )

Specified by:
toString in class Expression
Returns:
A string representation of the function.

hasFixedResult

public boolean hasFixedResult(Query q)
Return whether the function will return a fixed result, this only occurs iff all the arguments to the function also return a fixed result.

Specified by:
hasFixedResult in class Expression
Parameters:
q - The Query object.
Returns:
true if the expression evaluates to a fixed/constant result.


  Copyright © 2008 Gary Bentley. All Rights Reserved.