Package net.sf.saxon.expr

## Class XPathContextMajor

- java.lang.Object
- - net.sf.saxon.expr.XPathContextMinor
  - - net.sf.saxon.expr.XPathContextMajor

- All Implemented Interfaces:
    `XPathContext`

      public class XPathContextMajor
      extends XPathContextMinor

  This class represents a "major context" in which an XPath expression is evaluated: a "major context" object allows all aspects of the dynamic context to change, whereas a "minor context" only allows changes to the focus and the destination for push output.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `XPathContextMajor.ThreadManager` | The ThreadManager is used to manage asynchronous execution of xsl:result-document instructions in Saxon-EE.

    - ### Nested classes/interfaces inherited from class net.sf.saxon.expr.XPathContextMinor

      `XPathContextMinor.LastValue`

  - ### Field Summary

    - ### Fields inherited from class net.sf.saxon.expr.XPathContextMinor

      `currentDestination, stackFrame, temporaryOutputState`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `XPathContextMajor​(Controller controller)` | Constructor should only be called by the Controller, which acts as a XPathContext factory.
    `XPathContextMajor​(Item item, Executable exec)` | Constructor for use in free-standing Java applications.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `createThreadManager()` | Create a new thread manager.
    `Sequence[]` | `getAllVariableValues()` | Get a all the variables in the stack frame
    `Component` | `getCurrentComponent()` | Get the current component
    `XPathException` | `getCurrentException()` | Get the current exception (in saxon:catch)
    `GroupIterator` | `getCurrentGroupIterator()` | Get the current group iterator.
    `GroupIterator` | `getCurrentMergeGroupIterator()` | Get the current merge group iterator.
    `Component.M` | `getCurrentMode()` | Get the current mode.
    `RegexIterator` | `getCurrentRegexIterator()` | Get the current regex iterator.
    `Rule` | `getCurrentTemplateRule()` | Get the current template.
    `ErrorReporter` | `getErrorReporter()` | Get the error reporter.
    `ParameterSet` | `getLocalParameters()` | Get the local parameters for the current template call.
    `ContextOriginator` | `getOrigin()` | Get information about the creating expression or other construct.
    `TailCallLoop.TailCallInfo` | `getTailCallInfo()` | Determine whether the body of a function is to be repeated, due to tail-recursive function calls
    `Component` | `getTargetComponent​(int bindingSlot)` | Bind a component reference to a component.
    `XPathContextMajor.ThreadManager` | `getThreadManager()` | Get the thread manager in use for this context.
    `ParameterSet` | `getTunnelParameters()` | Get the tunnel parameters for the current template call.
    `javax.xml.transform.URIResolver` | `getURIResolver()` | Get the URI resolver.
    `XPathContextMajor` | `newContext()` | Construct a new context as a copy of another.
    `static XPathContextMajor` | `newContext​(XPathContextMinor prev)` | Create a new "major" context (one that is capable of holding a stack frame with local variables
    `static XPathContextMajor` | `newThreadContext​(XPathContextMinor prev)` | Make a copy of the supplied context for use in a new thread (typically for an asynchronous xsl:result-document)
    `void` | `openStackFrame​(int numberOfVariables)` | Create a new stack frame large enough to hold a given number of local variables, for which no stack frame map is available.
    `void` | `openStackFrame​(SlotManager map)` | Create a new stack frame for local variables, using the supplied SlotManager to define the allocation of slots to individual variables
    `void` | `requestTailCall​(TailCallLoop.TailCallInfo targetFn, Sequence[] variables)` | Reset the local stack frame.
    `void` | `resetAllVariableValues​(Sequence[] values)` | Overwrite all the variables in the stack frame
    `void` | `resetParameterValues​(Sequence[] values)` | Overwrite all the parameters in the stack frame.
    `void` | `resetStackFrameMap​(SlotManager map, int numberOfParams)` | Reset the stack frame variable map, while reusing the StackFrame object itself.
    `void` | `setCurrentComponent​(Component component)` | Set the current component, that is, the component being evaluated.
    `void` | `setCurrentException​(XPathException exception)` | Set the current exception (in saxon:catch)
    `void` | `setCurrentGroupIterator​(GroupIterator iterator)` | Set the current grouping iterator.
    `void` | `setCurrentMergeGroupIterator​(GroupIterator iterator)` | Set the current merge group iterator.
    `void` | `setCurrentMode​(Component.M mode)` | Set the current mode.
    `void` | `setCurrentRegexIterator​(RegexIterator currentRegexIterator)` | Set the current regex iterator.
    `void` | `setCurrentTemplateRule​(Rule rule)` | Set the current template.
    `void` | `setErrorReporter​(ErrorReporter reporter)` | Set the error reporter.
    `void` | `setLocalParameters​(ParameterSet localParameters)` | Set the local parameters for the current template call.
    `void` | `setOrigin​(ContextOriginator expr)` | Set the creating expression (for use in diagnostics).
    `void` | `setStackFrame​(SlotManager map, Sequence[] variables)` | Set the local stack frame.
    `void` | `setTunnelParameters​(ParameterSet tunnelParameters)` | Set the tunnel parameters for the current template call.
    `void` | `setURIResolver​(javax.xml.transform.URIResolver resolver)` | Set an object that will be used to resolve URIs used in document(), etc.
    `int` | `useLocalParameter​(StructuredQName paramName, int slotNumber, boolean isTunnel)` | Use local parameter.
    `void` | `waitForChildThreads()` | Wait for child threads started under the control of this context to finish.

    - ### Methods inherited from class net.sf.saxon.expr.XPathContextMinor

      `evaluateLocalVariable, getCaller, getConfiguration, getContextItem, getController, getCurrentDateTime, getCurrentIterator, getCurrentOutputUri, getImplicitTimezone, getLast, getNamePool, getStackFrame, getTemporaryOutputState, isAtLast, iterateStackFrames, makeStackFrameMutable, newCleanContext, newMinorContext, setCaller, setCurrentIterator, setCurrentOutputUri, setLocalVariable, setTemporaryOutputState, trackFocus, trackFocusMultithreaded`

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

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

- - ### Constructor Detail

    - #### XPathContextMajor

          public XPathContextMajor​(Controller controller)

      Constructor should only be called by the Controller, which acts as a XPathContext factory.
      Parameters:
        `controller` - the Controller

    - #### XPathContextMajor

          public XPathContextMajor​(Item item,
                                   Executable exec)

      Constructor for use in free-standing Java applications.
      Parameters:
        `item` - the item to use as the initial context item. If this is null, the comtext item is initially undefined (which will cause a dynamic error if it is referenced).
        `exec` - the Executable

  - ### Method Detail

    - #### newContext

          public XPathContextMajor newContext()

      Construct a new context as a copy of another. The new context is effectively added to the top of a stack, and contains a pointer to the previous context.
      Specified by:
        `newContext` in interface `XPathContext`
      Overrides:
        `newContext` in class `XPathContextMinor`
      Returns:
        a new context, created as a copy of this context

    - #### newContext

          public static XPathContextMajor newContext​(XPathContextMinor prev)

      Create a new "major" context (one that is capable of holding a stack frame with local variables
      Parameters:
        `prev` - the previous context (the one causing the new context to be created)
      Returns:
        the new major context

    - #### newThreadContext

          public static XPathContextMajor newThreadContext​(XPathContextMinor prev)

      Make a copy of the supplied context for use in a new thread (typically for an asynchronous xsl:result-document)
      Parameters:
        `prev` - the context to be copied
      Returns:
        the copy of the context

    - #### getThreadManager

          public XPathContextMajor.ThreadManager getThreadManager()

      Get the thread manager in use for this context.
      Specified by:
        `getThreadManager` in interface `XPathContext`
      Overrides:
        `getThreadManager` in class `XPathContextMinor`
      Returns:
        the current thread manager. This will be null if not running XSLT under Saxon-EE

    - #### createThreadManager

          public void createThreadManager()

      Create a new thread manager. This is called when starting an XSLT Transformation, and also when entering a try/catch block. In Saxon-HE it does nothing.

    - #### waitForChildThreads

          public void waitForChildThreads()
                                   throws XPathException

      Wait for child threads started under the control of this context to finish. This is called at the end of the (main thread of a) transformation, and also at the end of the "try" part of a try/catch. The threads affected are those used to implement xsl:result-document instructions.
      Specified by:
        `waitForChildThreads` in interface `XPathContext`
      Overrides:
        `waitForChildThreads` in class `XPathContextMinor`
      Throws:
        `XPathException` - if any of the child threads have failed with a dynamic error.

    - #### getLocalParameters

          public ParameterSet getLocalParameters()

      Get the local parameters for the current template call.
      Specified by:
        `getLocalParameters` in interface `XPathContext`
      Overrides:
        `getLocalParameters` in class `XPathContextMinor`
      Returns:
        the supplied parameters

    - #### setLocalParameters

          public void setLocalParameters​(ParameterSet localParameters)

      Set the local parameters for the current template call.
      Parameters:
        `localParameters` - the supplied parameters

    - #### getTunnelParameters

          public ParameterSet getTunnelParameters()

      Get the tunnel parameters for the current template call.
      Specified by:
        `getTunnelParameters` in interface `XPathContext`
      Overrides:
        `getTunnelParameters` in class `XPathContextMinor`
      Returns:
        the supplied tunnel parameters

    - #### setTunnelParameters

          public void setTunnelParameters​(ParameterSet tunnelParameters)

      Set the tunnel parameters for the current template call.
      Parameters:
        `tunnelParameters` - the supplied tunnel parameters

    - #### setOrigin

          public void setOrigin​(ContextOriginator expr)

      Set the creating expression (for use in diagnostics). The origin is generally set to "this" by the object that creates the new context. It's up to the debugger to determine whether this information is useful. The object will either be an `Expression`, allowing information about the calling instruction to be obtained, or null.

    - #### getOrigin

          public ContextOriginator getOrigin()

      Get information about the creating expression or other construct.

    - #### setStackFrame

          public void setStackFrame​(SlotManager map,
                                    Sequence[] variables)

      Set the local stack frame. This method is used when creating a Closure to support delayed evaluation of expressions. The "stack frame" is actually on the Java heap, which means it can survive function returns and the like.
      Parameters:
        `map` - the SlotManager, which holds static details of the allocation of variables to slots
        `variables` - the array of "slots" to hold the actual variable values. This array will be copied if it is too small to hold all the variables defined in the SlotManager

    - #### resetStackFrameMap

          public void resetStackFrameMap​(SlotManager map,
                                         int numberOfParams)

      Reset the stack frame variable map, while reusing the StackFrame object itself. This is done on a tail call to a different function
      Parameters:
        `map` - the SlotManager representing the stack frame contents
        `numberOfParams` - the number of parameters required on the new stack frame

    - #### getAllVariableValues

          public Sequence[] getAllVariableValues()

      Get a all the variables in the stack frame
      Returns:
        an array holding all the variables, each referenceable by its slot number

    - #### resetAllVariableValues

          public void resetAllVariableValues​(Sequence[] values)

      Overwrite all the variables in the stack frame
      Parameters:
        `values` - an array holding all the variables, each referenceable by its slot number; the caller must ensure this is the correct length (and valid in other ways)

    - #### resetParameterValues

          public void resetParameterValues​(Sequence[] values)

      Overwrite all the parameters in the stack frame. (Used from compiled bytecode)
      Parameters:
        `values` - an array holding all the parameters, each referenceable by its slot number; the caller must ensure this is the correct length (and valid in other ways)

    - #### requestTailCall

          public void requestTailCall​(TailCallLoop.TailCallInfo targetFn,
                                      Sequence[] variables)

      Reset the local stack frame. This method is used when processing a tail-recursive function. Instead of the function being called recursively, the parameters are set to new values and the function body is evaluated repeatedly
      Parameters:
        `targetFn` - the user function being called using tail recursion
        `variables` - the parameter to be supplied to the user function

    - #### getTailCallInfo

          public TailCallLoop.TailCallInfo getTailCallInfo()

      Determine whether the body of a function is to be repeated, due to tail-recursive function calls
      Returns:
        null if no tail call has been requested, or the name of the function to be called otherwise

    - #### openStackFrame

          public void openStackFrame​(SlotManager map)

      Create a new stack frame for local variables, using the supplied SlotManager to define the allocation of slots to individual variables
      Parameters:
        `map` - the SlotManager for the new stack frame

    - #### openStackFrame

          public void openStackFrame​(int numberOfVariables)

      Create a new stack frame large enough to hold a given number of local variables, for which no stack frame map is available. This is used in particular when evaluating match patterns of template rules.
      Parameters:
        `numberOfVariables` - The number of local variables to be accommodated.

    - #### setCurrentMode

          public void setCurrentMode​(Component.M mode)

      Set the current mode.
      Parameters:
        `mode` - the new current mode

    - #### getCurrentMode

          public Component.M getCurrentMode()

      Get the current mode.
      Specified by:
        `getCurrentMode` in interface `XPathContext`
      Overrides:
        `getCurrentMode` in class `XPathContextMinor`
      Returns:
        the current mode. May return null if the current mode is the default mode.

    - #### setCurrentTemplateRule

          public void setCurrentTemplateRule​(Rule rule)

      Set the current template. This is used to support xsl:apply-imports. The caller is responsible for remembering the previous current template and resetting it after use.
      Parameters:
        `rule` - the current template rule, or null to indicate that there is no current template rule

    - #### getCurrentTemplateRule

          public Rule getCurrentTemplateRule()

      Get the current template. This is used to support xsl:apply-imports
      Specified by:
        `getCurrentTemplateRule` in interface `XPathContext`
      Overrides:
        `getCurrentTemplateRule` in class `XPathContextMinor`
      Returns:
        the current template

    - #### setCurrentGroupIterator

          public void setCurrentGroupIterator​(GroupIterator iterator)

      Set the current grouping iterator. This supports the current-group() and current-grouping-key() functions in XSLT 2.0
      Parameters:
        `iterator` - the new current GroupIterator

    - #### getCurrentGroupIterator

          public GroupIterator getCurrentGroupIterator()

      Get the current group iterator. This supports the current-group() and current-grouping-key() functions in XSLT 2.0
      Specified by:
        `getCurrentGroupIterator` in interface `XPathContext`
      Overrides:
        `getCurrentGroupIterator` in class `XPathContextMinor`
      Returns:
        the current grouped collection

    - #### setCurrentMergeGroupIterator

          public void setCurrentMergeGroupIterator​(GroupIterator iterator)

      Set the current merge group iterator. This supports the current-merge-group() and current-merge-key() functions in XSLT 3.0
      Parameters:
        `iterator` - the new current GroupIterator

    - #### getCurrentMergeGroupIterator

          public GroupIterator getCurrentMergeGroupIterator()

      Get the current merge group iterator. This supports the current-merge-group() and current-merge-key() functions in XSLT 3.0
      Specified by:
        `getCurrentMergeGroupIterator` in interface `XPathContext`
      Overrides:
        `getCurrentMergeGroupIterator` in class `XPathContextMinor`
      Returns:
        the current grouped collection

    - #### setCurrentRegexIterator

          public void setCurrentRegexIterator​(RegexIterator currentRegexIterator)

      Set the current regex iterator. This supports the functionality of the regex-group() function in XSLT 2.0.
      Parameters:
        `currentRegexIterator` - the current regex iterator

    - #### getCurrentRegexIterator

          public RegexIterator getCurrentRegexIterator()

      Get the current regex iterator. This supports the functionality of the regex-group() function in XSLT 2.0.
      Specified by:
        `getCurrentRegexIterator` in interface `XPathContext`
      Overrides:
        `getCurrentRegexIterator` in class `XPathContextMinor`
      Returns:
        the current regular expressions iterator

    - #### useLocalParameter

          public int useLocalParameter​(StructuredQName paramName,
                                       int slotNumber,
                                       boolean isTunnel)
                                throws XPathException

      Use local parameter. This is called when a local xsl:param element is processed. If a parameter of the relevant name was supplied, it is bound to the xsl:param element. Otherwise the method returns false, so the xsl:param default will be evaluated
      Specified by:
        `useLocalParameter` in interface `XPathContext`
      Overrides:
        `useLocalParameter` in class `XPathContextMinor`
      Parameters:
        `paramName` - the name of the parameter
        `slotNumber` - the slot number of the parameter on the callee's stack frame
        `isTunnel` - True if a tunnel parameter is required, else false
      Returns:
        ParameterSet.NOT_SUPPLIED, ParameterSet.SUPPLIED, or ParameterSet.SUPPLIED_AND_CHECKED
      Throws:
        `XPathException`

    - #### setURIResolver

          public void setURIResolver​(javax.xml.transform.URIResolver resolver)

      Set an object that will be used to resolve URIs used in document(), etc. This method allows a URIResolver to be set that is local to this particular XPathContext, which is useful when local behaviour is needed, e.g. during schema validation. The URIResolver set in the Controller and in the Configuration are not affected by this call.
      Parameters:
        `resolver` - An object that implements the URIResolver interface, or null.
      Since:
        9.6

    - #### getURIResolver

          public javax.xml.transform.URIResolver getURIResolver()

      Get the URI resolver. This gets the local URIResolver set in the XPathContext if there is one; if not, it gets the URIResolver from the Controller (which itself defaults to the one set in the Configuration).
      Specified by:
        `getURIResolver` in interface `XPathContext`
      Overrides:
        `getURIResolver` in class `XPathContextMinor`
      Returns:
        the user-supplied URI resolver if there is one, or null otherwise.
      Since:
        9.6

    - #### setErrorReporter

          public void setErrorReporter​(ErrorReporter reporter)

      Set the error reporter. The ErrorReporter is set locally to this XPathContext object.
      Parameters:
        `reporter` - the ErrorReporter to be used
      Since:
        9.6. Changed in 10.0 to use the ErrorReporter interface in place of ErrorListener

    - #### getErrorReporter

          public ErrorReporter getErrorReporter()

      Get the error reporter. If no ErrorReporter has been set locally, the ErrorReporter in the Controller is returned; this in turn defaults to the ErrorReporter set in the Configuration.
      Specified by:
        `getErrorReporter` in interface `XPathContext`
      Overrides:
        `getErrorReporter` in class `XPathContextMinor`
      Returns:
        the ErrorReporter in use.
      Since:
        9.6. Changed in 10.0 to use an ErrorReporter rather than ErrorListener

    - #### setCurrentException

          public void setCurrentException​(XPathException exception)

      Set the current exception (in saxon:catch)
      Parameters:
        `exception` - the current exception

    - #### getCurrentException

          public XPathException getCurrentException()

      Get the current exception (in saxon:catch)
      Specified by:
        `getCurrentException` in interface `XPathContext`
      Overrides:
        `getCurrentException` in class `XPathContextMinor`
      Returns:
        the current exception, or null if there is none defined

    - #### getCurrentComponent

          public Component getCurrentComponent()

      Get the current component
      Specified by:
        `getCurrentComponent` in interface `XPathContext`
      Overrides:
        `getCurrentComponent` in class `XPathContextMinor`

    - #### setCurrentComponent

          public void setCurrentComponent​(Component component)

      Set the current component, that is, the component being evaluated. This is used during the evaluation to determine the bindings to other components (such as global variables, functions, and templates) referenced during the evaluation
      Parameters:
        `component` - the current component

    - #### getTargetComponent

          public Component getTargetComponent​(int bindingSlot)

      Bind a component reference to a component. This is used for binding component references (such as function calls, global variable references, or xsl:call-template) across package boundaries. The binding is done dynamically because, in the presence of overridden components, the choice among different components with the same name depends on which package the caller is in.
      Specified by:
        `getTargetComponent` in interface `XPathContext`
      Overrides:
        `getTargetComponent` in class `XPathContextMinor`
      Parameters:
        `bindingSlot` - Binding slots are allocated statically to the external component references in every component: for example, in the case of a template, to all global variable references, named function calls, and named template calls within that template. The binding slot therefore identifies the name of the component that is required; and the selection of an actual component is done by selection from the binding vector of the component currently being executed
      Returns:
        the component to be invoked