net.sf.saxon.sxpath

Class XPathVariable

Implemented Interfaces:
Binding, Serializable, VariableDeclaration

public final class XPathVariable
extends java.lang.Object
implements VariableDeclaration, Binding, Serializable

An object representing an XPath variable for use in the standalone XPath API. The object can only be created by calling the declareVariable method of class IndependentContext. Note that once declared, this object is thread-safe: it does not hold the actual variable value, which means it can be used with any number of evaluations of a given XPath expression, in series or in parallel.

A variable can be given a value by calling XPathDynamicContext.setVariable(XPathVariable,ValueRepresentation). Note that the value of the variable is not held in the XPathVariable object, but in the XPathDynamicContext, which means that the XPathVariable itself can be used in multiple threads.

Method Summary

ValueRepresentation
evaluateVariable(XPathContext context)
Get the value of the variable.
int
getLocalSlotNumber()
If this is a local variable held on the local stack frame, return the corresponding slot number.
SequenceType
getRequiredType()
Get the required type of this variable.
StructuredQName
getVariableQName()
Get the name of the variable as a QNameValue.
boolean
isAssignable()
Test whether it is permitted to assign to the variable using the saxon:assign extension element.
boolean
isGlobal()
Ask whether the binding is local or global.
protected static XPathVariable
make(StructuredQName name)
Factory method, for use by the declareVariable method of class IndependentContext
void
registerReference(BindingReference ref)
Method called by the XPath expression parser to register a reference to this variable.
void
setRequiredType(SequenceType requiredType)
Set the required type of this variable.
void
setSlotNumber(int slotNumber)
Set the slot number allocated to this variable.

Method Details

evaluateVariable

public ValueRepresentation evaluateVariable(XPathContext context)
Get the value of the variable. This method is used by the XPath execution engine to retrieve the value. Note that the value is not held within the variable itself, but within the dunamic context.
Specified by:
evaluateVariable in interface Binding
Parameters:
context - The dynamic evaluation context
Returns:
The value of the variable

getLocalSlotNumber

public int getLocalSlotNumber()
If this is a local variable held on the local stack frame, return the corresponding slot number. In other cases, return -1.
Specified by:
getLocalSlotNumber in interface Binding

getRequiredType

public SequenceType getRequiredType()
Get the required type of this variable. If no required type has been specified, the type item()* is returned.
Specified by:
getRequiredType in interface Binding
Returns:
the required type of the variable

getVariableQName

public StructuredQName getVariableQName()
Get the name of the variable as a QNameValue.
Specified by:
getVariableQName in interface VariableDeclaration
getVariableQName in interface Binding
Returns:
the name of the variable, as a QNameValue

isAssignable

public final boolean isAssignable()
Test whether it is permitted to assign to the variable using the saxon:assign extension element. This will only be for an XSLT global variable where the extra attribute saxon:assignable="yes" is present.
Specified by:
isAssignable in interface Binding
Returns:
false (always)

isGlobal

public boolean isGlobal()
Ask whether the binding is local or global. A global binding is one that has a fixed value for the life of a query or transformation; any other binding is local. An XPath variable is treated as a local variable (largely because it is held on the stack frame)
Specified by:
isGlobal in interface Binding
Returns:
false (always)

make

protected static XPathVariable make(StructuredQName name)
Factory method, for use by the declareVariable method of class IndependentContext
Parameters:
name - the name of the variable to create
Returns:
the constructed XPathVariable

registerReference

public void registerReference(BindingReference ref)
Method called by the XPath expression parser to register a reference to this variable. This method should not be called by users of the API.
Specified by:
registerReference in interface VariableDeclaration

setRequiredType

public void setRequiredType(SequenceType requiredType)
Set the required type of this variable. If no required type is specified, the type item()* is assumed.
Parameters:
requiredType - the required type

setSlotNumber

public void setSlotNumber(int slotNumber)
Set the slot number allocated to this variable. This method is for internal use.
Parameters:
slotNumber - the slot number to be allocated