net.sf.saxon.trans
Class Variable

java.lang.Object
  extended bynet.sf.saxon.trans.Variable
All Implemented Interfaces:
Binding, java.io.Serializable, VariableDeclaration

public final class Variable
extends java.lang.Object
implements VariableDeclaration, Binding, java.io.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 StandaloneContext.

See Also:
Serialized Form

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.
 int getNameCode()
          Establish the nameCode of the name of this variable.
 java.lang.String getVariableName()
          Get the name of the variable.
 boolean isAssignable()
          Test whether it is permitted to assign to the variable using the saxon:assign extension element.
 boolean isGlobal()
          Indicate whether the binding is local or global.
static Variable make(QNameValue name, Configuration config)
          Factory method, for use by the declareVariable method of class StandaloneContext
static Variable make(java.lang.String qname, Configuration config)
          Deprecated. since 8.5: use make(QNameValue, Configuration)
 void registerReference(BindingReference ref)
          Method called by the XPath expression parser to register a reference to this variable.
 void setSlotNumber(int slotNumber)
          Set the slot number allocated to this variable
 void setUseStack(boolean useStack)
          Indicate that values of variables are to be found on the stack, not in the Variable object itself
 void setValue(java.lang.Object value)
          Assign a value to the variable.
 void setXPathValue(ValueRepresentation value)
          Assign a value to the variable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

make

public static Variable make(QNameValue name,
                            Configuration config)
Factory method, for use by the declareVariable method of class StandaloneContext


make

public static Variable make(java.lang.String qname,
                            Configuration config)
                     throws XPathException
Deprecated. since 8.5: use make(QNameValue, Configuration)

Factory method, retained for backwards compatibility

Parameters:
qname - the lexical QName of the variable name
Throws:
XPathException

setUseStack

public void setUseStack(boolean useStack)
Indicate that values of variables are to be found on the stack, not in the Variable object itself


isGlobal

public boolean isGlobal()
Indicate 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.

Specified by:
isGlobal in interface Binding

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

setSlotNumber

public void setSlotNumber(int slotNumber)
Set the slot number allocated to this variable

Parameters:
slotNumber -

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

getVariableName

public java.lang.String getVariableName()
Get the name of the variable. Used for diagnostic purposes only.

Specified by:
getVariableName in interface VariableDeclaration
Returns:
the name of the variable, as a string (containing the raw QName)

getNameCode

public int getNameCode()
Establish the nameCode of the name of this variable.

Specified by:
getNameCode in interface VariableDeclaration
Returns:
the nameCode

setValue

public void setValue(java.lang.Object value)
              throws XPathException
Assign a value to the variable. This value may be changed between successive evaluations of a compiled XPath expression that references the variable. If this method is called, the value will be set directly within the Variable object. This is only workable if compilation and execution happen in the same thread. The preferred approach is to set the variable in the stack frame of the XPathContext object.

Parameters:
value - the value of the variable, as a Java object. This is converted to the "best fit" XPath data type.
Throws:
XPathException - if the Java value cannot be converted to an XPath type

setXPathValue

public void setXPathValue(ValueRepresentation value)
Assign a value to the variable. This value may be changed between successive evaluations of a compiled XPath expression that references the variable. If this method is called, the value will be set directly within the Variable object. This is only workable if compilation and execution happen in the same thread. The preferred approach is to set the variable in the stack frame of the XPathContext object.

Parameters:
value - the value of the variable, which must be an instance of a class representing a value in the XPath model.

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

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.

Specified by:
evaluateVariable in interface Binding
Parameters:
context - The dynamic evaluation context
Returns:
The value of the variable