net.sf.saxon.expr
Class UserFunctionCall

java.lang.Object
  |
  +--net.sf.saxon.expr.ComputedExpression
        |
        +--net.sf.saxon.expr.FunctionCall
              |
              +--net.sf.saxon.expr.UserFunctionCall
All Implemented Interfaces:
Expression, java.io.Serializable

public class UserFunctionCall
extends FunctionCall

This class represents a call to a function defined in the stylesheet or query. It is used for all user-defined functions in XQuery, and for a limited class of user-defined functions in XSLT: those that can be reduced to the evaluation of a single expression.

See Also:
Serialized Form

Nested Class Summary
static class UserFunctionCall.FunctionCallPackage
          Inner class used to wrap up the set of actual arguments to a tail-recursive call of the containing function.
 
Field Summary
 
Fields inherited from class net.sf.saxon.expr.FunctionCall
argument
 
Fields inherited from class net.sf.saxon.expr.ComputedExpression
lineNumber, NO_ARGUMENTS, staticProperties
 
Constructor Summary
UserFunctionCall()
           
 
Method Summary
 void checkArguments(StaticContext env)
          Method called during the type checking phase
 int computeCardinality()
          Determine the cardinality of the result
 void display(int level, NamePool pool)
          Diagnostic print of expression structure.
 Item evaluateItem(XPathContext c)
          Call the function, returning the value as an item.
 int getFingerprint()
          Get the fingerprint representing the name of the function
 ItemType getItemType()
          Determine the data type of the expression, if possible
 java.lang.String getName()
          Get the name of the function.
 SequenceIterator iterate(XPathContext c)
          Call the function, returning an iterator over the results.
 boolean markTailFunctionCalls()
          Mark tail-recursive calls on stylesheet functions.
 Expression preEvaluate(StaticContext env)
          Pre-evaluate a function at compile time.
 void setFingerprint(int fingerprint)
          Set the fingerprint representing the name of the function
 void setFunction(FunctionSignature sourceFunction, CallableFunction compiledFunction)
          Create the reference to the function to be called, and validate for consistency
 void setStaticType(SequenceType type)
          Set the static type
 Expression simplify()
          Simplify the function call
 
Methods inherited from class net.sf.saxon.expr.FunctionCall
analyze, checkArgumentCount, getNumberOfArguments, getSubExpressions, promote, setArguments, simplifyArguments
 
Methods inherited from class net.sf.saxon.expr.ComputedExpression
computeDependencies, computeSpecialProperties, computeStaticProperties, dynamicError, effectiveBooleanValue, evaluateAsString, getCardinality, getDependencies, getIntrinsicDependencies, getLineNumber, getSpecialProperties, setLineNumber, typeError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserFunctionCall

public UserFunctionCall()
Method Detail

setFingerprint

public void setFingerprint(int fingerprint)
Set the fingerprint representing the name of the function


getFingerprint

public int getFingerprint()
Get the fingerprint representing the name of the function


setStaticType

public void setStaticType(SequenceType type)
Set the static type


setFunction

public void setFunction(FunctionSignature sourceFunction,
                        CallableFunction compiledFunction)
                 throws XPathException
Create the reference to the function to be called, and validate for consistency

XPathException

getName

public java.lang.String getName()
Get the name of the function. Used for diagnostic purposes only.

Specified by:
getName in class FunctionCall
Returns:
the name of the function, as used in XSL expressions

checkArguments

public void checkArguments(StaticContext env)
                    throws XPathException
Method called during the type checking phase

Specified by:
checkArguments in class FunctionCall
XPathException

preEvaluate

public Expression preEvaluate(StaticContext env)
Pre-evaluate a function at compile time. This version of the method suppresses early evaluation by doing nothing.

Overrides:
preEvaluate in class FunctionCall

getItemType

public ItemType getItemType()
Determine the data type of the expression, if possible

Returns:
Type.ITEM (meaning not known in advance)

computeCardinality

public int computeCardinality()
Determine the cardinality of the result

Specified by:
computeCardinality in class ComputedExpression

simplify

public Expression simplify()
                    throws XPathException
Simplify the function call

Specified by:
simplify in interface Expression
Overrides:
simplify in class FunctionCall
Returns:
the simplified expression
Throws:
XPathException - if an error is discovered during expression rewriting

markTailFunctionCalls

public boolean markTailFunctionCalls()
Mark tail-recursive calls on stylesheet functions. For most expressions, this does nothing.

Overrides:
markTailFunctionCalls in class ComputedExpression
Returns:
true if a tail recursive call was found and if this call accounts for the whole of the value.

evaluateItem

public Item evaluateItem(XPathContext c)
                  throws XPathException
Call the function, returning the value as an item. This method will be used only when the cardinality is zero or one. If the function is tail recursive, it returns an Object representing the arguments to the next (recursive) call, which is specially handled by the code in FunctionInstr.

Specified by:
evaluateItem in interface Expression
Overrides:
evaluateItem in class ComputedExpression
Parameters:
c - The context in which the expression is to be evaluated
Returns:
the node or atomic value that results from evaluating the expression; or null to indicate that the result is an empty sequence
Throws:
XPathException - if any dynamic error occurs evaluating the expression

iterate

public SequenceIterator iterate(XPathContext c)
                         throws XPathException
Call the function, returning an iterator over the results. (But if the function is tail recursive, it returns an iterator over the arguments of the recursive call, which is specially handled by the code in FunctionInstr)

Specified by:
iterate in interface Expression
Overrides:
iterate in class ComputedExpression
Parameters:
c - supplies the context for evaluation
Returns:
a SequenceIterator that can be used to iterate over the result of the expression
Throws:
XPathException - if any dynamic error occurs evaluating the expression

display

public void display(int level,
                    NamePool pool)
Description copied from interface: Expression
Diagnostic print of expression structure. The expression is written to the System.err output stream

Specified by:
display in interface Expression
Overrides:
display in class FunctionCall
Parameters:
level - indentation level for this expression