net.sf.saxon.instruct
Class UserFunction

java.lang.Object
  |
  +--net.sf.saxon.instruct.UserFunction
All Implemented Interfaces:
CallableFunction, InstructionInfo, java.io.Serializable, javax.xml.transform.SourceLocator

public final class UserFunction
extends java.lang.Object
implements CallableFunction, java.io.Serializable, InstructionInfo, javax.xml.transform.SourceLocator

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:
Serialized Form

Constructor Summary
UserFunction(Expression body)
           
 
Method Summary
 Value call(Value[] actualArgs, Controller controller)
          Call this function.
 Value call(Value[] actualArgs, Controller controller, boolean evaluateTailCalls)
          Call this function.
 int getColumnNumber()
           
 java.lang.String getFunctionName()
          Get the name of the function, for diagnostics
 java.lang.String getInstructionName()
          Get the name of the instruction.
 int getLineNumber()
          Get the line number of the instruction in the source stylesheet module.
 java.util.HashMap getProperties()
          Get all the properties of the instruction.
 java.lang.Object getProperty(java.lang.String propertyName)
          Get the value of a particular property of the instruction.
 java.lang.String getPublicId()
           
 java.lang.String getSystemId()
          Get the system identifier (URI) of the source stylesheet module containing the instruction.
 void setFunctionName(java.lang.String name)
           
 void setLineNumber(int lineNumber)
           
 void setMemoFunction(boolean isMemo)
           
 void setSystemId(java.lang.String systemId)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserFunction

public UserFunction(Expression body)
Method Detail

setLineNumber

public void setLineNumber(int lineNumber)

setSystemId

public void setSystemId(java.lang.String systemId)

getLineNumber

public int getLineNumber()
Description copied from interface: InstructionInfo
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 interface InstructionInfo

getSystemId

public java.lang.String getSystemId()
Description copied from interface: InstructionInfo
Get the system identifier (URI) of the source stylesheet 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 interface InstructionInfo

getColumnNumber

public int getColumnNumber()
Specified by:
getColumnNumber in interface javax.xml.transform.SourceLocator

getPublicId

public java.lang.String getPublicId()
Specified by:
getPublicId in interface javax.xml.transform.SourceLocator

getInstructionName

public java.lang.String getInstructionName()
Description copied from interface: InstructionInfo
Get the name of the instruction. This will normally be the name of an XSLT instruction, a literal result element, or an extension element. The name is passed in a form suitable for display to the user: it will generally be a QName, but this is not guaranteed. Some instructions may be internally generated by the Saxon compiler, in which case the name might not relate to anything obvious in the source stylesheet

Specified by:
getInstructionName in interface InstructionInfo

getProperty

public java.lang.Object getProperty(java.lang.String propertyName)
Description copied from interface: InstructionInfo
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:
getProperty in interface InstructionInfo
Parameters:
propertyName - 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.HashMap getProperties()
Description copied from interface: InstructionInfo
Get all the properties of the instruction. Properties of XSLT instructions are generally known by the name of the stylesheet attribute that defines them.

Specified by:
getProperties in interface InstructionInfo
Returns:
a HashMap containing all the properties of this instruction.

setMemoFunction

public void setMemoFunction(boolean isMemo)

setFunctionName

public void setFunctionName(java.lang.String name)

getFunctionName

public java.lang.String getFunctionName()
Description copied from interface: CallableFunction
Get the name of the function, for diagnostics

Specified by:
getFunctionName in interface CallableFunction
Returns:
the function name, as a lexical QName

call

public Value call(Value[] actualArgs,
                  Controller controller,
                  boolean evaluateTailCalls)
           throws javax.xml.transform.TransformerException
Call this function.

Specified by:
call in interface CallableFunction
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 a Closure 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.
evaluateTailCalls - if true, then any function calls contained in the body of the function are evaluated in the normal way, whether or not they are marked as tail calls. If the argument is false, then tail calls are not evaluated, and instead a FunctionCallPackage is returned containing the information needed to evaluate the function. The caller must then be prepared to deal with this returned value by evaluating the packaged function call (which may return further packaged function calls, and so on).
Returns:
a Value representing the result of the function.
javax.xml.transform.TransformerException

call

public Value call(Value[] actualArgs,
                  Controller controller)
           throws javax.xml.transform.TransformerException
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 a Closure 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 calling XQueryExpression.getController(). 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.
javax.xml.transform.TransformerException