net.sf.saxon.sxpath

## Class XPathDynamicContext

- java.lang.Object
- - net.sf.saxon.sxpath.XPathDynamicContext

-     public class XPathDynamicContext
      extends Object

  This object represents the dynamic XPath execution context for use in the free-standing Saxon XPath API. The dynamic context holds the context item and the values of external variables used by the XPath expression.

  This object is always created via the method `XPathExpression.createDynamicContext(net.sf.saxon.om.Item)`

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `XPathDynamicContext(ItemType contextItemType, XPathContextMajor contextObject, SlotManager stackFrameMap)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `checkExternalVariables(SlotManager stackFrameMap, int numberOfExternals)` Check that all external variables have been given a value
    `CollectionURIResolver` | `getCollectionURIResolver()` Get the CollectionURIResolver used for resolving references to collections.
    `Item` | `getContextItem()` Get the context item
    `ErrorListener` | `getErrorListener()` Get the error listener.
    `UnparsedTextURIResolver` | `getUnparsedTextURIResolver()` Get the URI resolver for unparsed text.
    `URIResolver` | `getURIResolver()` Get the URI resolver.
    `XPathContext` | `getXPathContextObject()` For system use: get the wrapped XPathContext object
    `void` | `setCollectionURIResolver(CollectionURIResolver resolver)` Set the CollectionURIResolver used for resolving collection URIs.
    `void` | `setContextItem(Item item)` Set the context item for evaluation of the XPath Expression
    `void` | `setContextNode(Source source)` Set the context item to a node derived from a supplied Source object.
    `void` | `setErrorListener(ErrorListener listener)` Set the error listener.
    `void` | `setUnparsedTextURIResolver(UnparsedTextURIResolver resolver)` Set an object that will be used to resolve URIs used in fn:unparsed-text() and related functions.
    `void` | `setURIResolver(URIResolver resolver)` Set an object that will be used to resolve URIs used in document(), etc.
    `void` | `setVariable(XPathVariable variable, Sequence value)` Set the value of an external variable used within the XPath expression

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### XPathDynamicContext

          protected XPathDynamicContext(ItemType contextItemType,
                             XPathContextMajor contextObject,
                             SlotManager stackFrameMap)

  - ### Method Detail

    - #### setContextNode

          public void setContextNode(Source source)
                              throws XPathException

      Set the context item to a node derived from a supplied Source object. This may be any implementation of the Source interface recognized by Saxon. Note that the Saxon `NodeInfo` interface, representing a node in a tree, is one such implementation; others include `StreamSource`, `SAXSource`, and `DOMSource`
      Parameters:
        `source` - The source object representing the node that will be used as the context item
      Throws:
        `XPathException` - if a failure occurs reading or parsing a Source object to build an input tree, or if the source is a document that was built under the wrong configuration

    - #### setContextItem

          public void setContextItem(Item item)
                              throws XPathException

      Set the context item for evaluation of the XPath Expression
      Parameters:
        `item` - the context item
      Throws:
        `XPathException` - if the node is in a document that was built under the wrong configuration

    - #### getContextItem

          public Item getContextItem()

      Get the context item
      Returns:
        the context item if there is one, or null otherwise

    - #### setVariable

          public void setVariable(XPathVariable variable,
                         Sequence value)
                           throws XPathException

      Set the value of an external variable used within the XPath expression
      Parameters:
        `variable` - the object representing the variable, as returned by the `XPathEvaluator.declareVariable(String, String)` method. Note that setting the value of a variable does not modify the `XPathVariable` object itself, which means that this method is thread-safe.
        `value` - The value of the variable.
      Throws:
        `XPathException` - if the supplied value does not conform to the required type of the variable; or if the supplied value contains a node that does not belong to this Configuration (or another Configuration that shares the same namePool)

    - #### setURIResolver

          public void setURIResolver(URIResolver resolver)

      Set an object that will be used to resolve URIs used in document(), etc.
      Parameters:
        `resolver` - An object that implements the URIResolver interface, or null.
      Since:
        9.2

    - #### getURIResolver

          public URIResolver getURIResolver()

      Get the URI resolver.
      Returns:
        the user-supplied URI resolver if there is one, or null otherwise.
      Since:
        9.2

    - #### setCollectionURIResolver

          public void setCollectionURIResolver(CollectionURIResolver resolver)

      Set the CollectionURIResolver used for resolving collection URIs. Defaults to the CollectionURIResolver registered with the Configuration
      Parameters:
        `resolver` - the resolver for references to collections
      Since:
        9.4

    - #### getCollectionURIResolver

          public CollectionURIResolver getCollectionURIResolver()

      Get the CollectionURIResolver used for resolving references to collections. If none has been set on the Controller, returns the CollectionURIResolver registered with the Configuration
      Returns:
        the resolver for references to collections
      Since:
        9.4

    - #### setErrorListener

          public void setErrorListener(ErrorListener listener)

      Set the error listener.
      Parameters:
        `listener` - the ErrorListener to be used
      Since:
        9.2

    - #### getErrorListener

          public ErrorListener getErrorListener()

      Get the error listener.
      Returns:
        the ErrorListener in use
      Since:
        9.2

    - #### getXPathContextObject

          public XPathContext getXPathContextObject()

      For system use: get the wrapped XPathContext object
      Returns:
        the underlying XPathContext object

    - #### setUnparsedTextURIResolver

          public void setUnparsedTextURIResolver(UnparsedTextURIResolver resolver)

      Set an object that will be used to resolve URIs used in fn:unparsed-text() and related functions.
      Parameters:
        `resolver` - An object that implements the UnparsedTextURIResolver interface, or null.
      Since:
        9.5

    - #### getUnparsedTextURIResolver

          public UnparsedTextURIResolver getUnparsedTextURIResolver()

      Get the URI resolver for unparsed text.
      Returns:
        the user-supplied unparsed text URI resolver if there is one, or the system-defined one otherwise
      Since:
        9.5

    - #### checkExternalVariables

          protected void checkExternalVariables(SlotManager stackFrameMap,
                                    int numberOfExternals)
                                         throws XPathException

      Check that all external variables have been given a value
      Parameters:
        `stackFrameMap` - describes the stack frame
        `numberOfExternals` - the number of variables that need to be supplied
      Throws:
        `XPathException` - if required variables have not been given a value

Copyright (c) 2004-2013 Saxonica Limited. All rights reserved.