Package net.sf.saxon.sxpath
Class XPathVariable
- java.lang.Object
-
- net.sf.saxon.sxpath.XPathVariable
-
- All Implemented Interfaces:
Binding
,LocalBinding
public final class XPathVariable extends java.lang.Object implements LocalBinding
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 classIndependentContext
. 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, net.sf.saxon.om.Sequence)
. 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addReference(VariableReference ref, boolean isLoopingReference)
Method called by the XPath expression parser to register a reference to this variable.Sequence
evaluateVariable(XPathContext context)
Get the value of the variable.Sequence
getDefaultValue()
Get the default value of the variableIntegerValue[]
getIntegerBoundsForVariable()
If the variable is bound to an integer, get the minimum and maximum possible values.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.boolean
isIndexedVariable()
Ask whether the binding is to be indexedstatic XPathVariable
make(StructuredQName name)
Factory method, for use by the declareVariable method of class IndependentContextvoid
setDefaultValue(Sequence defaultValue)
Set a default value for the variable, to be used if no specific value is supplied when the expression is evaluatedvoid
setIndexedVariable()
Say that the bound value has the potential to be indexedvoid
setRequiredType(SequenceType requiredType)
Set the required type of this variable.void
setSlotNumber(int slotNumber)
Set the slot number allocated to this variable.
-
-
-
Method Detail
-
make
public 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
-
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)
-
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 interfaceBinding
- Returns:
- false (always)
-
setRequiredType
public void setRequiredType(SequenceType requiredType)
Set the required type of this variable. If no required type is specified, the typeitem()*
is assumed.- Parameters:
requiredType
- the required type
-
getRequiredType
public SequenceType getRequiredType()
Get the required type of this variable. If no required type has been specified, the typeitem()*
is returned.- Specified by:
getRequiredType
in interfaceBinding
- Returns:
- the required type of the variable
-
getIntegerBoundsForVariable
public IntegerValue[] getIntegerBoundsForVariable()
If the variable is bound to an integer, get the minimum and maximum possible values. Return null if unknown or not applicable- Specified by:
getIntegerBoundsForVariable
in interfaceBinding
- Returns:
- a pair of integers containing the minimum and maximum values for the integer value; or null if the value is not an integer or the range is unknown
-
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
-
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 interfaceLocalBinding
- Returns:
- the slot number on the local stack frame
-
getVariableQName
public StructuredQName getVariableQName()
Get the name of the variable as a QNameValue.- Specified by:
getVariableQName
in interfaceBinding
- Returns:
- the name of the variable, as a QNameValue
-
addReference
public void addReference(VariableReference ref, boolean isLoopingReference)
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:
addReference
in interfaceBinding
- Parameters:
ref
- the variable referenceisLoopingReference
- - true if the reference occurs within a loop, such as the predicate of a filter expression
-
setDefaultValue
public void setDefaultValue(Sequence defaultValue)
Set a default value for the variable, to be used if no specific value is supplied when the expression is evaluated- Parameters:
defaultValue
- the default value for the variable
-
getDefaultValue
public Sequence getDefaultValue()
Get the default value of the variable- Returns:
- the default value if one has been registered, or null otherwise
-
evaluateVariable
public Sequence 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 dynamic context.- Specified by:
evaluateVariable
in interfaceBinding
- Parameters:
context
- The dynamic evaluation context- Returns:
- The value of the variable
-
setIndexedVariable
public void setIndexedVariable()
Say that the bound value has the potential to be indexed- Specified by:
setIndexedVariable
in interfaceLocalBinding
-
isIndexedVariable
public boolean isIndexedVariable()
Ask whether the binding is to be indexed- Specified by:
isIndexedVariable
in interfaceLocalBinding
- Returns:
- true if the variable value can be indexed
-
-