com.saxonica.xslt3.instruct

## Class AccumulatorManagerPE

- java.lang.Object
- - com.saxonica.xslt3.instruct.AccumulatorManagerPE

- All Implemented Interfaces:
    Serializable, FunctionLibrary, IAccumulatorManager
  Direct Known Subclasses:
    AccumulatorManagerEE

      public class AccumulatorManagerPE
      extends Object
      implements IAccumulatorManager, FunctionLibrary

  Manager for accumulator functions (XSLT 3.0). Like the KeyManager, this is able to maintain data for the same accumulator in multiple executions of a stylesheet: the accumulator data is designed to be available for garbage collection if either the document or the stylesheet is no longer needed. This class also performs the role of a function library, handling requests to bind the two accumulator functions.
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Map<StructuredQName,Accumulator>` | `map`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AccumulatorManagerPE()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addAccumulator(Accumulator acc)` Register an accumulator with the manager
    `Expression` | `bind(StructuredQName functionName, int arity, Expression[] staticArgs, StaticContext env, Container container)` Bind a function call to a function in this library
    `FunctionLibrary` | `copy()` Copy this function library
    `AccumulatorData` | `getAccumulatorData(DocumentInfo doc, Accumulator acc, XPathContext context)` Get the data relating to a particular accumulator for a particular unstreamed document tree
    `FunctionLibrary` | `getAccumulatorFunctionLibrary()` Get the library of accumulator functions
    `FunctionItem` | `getFunctionItem(StructuredQName functionName, int arity, StaticContext staticContext)` Test whether a function with a given name and arity is available; if so, return a function item that can be dynamically called.
    `boolean` | `isAvailable(StructuredQName functionName, int arity)` Test whether a function with a given name and arity is available
    `boolean` | `isEmpty()` Ask whether any accumulators exist
    `protected AccumulatorFunctionCallPE` | `newAccumulatorFunctionCall(Accumulator acc, boolean isPostDescent)`

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

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

- - ### Field Detail

    - #### map

          protected Map<StructuredQName,Accumulator> map

  - ### Constructor Detail

    - #### AccumulatorManagerPE

          public AccumulatorManagerPE()

  - ### Method Detail

    - #### getAccumulatorFunctionLibrary

          public FunctionLibrary getAccumulatorFunctionLibrary()

      Get the library of accumulator functions
      Specified by:
        `getAccumulatorFunctionLibrary` in interface `IAccumulatorManager`
      Returns:
        this object, which itself implements the function library

    - #### addAccumulator

          public void addAccumulator(Accumulator acc)

      Register an accumulator with the manager
      Parameters:
        `acc` - the accumulator to be registered

    - #### bind

          public Expression bind(StructuredQName functionName,
                        int arity,
                        Expression[] staticArgs,
                        StaticContext env,
                        Container container)
                          throws XPathException

      Bind a function call to a function in this library
      Specified by:
        `bind` in interface `FunctionLibrary`
      Parameters:
        `functionName` - the QName of the function being called
        `arity` -
        `staticArgs` - The expressions supplied statically in arguments to the function call. The length of this array represents the arity of the function. The intention is that the static type of the arguments (obtainable via getItemType() and getCardinality()) may be used as part of the binding algorithm. In some cases it may be possible for the function to be pre-evaluated at compile time, for example if these expressions are all constant values.

        The conventions of the XPath language demand that the results of a function depend only on the values of the expressions supplied as arguments, and not on the form of those expressions. For example, the result of f(4) is expected to be the same as f(2+2). The actual expression is supplied here to enable the binding mechanism to select the most efficient possible implementation (including compile-time pre-evaluation where appropriate).

        `env` - The static context of the function call
        `container` - The container for the newly created Expression
      Returns:
        a function call expression, which in this case will be an AccumulatorFunctionCallPE object
      Throws:
        `XPathException`

    - #### newAccumulatorFunctionCall

          protected AccumulatorFunctionCallPE newAccumulatorFunctionCall(Accumulator acc,
                                                             boolean isPostDescent)

    - #### getFunctionItem

          public FunctionItem getFunctionItem(StructuredQName functionName,
                                     int arity,
                                     StaticContext staticContext)
                                       throws XPathException

      Test whether a function with a given name and arity is available; if so, return a function item that can be dynamically called.

      This supports the function-lookup() function in XPath 3.0.

      Specified by:
        `getFunctionItem` in interface `FunctionLibrary`
      Parameters:
        `functionName` - the qualified name of the function being called
        `arity` - The number of arguments.
        `staticContext` - the static context to be used by the function, in the event that it is a system function with dependencies on the static context
      Returns:
        if a function of this name and arity is available for calling, then a corresponding function item; or null if the function does not exist
      Throws:
        `XPathException` - in the event of certain errors, for example attempting to get a function that is private

    - #### isAvailable

          public boolean isAvailable(StructuredQName functionName,
                            int arity)

      Test whether a function with a given name and arity is available

      This supports the function-available() function in XSLT.

      Specified by:
        `isAvailable` in interface `FunctionLibrary`
      Parameters:
        `functionName` - the qualified name of the function being called
        `arity` - The number of arguments.
      Returns:
        true if a function of this name and arity is available for calling

    - #### copy

          public FunctionLibrary copy()

      Copy this function library
      Specified by:
        `copy` in interface `FunctionLibrary`
      Returns:
        a copy

    - #### isEmpty

          public boolean isEmpty()

      Ask whether any accumulators exist
      Returns:
        true if no accumulators have been registered

    - #### getAccumulatorData

          public AccumulatorData getAccumulatorData(DocumentInfo doc,
                                           Accumulator acc,
                                           XPathContext context)
                                             throws XPathException

      Get the data relating to a particular accumulator for a particular unstreamed document tree
      Parameters:
        `doc` - the source document tree in question
        `acc` - the required accumulator
        `context` - the XPath dynamic evaluation context
      Returns:
        a data structure holding the evaluated values of the accumulator for this source document
      Throws:
        `XPathException` - if any dynamic error occurs

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