net.sf.saxon.expr
Class FunctionProxy

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

public class FunctionProxy
extends FunctionCall

This class acts as a proxy for an extension function defined as a method in a user-defined class

See Also:
Serialized Form

Field Summary
 Configuration config
           
 
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
FunctionProxy()
          Constructor: creates an uncommitted FunctionProxy
 
Method Summary
 Expression analyze(StaticContext env)
          Type-check the function call.
 void checkArguments(StaticContext env)
          Method called by the expression parser when all arguments have been supplied
 int computeCardinality()
          Determine the cardinality of the result.
static Value convertJavaObjectToXPath(java.lang.Object result, Controller controller)
          Convert a Java object to an XPath value.
 Item evaluateItem(XPathContext context)
          Evaluate the function.
 java.lang.reflect.AccessibleObject getBestFit(Value[] argValues)
          Get the best fit amongst all the candidate methods, constructors, or fields
static java.lang.Class getImplicitJavaClass(java.lang.String uri)
          Extract a class name from the URI
 int getIntrinsicDependencies()
          Determine which aspects of the context the expression depends on.
 ItemType getItemType()
          Determine the data type of the expression, if possible
 java.lang.String getName()
          Get the name of the function
static java.lang.Class getVendorExtensionClass(java.lang.String uri)
          Get a class corresponding to a known extension function URI
 SequenceIterator iterate(XPathContext context)
          Return an Iterator to iterate over the values of a sequence.
 Expression preEvaluate(StaticContext env)
          preEvaluate: this method suppresses compile-time evaluation by doing nothing (because the external function might have side-effects and might use the context)
 void setConfiguration(Configuration config)
          Set the configuration
 boolean setFunctionName(java.lang.Class reqClass, java.lang.String localName, int numArgs)
          setFunctionName: locates the external class and the method (or candidate methods) to which this function relates.
 
Methods inherited from class net.sf.saxon.expr.FunctionCall
checkArgumentCount, display, getNumberOfArguments, getSubExpressions, promote, setArguments, simplify, simplifyArguments
 
Methods inherited from class net.sf.saxon.expr.ComputedExpression
computeDependencies, computeSpecialProperties, computeStaticProperties, dynamicError, effectiveBooleanValue, evaluateAsString, getCardinality, getDependencies, getLineNumber, getSourceLocator, getSpecialProperties, markTailFunctionCalls, setLineNumber, typeError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

config

public Configuration config
Constructor Detail

FunctionProxy

public FunctionProxy()
Constructor: creates an uncommitted FunctionProxy

Method Detail

setConfiguration

public void setConfiguration(Configuration config)
Set the configuration


setFunctionName

public boolean setFunctionName(java.lang.Class reqClass,
                               java.lang.String localName,
                               int numArgs)
setFunctionName: locates the external class and the method (or candidate methods) to which this function relates. At this stage addArguments() will have normally been called, so the number of arguments is known. If no method of the required name is located, an exception is saved, but it is not thrown until an attempt is made to evaluate the function. All methods that match the required number of arguments are saved in a list (candidateMethods), a decision among these methods is made at run-time when the types of the actual arguments are known.

The method is also used while calling function-available(). In this case the number of arguments is not known (it will be set to zero). We return true if a match was found, regardless of the number of arguments.

Parameters:
reqClass - The Java class name
localName - The local name used in the XPath function call
numArgs - The number of arguments in the function call. -1 indicates unknown; this is used during a call on function-available() with no second argument
Returns:
true if the function is available (with some number of arguments).

preEvaluate

public Expression preEvaluate(StaticContext env)
preEvaluate: this method suppresses compile-time evaluation by doing nothing (because the external function might have side-effects and might use the context)

Overrides:
preEvaluate in class FunctionCall

checkArguments

public void checkArguments(StaticContext env)
                    throws XPathException
Method called by the expression parser when all arguments have been supplied

Specified by:
checkArguments in class FunctionCall
XPathException

getItemType

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

Returns:
the return type of the function, if known in advance, or ITEM otherwise

computeCardinality

public int computeCardinality()
Determine the cardinality of the result. Try to work it out from the result class of the Java method.

Specified by:
computeCardinality in class ComputedExpression

getName

public java.lang.String getName()
Get the name of the function

Specified by:
getName in class FunctionCall

analyze

public Expression analyze(StaticContext env)
                   throws XPathException
Type-check the function call. This binds to the actual Java method if possible.

Specified by:
analyze in interface Expression
Overrides:
analyze in class FunctionCall
Parameters:
env - the static context of the expression
Returns:
the original expression, rewritten to perform necessary run-time type checks, and to perform other type-related optimizations
XPathException

getIntrinsicDependencies

public int getIntrinsicDependencies()
Determine which aspects of the context the expression depends on. The result is a bitwise-or'ed value composed from constants such as XPathContext.VARIABLES and XPathContext.CURRENT_NODE

Overrides:
getIntrinsicDependencies in class ComputedExpression
Returns:
a set of bit-significant flags identifying the "intrinsic" dependencies. The flags are documented in class net.sf.saxon.value.StaticProperty

getBestFit

public java.lang.reflect.AccessibleObject getBestFit(Value[] argValues)
                                              throws XPathException
Get the best fit amongst all the candidate methods, constructors, or fields

Returns:
the result is either a Method or a Constructor or a Field.
XPathException

evaluateItem

public Item evaluateItem(XPathContext context)
                  throws XPathException
Evaluate the function.

Specified by:
evaluateItem in interface Expression
Overrides:
evaluateItem in class ComputedExpression
Parameters:
context - The context in which the function is to be evaluated
Returns:
a Value representing the result of the function.
Throws:
XPathException - if the function cannot be evaluated.

iterate

public SequenceIterator iterate(XPathContext context)
                         throws XPathException
Description copied from class: ComputedExpression
Return an Iterator to iterate over the values of a sequence. The value of every expression can be regarded as a sequence, so this method is supported for all expressions. This default implementation handles iteration for expressions that return singleton values: for non-singleton expressions, the subclass must provide its own implementation.

Specified by:
iterate in interface Expression
Overrides:
iterate in class ComputedExpression
Parameters:
context - 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

getVendorExtensionClass

public static java.lang.Class getVendorExtensionClass(java.lang.String uri)
Get a class corresponding to a known extension function URI


getImplicitJavaClass

public static java.lang.Class getImplicitJavaClass(java.lang.String uri)
Extract a class name from the URI


convertJavaObjectToXPath

public static Value convertJavaObjectToXPath(java.lang.Object result,
                                             Controller controller)
                                      throws XPathException
Convert a Java object to an XPath value. This method is called to handle the result of an external function call (but only if the required type is not known), and also to process global parameters passed to the stylesheet.

Parameters:
result - The Java object to be converted
controller - The controller: may be null, in which case a Source object cannot be supplied
Returns:
the result of converting the value. If the value is null, returns null.
XPathException