Package net.sf.saxon.query
Class XQueryFunction
- java.lang.Object
-
- net.sf.saxon.query.XQueryFunction
-
- All Implemented Interfaces:
java.io.Serializable,javax.xml.transform.SourceLocator,LocationProvider,SaxonLocator,Container,Declaration,InstructionInfo,org.xml.sax.Locator
public class XQueryFunction extends java.lang.Object implements InstructionInfo, Container, Declaration
A user-defined function in an XQuery module- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description XQueryFunction()Create an XQuery function
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddArgument(UserFunctionParameter argument)Add an argument to the list of argumentsvoidcheckReferences(ExpressionVisitor visitor)Type-check references to this functionvoidcompile()Compile this function to create a run-time definition that can be interpreted (note, this has nothing to do with Java code generation)voidexplain(ExpressionPresenter out)Produce diagnostic output showing the compiled and optimized expression tree for a functionvoidfixupReferences()Fix up references to this functionSequenceType[]getArgumentTypes()Get the declared types of the arguments of this functionExpressiongetBody()Get the body of the functionintgetColumnNumber()Return the column numberintgetColumnNumber(long locationId)Get the column number within the document, entity, or module containing a particular locationintgetConstructType()Get the type of construct.intgetContainerGranularity()Get the granularity of the container.java.lang.StringgetDisplayName()Get the name of the function for display in error messagesExecutablegetExecutable()Get the executable in which this function is containedStructuredQNamegetFunctionName()Get the name of the function as a structured QNameintgetHostLanguage()Get the host language (XSLT, XQuery, XPath) used to implement the code in this containerjava.lang.StringgetIdentificationKey()Get an identifying key for this function, which incorporates the URI and local part of the function name plus the aritystatic java.lang.StringgetIdentificationKey(java.lang.String uri, java.lang.String localName, int arity)Construct what the identification key would be for a function with given URI, local name, and aritystatic java.lang.StringgetIdentificationKey(StructuredQName qName, int arity)Construct what the identification key would be for a function with given URI, local name, and arityintgetLineNumber()Get the line number of the instruction in the source stylesheet module.intgetLineNumber(long locationId)Get the line number within the document, entity or module containing a particular locationLocationProvidergetLocationProvider()Get the LocationProvider allowing location identifiers to be resolved.NamespaceResolvergetNamespaceResolver()Get the namespace context of the instruction.intgetNumberOfArguments()Get the arity of the functionStructuredQNamegetObjectName()Get a name identifying the object of the expression, for example a function name, template name, variable name, key name, element name, etc.UserFunctionParameter[]getParameterDefinitions()Get the definitions of the arguments to this functionjava.util.IteratorgetProperties()Get an iterator over all the properties available.java.lang.ObjectgetProperty(java.lang.String name)Get the value of a particular property of the instruction.java.lang.StringgetPublicId()Return the public identifier for the current document event.SequenceTypegetResultType()Get the result type of the functionStaticContextgetStaticContext()Get the static context for this functionjava.lang.StringgetSystemId()Get the system identifier (URI) of the source module containing the instruction.java.lang.StringgetSystemId(long locationId)Get the URI of the document, entity, or module containing a particular locationUserFunctiongetUserFunction()Get the callable compiled function contained within this XQueryFunction definition.booleanisMemoFunction()Find out whether this is a memo functionbooleanisPrivate()Ask whether this is a private function (as defined in XQuery 1.1)booleanisUpdating()Ask whether this is an updating function (as defined in XQuery Update)voidoptimize()Optimize the body of this functionvoidregisterReference(UserFunctionCall ufc)Register a call on this functionvoidsetBody(Expression body)Set the body of the functionvoidsetColumnNumber(int column)Set the column number of the function declarationvoidsetExecutable(Executable exec)Set the executable in which this function is containedvoidsetFunctionName(StructuredQName name)Set the name of the functionvoidsetLineNumber(int line)Set the line number of the function declaration within its modulevoidsetMemoFunction(boolean isMemoFunction)Set that this is, or is not, a memo function.voidsetPrivate(boolean privateFunction)Set whether this is a private function (as defined in XQuery 1.1)voidsetResultType(SequenceType resultType)Set the required result type of the functionvoidsetStaticContext(QueryModule env)Set the static context for this functionvoidsetSystemId(java.lang.String systemId)Set the system ID of the module containing the functionvoidsetUpdating(boolean isUpdating)Set whether this is an updating function (as defined in XQuery Update)
-
-
-
Method Detail
-
getContainerGranularity
public int getContainerGranularity()
Get the granularity of the container.- Specified by:
getContainerGranularityin interfaceContainer- Returns:
- 0 for a temporary container created during parsing; 1 for a container that operates at the level of an XPath expression; 2 for a container at the level of a global function or template
-
setFunctionName
public void setFunctionName(StructuredQName name)
Set the name of the function- Parameters:
name- the name of the function as a StructuredQName object
-
addArgument
public void addArgument(UserFunctionParameter argument)
Add an argument to the list of arguments- Parameters:
argument- the formal declaration of the argument to be added
-
setResultType
public void setResultType(SequenceType resultType)
Set the required result type of the function- Parameters:
resultType- the declared result type of the function
-
setBody
public void setBody(Expression body)
Set the body of the function- Parameters:
body- the expression forming the body of the function
-
getBody
public Expression getBody()
Get the body of the function- Returns:
- the expression making up the body of the function
-
setSystemId
public void setSystemId(java.lang.String systemId)
Set the system ID of the module containing the function- Parameters:
systemId- the system ID (= base URI) of the module containing the function
-
setLineNumber
public void setLineNumber(int line)
Set the line number of the function declaration within its module- Parameters:
line- the line number of the function declaration
-
setColumnNumber
public void setColumnNumber(int column)
Set the column number of the function declaration- Parameters:
column- the column number of the function declaration
-
getFunctionName
public StructuredQName getFunctionName()
Get the name of the function as a structured QName- Returns:
- the name of the function as a structured QName
-
getDisplayName
public java.lang.String getDisplayName()
Get the name of the function for display in error messages- Returns:
- the name of the function as a lexical QName
-
getIdentificationKey
public java.lang.String 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
public static java.lang.String getIdentificationKey(java.lang.String uri, java.lang.String localName, int arity)Construct what the identification key would be for a function with given URI, local name, and arity- Parameters:
uri- the URI part of the function namelocalName- the local part of the function namearity- the number of arguments in the function- Returns:
- an identifying key
-
getIdentificationKey
public static java.lang.String getIdentificationKey(StructuredQName qName, int arity)
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
public SequenceType getResultType()
Get the result type of the function- Returns:
- the declared result type
-
setExecutable
public void setExecutable(Executable exec)
Set the executable in which this function is contained- Parameters:
exec- the executable
-
getExecutable
public Executable getExecutable()
Get the executable in which this function is contained- Specified by:
getExecutablein interfaceContainer- Returns:
- the executable
-
getLocationProvider
public LocationProvider getLocationProvider()
Get the LocationProvider allowing location identifiers to be resolved.- Specified by:
getLocationProviderin interfaceContainer- Returns:
- the location provider
-
setStaticContext
public void setStaticContext(QueryModule env)
Set the static context for this function- Parameters:
env- the static context for the module in which the function is declared
-
getStaticContext
public StaticContext getStaticContext()
Get the static context for this function- Returns:
- the static context for the module in which the function is declared
-
getArgumentTypes
public SequenceType[] getArgumentTypes()
Get the declared types of the arguments of this function- Returns:
- an array, holding the types of the arguments in order
-
getParameterDefinitions
public UserFunctionParameter[] getParameterDefinitions()
Get the definitions of the arguments to this function- Returns:
- an array of UserFunctionParameter objects, one for each argument
-
getNumberOfArguments
public int getNumberOfArguments()
Get the arity of the function- Returns:
- the arity (the number of arguments)
-
registerReference
public void registerReference(UserFunctionCall ufc)
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
-
setPrivate
public void setPrivate(boolean privateFunction)
Set whether this is a private function (as defined in XQuery 1.1)- Parameters:
privateFunction- true if this is a private function
-
isPrivate
public boolean isPrivate()
Ask whether this is a private function (as defined in XQuery 1.1)- Returns:
- true if this is a private function
-
compile
public void compile() throws XPathExceptionCompile 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
public void optimize() throws XPathExceptionOptimize the body of this function- Throws:
XPathException
-
fixupReferences
public void fixupReferences() throws XPathExceptionFix up references to this function- Throws:
XPathException
-
checkReferences
public void checkReferences(ExpressionVisitor visitor) throws XPathException
Type-check references to this function- Parameters:
visitor- the expression visitor- Throws:
XPathException
-
explain
public void explain(ExpressionPresenter out)
Produce diagnostic output showing the compiled and optimized expression tree for a function- Parameters:
out- the destination to be used
-
getUserFunction
public UserFunction getUserFunction()
Get the callable compiled function contained within this XQueryFunction definition.- Returns:
- the compiled function object
-
getConstructType
public int getConstructType()
Get the type of construct. This will be a constant in classLocation.- Specified by:
getConstructTypein interfaceInstructionInfo- Returns:
- an integer identifying the kind of construct
-
getObjectName
public StructuredQName 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.- Specified by:
getObjectNamein interfaceInstructionInfo- Returns:
- the QName of the object declared or manipulated by this instruction or expression
-
getSystemId
public java.lang.String 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:
getSystemIdin interfaceInstructionInfo- Specified by:
getSystemIdin interfaceorg.xml.sax.Locator- Specified by:
getSystemIdin interfacejavax.xml.transform.SourceLocator- Returns:
- the URI of the containing module
-
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:
getLineNumberin interfaceInstructionInfo- Specified by:
getLineNumberin interfaceorg.xml.sax.Locator- Specified by:
getLineNumberin interfacejavax.xml.transform.SourceLocator- Returns:
- the line number of the expression within the containing module
-
getPublicId
public java.lang.String getPublicId()
Return the public identifier for the current document event.- Specified by:
getPublicIdin interfaceorg.xml.sax.Locator- Specified by:
getPublicIdin interfacejavax.xml.transform.SourceLocator- Returns:
- A string containing the public identifier, or null if none is available.
- See Also:
getSystemId()
-
getColumnNumber
public int getColumnNumber()
Return the column number- Specified by:
getColumnNumberin interfaceorg.xml.sax.Locator- Specified by:
getColumnNumberin interfacejavax.xml.transform.SourceLocator- Returns:
- The column number, or -1 if none is available.
- See Also:
getLineNumber()
-
getSystemId
public java.lang.String getSystemId(long locationId)
Description copied from interface:LocationProviderGet the URI of the document, entity, or module containing a particular location- Specified by:
getSystemIdin interfaceLocationProvider- Parameters:
locationId- identifier of the location in question (as passed down the Receiver pipeline)- Returns:
- the URI of the document, XML entity or module. For a SourceLocationProvider this will be the URI of the document or entity (the URI that would be the base URI if there were no xml:base attributes). In other cases it may identify the query or stylesheet module currently being executed.
-
getLineNumber
public int getLineNumber(long locationId)
Description copied from interface:LocationProviderGet the line number within the document, entity or module containing a particular location- Specified by:
getLineNumberin interfaceLocationProvider- Parameters:
locationId- identifier of the location in question (as passed down the Receiver pipeline)- Returns:
- the line number within the document, entity or module, or -1 if no information is available.
-
getColumnNumber
public int getColumnNumber(long locationId)
Description copied from interface:LocationProviderGet the column number within the document, entity, or module containing a particular location- Specified by:
getColumnNumberin interfaceLocationProvider- Parameters:
locationId- identifier of the location in question (as passed down the Receiver pipeline)- Returns:
- the column number within the document, entity, or module, or -1 if this is not available
-
getNamespaceResolver
public NamespaceResolver getNamespaceResolver()
Get the namespace context of the instruction. This will not always be available, in which case the method returns null.
-
getProperty
public java.lang.Object getProperty(java.lang.String name)
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.- Specified by:
getPropertyin interfaceInstructionInfo- Parameters:
name- The name of the required property- Returns:
- The value of the requested property, or null if the property is not available
-
getProperties
public java.util.Iterator 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.- Specified by:
getPropertiesin interfaceInstructionInfo- Returns:
- an iterator over the properties.
-
getHostLanguage
public int getHostLanguage()
Get the host language (XSLT, XQuery, XPath) used to implement the code in this container- Specified by:
getHostLanguagein interfaceContainer- Returns:
- typically
Configuration.XSLTorConfiguration.XQUERY
-
-