net.sf.saxon.pattern

## Class NodeSetPattern

- java.lang.Object
- - net.sf.saxon.pattern.Pattern
  - - net.sf.saxon.pattern.NodeSetPattern

- All Implemented Interfaces:
    Serializable, SourceLocator, Container, PatternFinder

      public class NodeSetPattern
      extends Pattern

  A NodeSetPattern is a pattern based on an expression that is evaluated to return a set of nodes; a node matches the pattern if it is a member of this node-set.

  In XSLT 2.0 there are two forms of NodeSetPattern allowed, represented by calls on the id() and key() functions. In XSLT 3.0, additional forms are allowed, for example a variable reference, and a call to the doc() function. This class provides the general capability to use any expression at the head of a pattern. This is used also to support streaming, where streaming XPath expressions are mapped to patterns.

  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Expression` | `expression`
    `protected ItemType` | `itemType`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NodeSetPattern(Expression exp)` Create a node-set pattern.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `allocateSlots(SlotManager slotManager, int nextFree)` Allocate slots to any variables used within the pattern
    `Pattern` | `analyze(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType)` Type-check the pattern.
    `boolean` | `equals(Object other)` Determine whether this pattern is the same as another pattern
    `int` | `getDependencies()` Get the dependencies of the pattern.
    `ItemType` | `getItemType()` Get a NodeTest that all the nodes matching this pattern must satisfy
    `int` | `getNodeKind()` Determine the type of nodes to which this pattern applies.
    `int` | `hashCode()` Hashcode supporting equals()
    `boolean` | `isMotionless(boolean allowExtensions)` Test whether a pattern is motionless, that is, whether it can be evaluated against a node without repositioning the input stream.
    `Iterator<Expression>` | `iterateSubExpressions()` Iterate over the subexpressions within this pattern
    `boolean` | `matches(Item item, XPathContext context)` Determine whether this Pattern matches the given Node
    `void` | `promote(PromotionOffer offer, Expression parent)` Offer promotion for subexpressions within this pattern.
    `boolean` | `replaceSubExpression(Expression original, Expression replacement)` Replace a subexpression by a replacement subexpression

    - ### Methods inherited from class net.sf.saxon.pattern.Pattern

      `bindCurrent, getColumnNumber, getContainerGranularity, getDefaultPriority, getExecutable, getFingerprint, getHostLanguage, getLineNumber, getLocationProvider, getPublicId, getSystemId, make, matchesBeneathAnchor, replaceCurrent, selectNodes, setExecutable, setLineNumber, setOriginalText, setSystemId, simplify, toString`

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### expression

          protected Expression expression

    - #### itemType

          protected ItemType itemType

  - ### Constructor Detail

    - #### NodeSetPattern

          public NodeSetPattern(Expression exp)

      Create a node-set pattern.
      Parameters:
        `exp` - an expression that can be evaluated to return a node-set; a node matches the pattern if it is present in this node-set. The expression must not depend on the focus, though it can depend on other aspects of the dynamic context such as local or global variables.

  - ### Method Detail

    - #### analyze

          public Pattern analyze(ExpressionVisitor visitor,
                        ExpressionVisitor.ContextItemType contextItemType)
                          throws XPathException

      Type-check the pattern. Default implementation does nothing. This is only needed for patterns that contain variable references or function calls.
      Overrides:
        `analyze` in class `Pattern`
      Parameters:
        `visitor` - the expression visitor
        `contextItemType` - the type of the context item at the point where the pattern is defined. Set to null if it is known that the context item is undefined.
      Returns:
        the optimised Pattern
      Throws:
        `XPathException`

    - #### getDependencies

          public int getDependencies()

      Get the dependencies of the pattern. The only possible dependency for a pattern is on local variables. This is analyzed in those patterns where local variables may appear.
      Overrides:
        `getDependencies` in class `Pattern`
      Returns:
        the dependencies, as a bit-significant mask

    - #### iterateSubExpressions

          public Iterator<Expression> iterateSubExpressions()

      Iterate over the subexpressions within this pattern
      Overrides:
        `iterateSubExpressions` in class `Pattern`
      Returns:
        an iterator over the subexpressions. Default implementation returns an empty sequence

    - #### promote

          public void promote(PromotionOffer offer,
                     Expression parent)
                       throws XPathException

      Offer promotion for subexpressions within this pattern. The offer will be accepted if the subexpression is not dependent on the factors (e.g. the context item) identified in the PromotionOffer. By default the offer is not accepted - this is appropriate in the case of simple expressions such as constant values and variable references where promotion would give no performance advantage. This method is always called at compile time.

      Unlike the corresponding method on `Expression`, this method does not return anything: it can make internal changes to the pattern, but cannot return a different pattern. Only certain kinds of promotion are applicable within a pattern: specifically, promotions affecting local variable references within the pattern.

      Overrides:
        `promote` in class `Pattern`
      Parameters:
        `offer` - details of the offer, for example the offer to move expressions that don't depend on the context to an outer level in the containing expression
        `parent` -
      Throws:
        `XPathException` - if any error is detected

    - #### replaceSubExpression

          public boolean replaceSubExpression(Expression original,
                                     Expression replacement)

      Replace a subexpression by a replacement subexpression
      Overrides:
        `replaceSubExpression` in class `Pattern`
      Parameters:
        `original` - the expression to be replaced
        `replacement` - the new expression to be inserted in its place
      Returns:
        true if the replacement was carried out

    - #### isMotionless

          public boolean isMotionless(boolean allowExtensions)

      Test whether a pattern is motionless, that is, whether it can be evaluated against a node without repositioning the input stream. This is a necessary condition for patterns used as the match pattern of a streamed template rule.
      Overrides:
        `isMotionless` in class `Pattern`
      Parameters:
        `allowExtensions` -
      Returns:
        true if the pattern is motionless, that is, if it can be evaluated against a streamed node without changing the position in the streamed input file

    - #### allocateSlots

          public int allocateSlots(SlotManager slotManager,
                          int nextFree)

      Allocate slots to any variables used within the pattern
      Overrides:
        `allocateSlots` in class `Pattern`
      Parameters:
        `slotManager` - the slot manager representing the stack frame for local variables
        `nextFree` - the next slot that is free to be allocated @return the next slot that is free to be allocated
      Returns:
        the next slot that is free to be allocated

    - #### matches

          public boolean matches(Item item,
                        XPathContext context)
                          throws XPathException

      Determine whether this Pattern matches the given Node
      Specified by:
        `matches` in class `Pattern`
      Parameters:
        `item` - The NodeInfo representing the Element or other node to be tested against the Pattern
        `context` - The dynamic context. Only relevant if the pattern uses variables, or contains calls on functions such as document() or key().
      Returns:
        true if the node matches the Pattern, false otherwise
      Throws:
        `XPathException` - if an error occurs while matching the pattern (the caller will usually treat this the same as a false result)

    - #### getNodeKind

          public int getNodeKind()

      Determine the type of nodes to which this pattern applies.
      Overrides:
        `getNodeKind` in class `Pattern`
      Returns:
        Type.NODE (may be overridden in subclasses)

    - #### getItemType

          public ItemType getItemType()

      Get a NodeTest that all the nodes matching this pattern must satisfy
      Specified by:
        `getItemType` in class `Pattern`
      Returns:
        an ItemType, as specific as possible, which all the matching items satisfy

    - #### equals

          public boolean equals(Object other)

      Determine whether this pattern is the same as another pattern
      Overrides:
        `equals` in class `Object`
      Parameters:
        `other` - the other object

    - #### hashCode

          public int hashCode()

      Hashcode supporting equals()
      Overrides:
        `hashCode` in class `Object`

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