net.sf.saxon.query

Class XQueryFunction

public class XQueryFunction extends Object implements InstructionInfo, Container, Declaration

Constructor Summary
XQueryFunction()
Create an XQuery function
Method Summary
voidaddArgument(UserFunctionParameter argument)
Add an argument to the list of arguments
voidcheckReferences(ExpressionVisitor visitor)
Type-check references to this function
voidcompile()
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 function
voidfixupReferences(StaticContext env)
Fix up references to this function
SequenceType[]getArgumentTypes()
Get the declared types of the arguments of this function
ExpressiongetBody()
Get the body of the function
intgetColumnNumber()
Return the column number
intgetColumnNumber(long locationId)
intgetConstructType()
Get the type of construct.
intgetContainerGranularity()
Get the granularity of the container.
StringgetDisplayName()
Get the name of the function for display in error messages
ExecutablegetExecutable()
Get the executable in which this function is contained
StructuredQNamegetFunctionName()
Get the name of the function as a structured QName
intgetHostLanguage()
Get the host language (XSLT, XQuery, XPath) used to implement the code in this container
StringgetIdentificationKey()
Get an identifying key for this function, which incorporates the URI and local part of the function name plus the arity
static StringgetIdentificationKey(String uri, String localName, int arity)
Construct what the identification key would be for a function with given URI, local name, and arity
static StringgetIdentificationKey(StructuredQName qName, int arity)
Construct what the identification key would be for a function with given URI, local name, and arity
intgetLineNumber()
Get the line number of the instruction in the source stylesheet module.
intgetLineNumber(long locationId)
LocationProvidergetLocationProvider()
Get the LocationProvider allowing location identifiers to be resolved.
NamespaceResolvergetNamespaceResolver()
Get the namespace context of the instruction.
intgetNumberOfArguments()
Get the arity of the function
StructuredQNamegetObjectName()
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 function
IteratorgetProperties()
Get an iterator over all the properties available.
ObjectgetProperty(String name)
Get the value of a particular property of the instruction.
StringgetPublicId()
Return the public identifier for the current document event.
SequenceTypegetResultType()
Get the result type of the function
StaticContextgetStaticContext()
Get the static context for this function
StringgetSystemId()
Get the system identifier (URI) of the source module containing the instruction.
StringgetSystemId(long locationId)
UserFunctiongetUserFunction()
Get the callable compiled function contained within this XQueryFunction definition.
booleanisMemoFunction()
Find out whether this is a memo function
booleanisUpdating()
Ask whether this is an updating function (as defined in XQuery Update)
voidoptimize()
Optimize the body of this function
voidregisterReference(UserFunctionCall ufc)
Register a call on this function
voidsetBody(Expression body)
Set the body of the function
voidsetColumnNumber(int column)
Set the column number of the function declaration
voidsetExecutable(Executable exec)
Set the executable in which this function is contained
voidsetFunctionName(StructuredQName name)
Set the name of the function
voidsetLineNumber(int line)
Set the line number of the function declaration within its module
voidsetMemoFunction(boolean isMemoFunction)
Set that this is, or is not, a memo function.
voidsetResultType(SequenceType resultType)
Set the required result type of the function
voidsetStaticContext(QueryModule env)
Set the static context for this function
voidsetSystemId(String systemId)
Set the system ID of the module containing the function
voidsetUpdating(boolean isUpdating)
Set whether this is an updating function (as defined in XQuery Update)

Constructor Detail

XQueryFunction

public XQueryFunction()
Create an XQuery function

Method Detail

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

checkReferences

public void checkReferences(ExpressionVisitor visitor)
Type-check references to this function

Parameters: visitor the expression visitor

compile

public void 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

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

fixupReferences

public void fixupReferences(StaticContext env)
Fix up references to this function

Parameters: env the static context

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

getBody

public Expression getBody()
Get the body of the function

Returns: the expression making up the body of the function

getColumnNumber

public int getColumnNumber()
Return the column number

Returns: The column number, or -1 if none is available.

See Also: XQueryFunction

getColumnNumber

public int getColumnNumber(long locationId)

getConstructType

public int getConstructType()
Get the type of construct. This will be a constant in class Location.

getContainerGranularity

public int getContainerGranularity()
Get the granularity of the container.

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

getDisplayName

public String getDisplayName()
Get the name of the function for display in error messages

Returns: the name of the function as a lexical QName

getExecutable

public Executable getExecutable()
Get the executable in which this function is contained

Returns: the executable

getFunctionName

public StructuredQName getFunctionName()
Get the name of the function as a structured QName

Returns: the name of the function as a structured QName

getHostLanguage

public int getHostLanguage()
Get the host language (XSLT, XQuery, XPath) used to implement the code in this container

Returns: typically XSLT or XQUERY

getIdentificationKey

public 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 String getIdentificationKey(String uri, 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 name localName the local part of the function name arity the number of arguments in the function

Returns: an identifying key

getIdentificationKey

public static 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 function arity the number of arguments

Returns: an identifying key

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.

getLineNumber

public int getLineNumber(long locationId)

getLocationProvider

public LocationProvider getLocationProvider()
Get the LocationProvider allowing location identifiers to be resolved.

Returns: the location provider

getNamespaceResolver

public NamespaceResolver getNamespaceResolver()
Get the namespace context of the instruction. This will not always be available, in which case the method returns null.

getNumberOfArguments

public int getNumberOfArguments()
Get the arity of the function

Returns: the arity (the number of arguments)

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.

getParameterDefinitions

public UserFunctionParameter[] getParameterDefinitions()
Get the definitions of the arguments to this function

Returns: an array of UserFunctionParameter objects, one for each argument

getProperties

public 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.

getProperty

public Object getProperty(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.

Parameters: name The name of the required property

Returns: The value of the requested property, or null if the property is not available

getPublicId

public String getPublicId()
Return the public identifier for the current document event.

Returns: A string containing the public identifier, or null if none is available.

See Also: XQueryFunction

getResultType

public SequenceType getResultType()
Get the result type of the function

Returns: the declared result type

getStaticContext

public StaticContext getStaticContext()
Get the static context for this function

Returns: the static context for the module in which the function is declared

getSystemId

public 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.

getSystemId

public String getSystemId(long locationId)

getUserFunction

public UserFunction getUserFunction()
Get the callable compiled function contained within this XQueryFunction definition.

Returns: the compiled function object

isMemoFunction

public boolean isMemoFunction()
Find out whether this is a memo function

Returns: true if this is a memo 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

optimize

public void optimize()
Optimize the body of this function

registerReference

public void registerReference(UserFunctionCall ufc)
Register a call on this function

Parameters: ufc a user function call that references this function.

setBody

public void setBody(Expression body)
Set the body of the function

Parameters: body the expression forming the body of the function

setColumnNumber

public void setColumnNumber(int column)
Set the column number of the function declaration

Parameters: column the column number of the function declaration

setExecutable

public void setExecutable(Executable exec)
Set the executable in which this function is contained

Parameters: exec the executable

setFunctionName

public void setFunctionName(StructuredQName name)
Set the name of the function

Parameters: name the name of the function as a StructuredQName object

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

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.

setResultType

public void setResultType(SequenceType resultType)
Set the required result type of the function

Parameters: resultType the declared result type of the function

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

setSystemId

public void setSystemId(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

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