com.icl.saxon.expr

Class FunctionProxy

public class FunctionProxy extends Function

This class acts as a proxy for an extension function defined as a method in a user-defined class
Constructor Summary
FunctionProxy()
Constructor: creates an uncommitted FunctionProxy
Method Summary
static ValueconvertJavaObjectToXPath(Object result, Controller controller)
Convert a Java object to an XPath value.
NodeEnumerationenumerate(Context context, boolean requireSorted)
Valueevaluate(Context context)
Evaluate the function.
booleanevaluateAsBoolean(Context context)
doubleevaluateAsNumber(Context context)
StringevaluateAsString(Context context)
ObjectgetBestFit(Value[] argValues)
Get the best fit amongst all the candidate methods or constructors
intgetDataType()
Determine the data type of the expression, if possible
intgetDependencies()
Determine which aspects of the context the expression depends on.
StringgetName()
Get the name of the function
Expressionreduce(int dependencies, Context context)
Perform a partial evaluation of the expression, by eliminating specified dependencies on the context.
booleansetFunctionName(Class reqClass, String localName)
setFunctionName: locates the external class and the method (or candidate methods) to which this function relates.
Expressionsimplify()
Simplify the function (by simplifying its arguments)

Constructor Detail

FunctionProxy

public FunctionProxy()
Constructor: creates an uncommitted FunctionProxy

Method Detail

convertJavaObjectToXPath

public static Value convertJavaObjectToXPath(Object result, Controller controller)
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.

enumerate

public NodeEnumeration enumerate(Context context, boolean requireSorted)

evaluate

public Value evaluate(Context context)
Evaluate the function.

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.

evaluateAsBoolean

public boolean evaluateAsBoolean(Context context)

evaluateAsNumber

public double evaluateAsNumber(Context context)

evaluateAsString

public String evaluateAsString(Context context)

getBestFit

public Object getBestFit(Value[] argValues)
Get the best fit amongst all the candidate methods or constructors

Returns: the result is either a Method or a Constructor. In JDK 1.2 these have a common superclass, AccessibleObject, but this is not available in JDK 1.1, which we still support.

getDataType

public int getDataType()
Determine the data type of the expression, if possible

Returns: Value.ANY (meaning not known in advance)

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

getName

public String getName()
Get the name of the function

reduce

public Expression reduce(int dependencies, Context context)
Perform a partial evaluation of the expression, by eliminating specified dependencies on the context.

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

setFunctionName

public boolean setFunctionName(Class reqClass, String localName)
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

Returns: true if the function is available (with some number of arguments).

simplify

public Expression simplify()
Simplify the function (by simplifying its arguments)