Context
Date: 2016-07-03

com.icl.saxon

## Class Context

- java.lang.Object
- - com.icl.saxon.Context

- All Implemented Interfaces:
    LastPositionFinder, XSLTContext

      public final class Context
      extends java.lang.Object
      implements XSLTContext, LastPositionFinder

  This class represents a context in which an expression is evaluated or a template is executed (as defined in the XSLT specification). It also provides a range of services to node handlers, for example access to the outputter and bindery, and the applyTemplates() function.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `ALL_DEPENDENCIES`
    `static int` | `CONTEXT_DOCUMENT`
    `static int` | `CONTEXT_NODE`
    `static int` | `CONTROLLER`
    `static int` | `CURRENT_NODE`
    `static int` | `LAST`
    `static int` | `NO_DEPENDENCIES`
    `static int` | `POSITION`
    `static int` | `VARIABLES`
    `static int` | `XSLT_CONTEXT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Context()` The default constructor is not used within Saxon itself, but is available to applications (and is used in some samples).
    `Context(Controller c)` Constructor should only be called by the Controller, which acts as a Context factory.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Bindery` | `getBindery()` Get the Bindery used by this Context
    `org.w3c.dom.Node` | `getContextNode()` Get the context node, provided it is a DOM Node
    `NodeInfo` | `getContextNodeInfo()` Get the context node
    `int` | `getContextPosition()` Get the context position (the position of the context node in the context node list)
    `int` | `getContextSize()` Get the context size (the position of the last item in the current node list).
    `Controller` | `getController()` Get the controller for this Context
    `org.w3c.dom.Node` | `getCurrentNode()` Get the current node,provided it is a DOM Node.
    `NodeInfo` | `getCurrentNodeInfo()` Get the current node.
    `XSLTemplate` | `getCurrentTemplate()` Get the current template.
    `XPathException` | `getException()` Get the saved exception value.
    `java.util.Stack` | `getGroupActivationStack()` Get the saxon:group activation stack
    `int` | `getLast()` Get the context size (the position of the last item in the current node list)
    `int` | `getLastPosition()` Get the last position, to be used only when the context object is being used as the last position finder
    `Mode` | `getMode()` Get the current mode (for use by the built-in handlers)
    `Outputter` | `getOutputter()` Get the current Outputter.
    `org.w3c.dom.Document` | `getOwnerDocument()` Get owner Document (enabling extension functions to create new Nodes)
    `int` | `getRememberedNumber(NodeInfo node)` Get the number of a node if it is the last remembered one.
    `Value` | `getReturnValue()` Get the return value from function
    `StaticContext` | `getStaticContext()` Get the static context.
    `ParameterSet` | `getTailRecursion()` Get tail recursion parameters
    `boolean` | `isAtLast()` Determine whether the context position is the same as the context size that is, whether position()=last()
    `Context` | `newContext()` Construct a new context as a copy of another
    `void` | `setContextNode(NodeInfo node)` Set the context node.
    `void` | `setController(Controller c)` Set the controller for this Context
    `void` | `setCurrentNode(NodeInfo node)` Set the current node.
    `void` | `setCurrentTemplate(XSLTemplate template)` Set the current template.
    `void` | `setException(XPathException err)` Set an exception value.
    `void` | `setLast(int last)` Set the context size; this also makes the Context object responisble for returning the last() position.
    `void` | `setLastPositionFinder(LastPositionFinder finder)` Set the LastPositionFinder, another object that will do the work of returning the last() position
    `void` | `setMode(Mode mode)` Set the mode (for use by the built-in handlers)
    `void` | `setPosition(int pos)` Set the context position
    `void` | `setRememberedNumber(NodeInfo node, int number)` Set the last remembered node, for node numbering purposes
    `void` | `setReturnValue(Value value)` Set return value from function
    `void` | `setStaticContext(StaticContext sc)` Set the static context
    `void` | `setTailRecursion(ParameterSet p)` Set tail recursion parameters
    `java.lang.String` | `stringValue(org.w3c.dom.Node n)` Return the String value of a node
    `java.lang.Object` | `systemProperty(java.lang.String namespaceURI, java.lang.String localName)` Get the value of a system property

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

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

- - ### Field Detail

    - #### VARIABLES

          public static final int VARIABLES

      See Also:
        Constant Field Values

    - #### CURRENT_NODE

          public static final int CURRENT_NODE

      See Also:
        Constant Field Values

    - #### CONTEXT_NODE

          public static final int CONTEXT_NODE

      See Also:
        Constant Field Values

    - #### POSITION

          public static final int POSITION

      See Also:
        Constant Field Values

    - #### LAST

          public static final int LAST

      See Also:
        Constant Field Values

    - #### CONTROLLER

          public static final int CONTROLLER

      See Also:
        Constant Field Values

    - #### CONTEXT_DOCUMENT

          public static final int CONTEXT_DOCUMENT

      See Also:
        Constant Field Values

    - #### NO_DEPENDENCIES

          public static final int NO_DEPENDENCIES

      See Also:
        Constant Field Values

    - #### ALL_DEPENDENCIES

          public static final int ALL_DEPENDENCIES

      See Also:
        Constant Field Values

    - #### XSLT_CONTEXT

          public static final int XSLT_CONTEXT

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Context

          public Context()

      The default constructor is not used within Saxon itself, but is available to applications (and is used in some samples). Because some expressions (for example union expressions) cannot execute without a Controller, a system default Controller is created. This is a quick fix, but is not entirely satisfactory, because it's not thread-safe. Applications are encouraged to create a Controller explicitly and use it only within a single thread.

    - #### Context

          public Context(Controller c)

      Constructor should only be called by the Controller, which acts as a Context factory.

  - ### Method Detail

    - #### newContext

          public Context newContext()

      Construct a new context as a copy of another

    - #### setController

          public void setController(Controller c)

      Set the controller for this Context

    - #### getController

          public Controller getController()

      Get the controller for this Context

    - #### getBindery

          public Bindery getBindery()

      Get the Bindery used by this Context

    - #### getOutputter

          public Outputter getOutputter()

      Get the current Outputter. This gives access to the writeStartTag, writeAttribute, and writeEndTag methods
      Returns:
        the current Outputter

    - #### setMode

          public void setMode(Mode mode)

      Set the mode (for use by the built-in handlers)

    - #### getMode

          public Mode getMode()

      Get the current mode (for use by the built-in handlers)

    - #### setContextNode

          public void setContextNode(NodeInfo node)

      Set the context node.
      Note that this has no effect on position() or last(), which must be set separately.
      Parameters:
        `node` - the node that is to be the context node.

    - #### getContextNodeInfo

          public NodeInfo getContextNodeInfo()

      Get the context node
      Returns:
        the context node

    - #### getContextNode

          public org.w3c.dom.Node getContextNode()

      Get the context node, provided it is a DOM Node
      Specified by:
        `getContextNode` in interface `XSLTContext`
      Returns:
        the context node if it is a DOM Node, otherwise null

    - #### setPosition

          public void setPosition(int pos)

      Set the context position

    - #### getContextPosition

          public int getContextPosition()

      Get the context position (the position of the context node in the context node list)
      Specified by:
        `getContextPosition` in interface `XSLTContext`
      Returns:
        the context position (starting at one)

    - #### setLast

          public void setLast(int last)

      Set the context size; this also makes the Context object responisble for returning the last() position.

    - #### setLastPositionFinder

          public void setLastPositionFinder(LastPositionFinder finder)

      Set the LastPositionFinder, another object that will do the work of returning the last() position

    - #### getLast

          public int getLast()
                      throws XPathException

      Get the context size (the position of the last item in the current node list)
      Returns:
        the context size
      Throws:
        `XPathException`

    - #### isAtLast

          public boolean isAtLast()
                           throws XPathException

      Determine whether the context position is the same as the context size that is, whether position()=last()
      Throws:
        `XPathException`

    - #### getContextSize

          public int getContextSize()

      Get the context size (the position of the last item in the current node list). This is the XSLTContext method: it differs from getLast() in that it cannot throw an exception. This method should be called only from within extension functions. If any error occurs, it will be accessible via Context#getException().
      Specified by:
        `getContextSize` in interface `XSLTContext`
      Returns:
        the context size

    - #### getLastPosition

          public int getLastPosition()

      Get the last position, to be used only when the context object is being used as the last position finder
      Specified by:
        `getLastPosition` in interface `LastPositionFinder`

    - #### setCurrentNode

          public void setCurrentNode(NodeInfo node)

      Set the current node. This is the node in the source document currently being processed (e.g. by apply-templates).

    - #### getCurrentNodeInfo

          public NodeInfo getCurrentNodeInfo()

      Get the current node. This is the node in the source document currently being processed (e.g. by apply-templates). It is not necessarily the same as the context node: the context node can change in a sub-expression, the current node cannot.

    - #### getCurrentNode

          public org.w3c.dom.Node getCurrentNode()

      Get the current node,provided it is a DOM Node. This is the node in the source document currently being processed (e.g. by apply-templates). It is not necessarily the same as the context node: the context node can change in a sub-expression, the current node cannot.
      Specified by:
        `getCurrentNode` in interface `XSLTContext`
      Returns:
        the current node if it is a DOM Node; otherwise null.

    - #### setCurrentTemplate

          public void setCurrentTemplate(XSLTemplate template)

      Set the current template. This is used to support xsl:apply-imports

    - #### getCurrentTemplate

          public XSLTemplate getCurrentTemplate()

      Get the current template. This is used to support xsl:apply-imports

    - #### getOwnerDocument

          public org.w3c.dom.Document getOwnerDocument()

      Get owner Document (enabling extension functions to create new Nodes)
      Specified by:
        `getOwnerDocument` in interface `XSLTContext`

    - #### systemProperty

          public java.lang.Object systemProperty(java.lang.String namespaceURI,
                                        java.lang.String localName)

      Get the value of a system property
      Specified by:
        `systemProperty` in interface `XSLTContext`

    - #### stringValue

          public java.lang.String stringValue(org.w3c.dom.Node n)

      Return the String value of a node
      Specified by:
        `stringValue` in interface `XSLTContext`
      Throws:
        `java.lang.IllegalArgumentException` - if it is not a Saxon node

    - #### setStaticContext

          public void setStaticContext(StaticContext sc)

      Set the static context

    - #### getStaticContext

          public StaticContext getStaticContext()

      Get the static context. This is currently available only while processing an extension function

    - #### setException

          public void setException(XPathException err)

      Set an exception value. This is useful when an extension function makes a call such as getContextSize() that causes an error. The error is saved as part of the context, and reported on return from the extension function

    - #### getException

          public XPathException getException()

      Get the saved exception value.

    - #### getGroupActivationStack

          public java.util.Stack getGroupActivationStack()

      Get the saxon:group activation stack

    - #### setRememberedNumber

          public void setRememberedNumber(NodeInfo node,
                                 int number)

      Set the last remembered node, for node numbering purposes

    - #### getRememberedNumber

          public int getRememberedNumber(NodeInfo node)

      Get the number of a node if it is the last remembered one.
      Returns:
        the number of this node if known, else -1.

    - #### setTailRecursion

          public void setTailRecursion(ParameterSet p)

      Set tail recursion parameters

    - #### getTailRecursion

          public ParameterSet getTailRecursion()

      Get tail recursion parameters

    - #### setReturnValue

          public void setReturnValue(Value value)
                              throws javax.xml.transform.TransformerException

      Set return value from function
      Throws:
        `javax.xml.transform.TransformerException`

    - #### getReturnValue

          public Value getReturnValue()

      Get the return value from function