com.icl.saxon.expr
Class Function

java.lang.Object
  |
  +--com.icl.saxon.expr.Expression
        |
        +--com.icl.saxon.expr.Function
Direct Known Subclasses:
BooleanFn, Ceiling, Concat, Contains, Count, Current, Document, ElementAvailable, Floor, FormatNumber, FunctionAvailable, FunctionProxy, GenerateId, Id, Key, Lang, Last, LocalName, NameFn, NamespaceURI, NormalizeSpace, Not, NumberFn, Position, Round, StartsWith, StringFn, StringLength, StyleSheetFunctionCall, Substring, SubstringAfter, SubstringBefore, Sum, SystemProperty, Translate, UnparsedEntityURI

public abstract class Function
extends Expression

Abstract superclass for system-defined and user-defined functions


Field Summary
protected  java.util.Vector arguments
           
 
Fields inherited from class com.icl.saxon.expr.Expression
emptyVector, staticContext
 
Constructor Summary
Function()
           
 
Method Summary
 void addArgument(Expression expr)
          Method to add an argument during function definition.
protected  int checkArgumentCount(int min, int max)
          Check number of arguments.
abstract  Value eval(java.util.Vector arguments, Context context)
          Evaluate the function, having evaluated its arguments.
 Value evaluate(Context c)
          Evaluate the function: evaluate the arguments, then call the function's eval() method
 int getDependencies()
          Determine which aspects of the context the expression depends on.
 int getIntrinsicDependencies()
          Get the intrinsic dependencies for the function, independent of the arguments
abstract  java.lang.String getName()
          Get the name of the function.
 Function newInstance()
          Make a new instance of this function
 Expression reduce(int dependencies, Context context)
          Perform a partial evaluation of the expression, by eliminating specified dependencies on the context.
protected  Expression reduceIntrinsic(int dependencies, Context context)
          Remove intrinsic dependencies.
 Expression simplify()
          Simplify an expression
 Expression simplifyPureFunction()
          Method to simplify a pure function, ie.
 java.lang.String toString()
          Get a string representation of the function call
 
Methods inherited from class com.icl.saxon.expr.Expression
containsReferences, enumerate, evaluateAsBoolean, evaluateAsNodeSet, evaluateAsNumber, evaluateAsString, getDataType, getStaticContext, isNumeric, isRelative, make, make, setStaticContext, usesCurrent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

arguments

protected java.util.Vector arguments
Constructor Detail

Function

public Function()
Method Detail

addArgument

public void addArgument(Expression expr)
Method to add an argument during function definition.

getName

public abstract java.lang.String getName()
Get the name of the function. This method must be implemented in all subclasses.
Returns:
the name of the function, as used in XSL expressions, but excluding its namespace prefix

simplify

public Expression simplify()
                    throws org.xml.sax.SAXException
Simplify an expression
Overrides:
simplify in class Expression
Returns:
the simplified expression

simplifyPureFunction

public Expression simplifyPureFunction()
                                throws org.xml.sax.SAXException
Method to simplify a pure function, ie. one which is not context dependent. This method may be invoked from the simplify() method of a subclass. If all the arguments of the function are Values, it pre-evaluates the function and returns the result.

evaluate

public Value evaluate(Context c)
               throws org.xml.sax.SAXException
Evaluate the function: evaluate the arguments, then call the function's eval() method
Overrides:
evaluate in class Expression
Following copied from class: com.icl.saxon.expr.Expression
Parameters:
context - The context in which the expression is to be evaluated
Returns:
the value of the expression, evaluated in the current context

getIntrinsicDependencies

public int getIntrinsicDependencies()
Get the intrinsic dependencies for the function, independent of the arguments

getDependencies

public int getDependencies()
Determine which aspects of the context the expression depends on. The result is a bitwise-or'ed value composed from constants such as Context.VARIABLES and Context.CURRENT_NODE
Overrides:
getDependencies in class Expression

reduce

public Expression reduce(int dependencies,
                         Context context)
                  throws org.xml.sax.SAXException
Perform a partial evaluation of the expression, by eliminating specified dependencies on the context.
Overrides:
reduce in class Expression
Parameters:
dependencies - The dependencies to be removed
context - The context to be used for the partial evaluation
Returns:
a new expression that does not have any of the specified dependencies

newInstance

public Function newInstance()
                     throws org.xml.sax.SAXException
Make a new instance of this function

reduceIntrinsic

protected Expression reduceIntrinsic(int dependencies,
                                     Context context)
                              throws org.xml.sax.SAXException
Remove intrinsic dependencies. Default implementation. An "intrinsic" dependency is one in the function itself, as distinct from a dependency in its arguments.

eval

public abstract Value eval(java.util.Vector arguments,
                           Context context)
                    throws org.xml.sax.SAXException
Evaluate the function, having evaluated its arguments.
This method must be implemented in all subclasses.
Parameters:
arguments - A Vector, each of whose elements is a Value containing the value of a supplied argument to the function.
context - The context in which the function is to be evaluated
Returns:
a Value representing the result of the function. This must be of the data type corresponding to the result of getType().
Throws:
org.xml.sax.SAXException - if the function cannot be evaluated.

toString

public java.lang.String toString()
Get a string representation of the function call
Overrides:
toString in class java.lang.Object

checkArgumentCount

protected int checkArgumentCount(int min,
                                 int max)
                          throws org.xml.sax.SAXException
Check number of arguments.
A convenience routine for use in subclasses.
Parameters:
min - the minimum number of arguments allowed
max - the maximum number of arguments allowed
Returns:
the actual number of arguments
Throws:
org.xml.sax.SAXException - if the number of arguments is out of range