Package net.sf.saxon.query
Class XQueryFunction
java.lang.Object
net.sf.saxon.query.XQueryFunction
- All Implemented Interfaces:
SourceLocator
,FunctionDefinition
,Declaration
,Location
,Locator
A user-defined function in an XQuery module
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an argument to the list of parametersvoid
checkReferences
(ExpressionVisitor visitor) Type-check references to this functionvoid
compile()
Compile this function to create a run-time definition that can be interpreted (note, this has nothing to do with Java code generation)void
Produce diagnostic output showing the compiled and optimized expression tree for a functionvoid
Fix up references to this functionGet the annotations defined on this functionGet the declared types of the arguments of this functiongetBody()
Get the body of the functionint
Return the column numbergetDefaultValueExpression
(int i) Get the default value expression of the Nth parameter, if anyGet the name of the function for display in error messagesGet the name of the function as a structured QNameGet the host language (XSLT, XQuery, XPath) used to implement the code in this containerGet an identifying key for this function, which incorporates the URI and local part of the function name plus the aritystatic SymbolicName
getIdentificationKey
(StructuredQName qName, int arity) Construct what the identification key would be for a function with given URI, local name, and arityint
Get the line number of the instruction in the source stylesheet module.int
Get the minimum arity of the functionGet the namespace context of the instruction.int
Get the maximum arity of the functionGet a name identifying the object of the expression, for example a function name, template name, variable name, key name, element name, etc.Get data about the unit of compilation (XQuery module, XSLT package) to which this container belongsGet the definitions of the arguments to this functiongetParameterName
(int i) Get the name of the Nth parameter, if anyint
Get the position in the parameter list of a given parameter nameGet an iterator over all the properties available.getProperty
(String name) Get the value of a particular property of the instruction.Return the public identifier for the current document event.Get the result type of the functionGet the static context for this functionGet the system identifier (URI) of the source module containing the instruction.Get the callable compiled function contained within this XQueryFunction definition.boolean
hasAnnotation
(StructuredQName name) Ask whether the function has an annotation with a particular nameboolean
Find out whether this is a memo functionboolean
Ask whether this is a private function (as defined in XQuery 3.0)boolean
Ask whether this is an updating function (as defined in XQuery Update)void
optimize()
Optimize the body of this functionvoid
Register a call on this functionGet an immutable copy of this Location object.void
setAnnotations
(AnnotationList annotations) Set the annotations on this functionvoid
setBody
(Expression body) Set the body of the functionvoid
Set the name of the functionvoid
setLocation
(Location location) Set the location of the source declaration of the functionvoid
setMemoFunction
(boolean isMemoFunction) Set that this is, or is not, a memo function.void
setResultType
(SequenceType resultType) Set the required result type of the functionvoid
Set the static context for this functionvoid
setUpdating
(boolean isUpdating) Set whether this is an updating function (as defined in XQuery Update)
-
Constructor Details
-
XQueryFunction
public XQueryFunction()Create an XQuery function
-
-
Method Details
-
getPackageData
Get data about the unit of compilation (XQuery module, XSLT package) to which this container belongs- Returns:
- the package information
-
setFunctionName
Set the name of the function- Parameters:
name
- the name of the function as a StructuredQName object
-
addParameter
Add an argument to the list of parameters- Parameters:
param
- the formal declaration of the parameter to be added
-
setResultType
Set the required result type of the function- Parameters:
resultType
- the declared result type of the function
-
setBody
Set the body of the function- Parameters:
body
- the expression forming the body of the function
-
getBody
Get the body of the function- Returns:
- the expression making up the body of the function
-
setLocation
Set the location of the source declaration of the function- Parameters:
location
- the source location
-
getFunctionName
Get the name of the function as a structured QName- Specified by:
getFunctionName
in interfaceFunctionDefinition
- Returns:
- the name of the function as a structured QName
-
getDisplayName
Get the name of the function for display in error messages- Returns:
- the name of the function as a lexical QName
-
getIdentificationKey
Get an identifying key for this function, which incorporates the URI and local part of the function name plus the arity- Returns:
- an identifying key
-
getIdentificationKey
Construct what the identification key would be for a function with given URI, local name, and arity- Parameters:
qName
- the name of the functionarity
- the number of arguments- Returns:
- an identifying key
-
getResultType
Get the result type of the function- Returns:
- the declared result type
-
setStaticContext
Set the static context for this function- Parameters:
env
- the static context for the module in which the function is declared
-
getStaticContext
Get the static context for this function- Returns:
- the static context for the module in which the function is declared
-
getArgumentTypes
Get the declared types of the arguments of this function- Returns:
- an array, holding the types of the arguments in order
-
getParameterDefinitions
Get the definitions of the arguments to this function- Returns:
- an array of UserFunctionParameter objects, one for each argument
-
getPositionOfParameter
Get the position in the parameter list of a given parameter name- Specified by:
getPositionOfParameter
in interfaceFunctionDefinition
- Parameters:
name
- the name of the required parameter- Returns:
- the position of the parameter in the parameter list, or -1 if absent
-
getParameterName
Get the name of the Nth parameter, if any- Specified by:
getParameterName
in interfaceFunctionDefinition
- Parameters:
i
- the position of the required parameter- Returns:
- the name (keyword) of the Nth parameter
-
getDefaultValueExpression
Get the default value expression of the Nth parameter, if any- Specified by:
getDefaultValueExpression
in interfaceFunctionDefinition
- Parameters:
i
- the position of the required parameter- Returns:
- the expression for computing the value of the Nth parameter, or null if there is none
-
getNumberOfParameters
public int getNumberOfParameters()Get the maximum arity of the function- Specified by:
getNumberOfParameters
in interfaceFunctionDefinition
- Returns:
- the arity (the maximum number of arguments including optional arguments)
-
getMinimumArity
public int getMinimumArity()Get the minimum arity of the function- Specified by:
getMinimumArity
in interfaceFunctionDefinition
- Returns:
- the number of mandatory parameters
-
registerReference
Register a call on this function- Parameters:
ufc
- a user function call that references this function.
-
setMemoFunction
public void setMemoFunction(boolean isMemoFunction) Set that this is, or is not, a memo function. A memo function remembers the results of calls on the function so that the a subsequent call with the same arguments simply look up the result- Parameters:
isMemoFunction
- true if this is a memo function.
-
isMemoFunction
public boolean isMemoFunction()Find out whether this is a memo function- Returns:
- true if this is a memo function
-
setUpdating
public void setUpdating(boolean isUpdating) Set whether this is an updating function (as defined in XQuery Update)- Parameters:
isUpdating
- true if this is an updating function
-
isUpdating
public boolean isUpdating()Ask whether this is an updating function (as defined in XQuery Update)- Returns:
- true if this is an updating function
-
setAnnotations
Set the annotations on this function- Parameters:
annotations
- the annotations, indexed by annotation name
-
getAnnotations
Get the annotations defined on this function- Returns:
- the list of annotations defined on this function
-
hasAnnotation
Ask whether the function has an annotation with a particular name- Parameters:
name
- the name of the required annotation- Returns:
- true if the function has an annotation with this name
-
isPrivate
public boolean isPrivate()Ask whether this is a private function (as defined in XQuery 3.0)- Returns:
- true if this is a private function
-
compile
Compile this function to create a run-time definition that can be interpreted (note, this has nothing to do with Java code generation)- Throws:
XPathException
- if errors are found
-
optimize
Optimize the body of this function- Throws:
XPathException
- if execution fails, for example because the function is updating and contains constructs not allowed in an updating function, or vice-versa.
-
fixupReferences
public void fixupReferences()Fix up references to this function -
checkReferences
Type-check references to this function- Parameters:
visitor
- the expression visitor- Throws:
XPathException
- if type errors are found
-
explain
Produce diagnostic output showing the compiled and optimized expression tree for a function- Parameters:
out
- the destination to be used- Throws:
XPathException
- if things go wrong
-
getUserFunction
Get the callable compiled function contained within this XQueryFunction definition.- Returns:
- the compiled function object
-
getObjectName
Get a name identifying the object of the expression, for example a function name, template name, variable name, key name, element name, etc. This is used only where the name is known statically.- Returns:
- the function name
-
getSystemId
Get the system identifier (URI) of the source module containing the instruction. This will generally be an absolute URI. If the system identifier is not known, the method may return null. In some cases, for example where XML external entities are used, the correct system identifier is not always retained.- Specified by:
getSystemId
in interfaceLocation
- Specified by:
getSystemId
in interfaceLocator
- Specified by:
getSystemId
in interfaceSourceLocator
- Returns:
- the system ID, or null if the information is not available.
-
getLineNumber
public int getLineNumber()Get the line number of the instruction in the source stylesheet module. If this is not known, or if the instruction is an artificial one that does not relate to anything in the source code, the value returned may be -1.- Specified by:
getLineNumber
in interfaceLocation
- Specified by:
getLineNumber
in interfaceLocator
- Specified by:
getLineNumber
in interfaceSourceLocator
- Returns:
- the line number, or -1 if the information is not available.
-
getPublicId
Return the public identifier for the current document event.- Specified by:
getPublicId
in interfaceLocation
- Specified by:
getPublicId
in interfaceLocator
- Specified by:
getPublicId
in interfaceSourceLocator
- Returns:
- A string containing the public identifier, or null if none is available.
- See Also:
-
getColumnNumber
public int getColumnNumber()Return the column number- Specified by:
getColumnNumber
in interfaceLocation
- Specified by:
getColumnNumber
in interfaceLocator
- Specified by:
getColumnNumber
in interfaceSourceLocator
- Returns:
- The column number, or -1 if none is available.
- See Also:
-
saveLocation
Get an immutable copy of this Location object. By default Location objects may be mutable, so they should not be saved for later use. The result of this operation holds the same location information, but in an immutable form.- Specified by:
saveLocation
in interfaceLocation
- Returns:
- an immutable copy (which may be the original object, if it is already immutable)
-
getNamespaceResolver
Get the namespace context of the instruction. This will not always be available, in which case the method returns null.- Returns:
- a resolver representing the namespace context for the function
-
getProperty
Get the value of a particular property of the instruction. Properties of XSLT instructions are generally known by the name of the stylesheet attribute that defines them.- Parameters:
name
- The name of the required property- Returns:
- The value of the requested property, or null if the property is not available
-
getProperties
Get an iterator over all the properties available. The values returned by the iterator will be of type String, and each string can be supplied as input to the getProperty() method to retrieve the value of the property.- Returns:
- the properties available
-
getHostLanguage
Get the host language (XSLT, XQuery, XPath) used to implement the code in this container- Returns:
HostLanguage.XQUERY
-