Package net.sf.saxon.instruct
Class UserFunction
java.lang.Object
net.sf.saxon.instruct.Procedure
net.sf.saxon.instruct.UserFunction
- All Implemented Interfaces:
Serializable
,SourceLocator
,LocationProvider
,Container
,InstructionInfoProvider
This object represents the compiled form of a user-written function
(the source can be either an XSLT stylesheet function or an XQuery function).
It is assumed that type-checking, of both the arguments and the results, has been handled at compile time. That is, the expression supplied as the body of the function must be wrapped in code to check or convert the result to the required type, and calls on the function must be wrapped at compile time to check or convert the supplied arguments.
- See Also:
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncall
(ValueRepresentation[] actualArgs, Controller controller) Call this function.call
(ValueRepresentation[] actualArgs, XPathContextMajor context) Call this function to return a value.void
getArgumentType
(int n) Get the required types of an argument to this functionint
Get the evaluation modeint
Get the namepool name code of the functionGet the InstructionInfo details about the construct.int
Get the arity of this functionGet the type of value returned by this functionboolean
void
process
(ValueRepresentation[] actualArgs, XPathContextMajor context) Call this function in "push" mode, writing the results to the current output destination.void
setFunctionNameCode
(int nameCode) Set the namepool name code of the functionvoid
setMemoFunction
(boolean isMemo) Mark this function as a memo function (or not)void
setParameterDefinitions
(UserFunctionParameter[] params) void
setResultType
(SequenceType resultType) void
setTailRecursive
(boolean tailCalls) Methods inherited from class net.sf.saxon.instruct.Procedure
getBody, getColumnNumber, getExecutable, getHostLanguage, getLineNumber, getLineNumber, getLocationProvider, getPublicId, getStackFrameMap, getSystemId, getSystemId, replaceSubExpression, setBody, setExecutable, setHostLanguage, setLineNumber, setStackFrameMap, setSystemId
-
Constructor Details
-
UserFunction
public UserFunction() -
UserFunction
-
-
Method Details
-
computeEvaluationMode
public void computeEvaluationMode() -
setParameterDefinitions
-
getParameterDefinitions
-
setResultType
-
setTailRecursive
public void setTailRecursive(boolean tailCalls) -
isTailRecursive
public boolean isTailRecursive() -
getResultType
Get the type of value returned by this function- Returns:
- the declared result type, or the inferred result type if this is more precise
-
getArgumentType
Get the required types of an argument to this function- Parameters:
n
- identifies the argument in question, starting at 0- Returns:
- a SequenceType object, indicating the required type of the argument
-
getEvaluationMode
public int getEvaluationMode()Get the evaluation mode -
getNumberOfArguments
public int getNumberOfArguments()Get the arity of this function- Returns:
- the number of arguments
-
setMemoFunction
public void setMemoFunction(boolean isMemo) Mark this function as a memo function (or not)- Parameters:
isMemo
- true if this is a memo function
-
setFunctionNameCode
public void setFunctionNameCode(int nameCode) Set the namepool name code of the function- Parameters:
nameCode
- represents the function name
-
getFunctionNameCode
public int getFunctionNameCode()Get the namepool name code of the function- Returns:
- a name code representing the function name
-
call
public ValueRepresentation call(ValueRepresentation[] actualArgs, XPathContextMajor context) throws XPathException Call this function to return a value.- Parameters:
actualArgs
- the arguments supplied to the function. These must have the correct types required by the function signature (it is the caller's responsibility to check this). It is acceptable to supply aClosure
to represent a value whose evaluation will be delayed until it is needed. The array must be the correct size to match the number of arguments: again, it is the caller's responsibility to check this.context
- This provides the run-time context for evaluating the function. It is the caller's responsibility to allocate a "clean" context for the function to use; the context that is provided will be overwritten by the function.- Returns:
- a Value representing the result of the function.
- Throws:
XPathException
-
process
public void process(ValueRepresentation[] actualArgs, XPathContextMajor context) throws XPathException Call this function in "push" mode, writing the results to the current output destination.- Parameters:
actualArgs
- the arguments supplied to the function. These must have the correct types required by the function signature (it is the caller's responsibility to check this). It is acceptable to supply aClosure
to represent a value whose evaluation will be delayed until it is needed. The array must be the correct size to match the number of arguments: again, it is the caller's responsibility to check this.context
- This provides the run-time context for evaluating the function. It is the caller's responsibility to allocate a "clean" context for the function to use; the context that is provided will be overwritten by the function.- Throws:
XPathException
-
call
public ValueRepresentation call(ValueRepresentation[] actualArgs, Controller controller) throws XPathException Call this function. This method allows an XQuery function to be called directly from a Java application. It creates the environment needed to achieve this- Parameters:
actualArgs
- the arguments supplied to the function. These must have the correct types required by the function signature (it is the caller's responsibility to check this). It is acceptable to supply aClosure
to represent a value whose evaluation will be delayed until it is needed. The array must be the correct size to match the number of arguments: again, it is the caller's responsibility to check this.controller
- This provides the run-time context for evaluating the function. A Controller may be obtained by callingXQueryExpression.newController()
. This may be used for a series of calls on functions defined in the same module as the XQueryExpression.- Returns:
- a Value representing the result of the function.
- Throws:
XPathException
-
getInstructionInfo
Get the InstructionInfo details about the construct. This information isn't used for tracing, but it is available when inspecting the context stack.- Specified by:
getInstructionInfo
in interfaceInstructionInfoProvider
-