## net.sf.saxon.xpath
Class JAXPVariable

    java.lang.Object
      net.sf.saxon.xpath.JAXPVariable

All Implemented Interfaces:
  Binding, VariableDeclaration

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

An object representing an XPath variable for use in the JAXP XPath API. The object is created at compile time when the parser tries to bind a variable reference; the value is fetched at run-time from the XPathVariableResolver. With this interface, there is no way of reporting a static error if the variable has not been declared.

In Saxon terms, this class is both a VariableDeclaration and a Binding. Unlike a normal VariableDeclaration, it isn't created in advance, but is created on demand when the parser encounters a variable reference. This actually means that if the XPath expression contains two references to the same variable, two VariableDeclarations will be created; however, they will be indistinguishable to the VariableResolver. Acting as a VariableDeclaration, the object goes through the motions of fixing up a binding to a variable reference (in practice, of course, there is exactly one reference to the variable). Acting as a run-time binding, it then evaluates the variable by calling the XPathVariableResolver supplied by the API caller. If no XPathVariableResolver was supplied, an error is reported when a variable is encountered; but if the variable resolver doesn't recognize the variable name, it returns null, which is treated as an empty sequence.

Constructor Summary
`JAXPVariable(QNameValue name, javax.xml.xpath.XPathVariableResolver resolver)` Private constructor: for use only be the protected factory method make()

Method Summary
`ValueRepresentation` `evaluateVariable(XPathContext context)` Get the value of the variable.
`int` `getNameCode()` Establish the fingerprint of the name of this variable.
`java.lang.String` `getVariableName()` Get the name of the variable.
`boolean` `isGlobal()` Indicate whether the binding is local or global.
`void` `registerReference(BindingReference ref)` Method called by the XPath expression parser to register a reference to this variable.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### JAXPVariable

    public JAXPVariable(QNameValue name,
                        javax.xml.xpath.XPathVariableResolver resolver)

  Private constructor: for use only be the protected factory method make()

Method Detail

### 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`

### 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 fingerprint of the name of this variable. Dummy implementation, not used.

  Specified by:
    `getNameCode` in interface `VariableDeclaration`
  Returns:
    -1, always

### 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)
                                         throws XPathException

  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
  Throws:
    `XPathException`