net.sf.saxon.pattern

## Class PatternThatSetsCurrent

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

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

      public class PatternThatSetsCurrent
      extends Pattern

  This class represents a pattern that sets the value of current() to the node being matched, and then wraps another pattern that uses the value of current()
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PatternThatSetsCurrent(Pattern wrappedPattern)`

  - ### 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.
    `Binding` | `getCurrentBinding()` Get the binding of the item being matched by the pattern, that is, the binding that represents the value of the current() function
    `double` | `getDefaultPriority()` Determine the default priority to use if this pattern appears as a match pattern for a template with no explicit priority attribute.
    `int` | `getFingerprint()` Determine the name fingerprint of nodes to which this pattern applies.
    `int` | `getHostLanguage()` Get the host language (XSLT, XQuery, XPath) used to implement the code in this container
    `ItemType` | `getItemType()` Get an ItemType that all the items matching this pattern must satisfy
    `int` | `getNodeKind()` Determine the types of nodes to which this pattern applies.
    `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 item.
    `boolean` | `matchesBeneathAnchor(NodeInfo node, NodeInfo anchor, XPathContext context)` Determine whether this pattern matches a given Node within the subtree rooted at a given anchor node.
    `boolean` | `replaceSubExpression(Expression original, Expression replacement)` Replace a subexpression by a replacement subexpression
    `Pattern` | `simplify(ExpressionVisitor visitor)` Simplify the pattern by applying any context-independent optimisations.
    `String` | `toString()` Get the original pattern text

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

      `bindCurrent, getColumnNumber, getContainerGranularity, getDependencies, getExecutable, getLineNumber, getLocationProvider, getPublicId, getSystemId, make, promote, replaceCurrent, selectNodes, setExecutable, setLineNumber, setOriginalText, setSystemId`

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

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

- - ### Constructor Detail

    - #### PatternThatSetsCurrent

          public PatternThatSetsCurrent(Pattern wrappedPattern)

  - ### Method Detail

    - #### getCurrentBinding

          public Binding getCurrentBinding()

      Get the binding of the item being matched by the pattern, that is, the binding that represents the value of the current() function
      Returns:
        the binding of the item being matched by the pattern

    - #### 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
      Returns:
        the next slot that is free to be allocated

    - #### 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

    - #### matches

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

      Determine whether this Pattern matches the given item. This is the main external interface for matching patterns: it sets current() to the node being tested
      Specified by:
        `matches` in class `Pattern`
      Parameters:
        `item` - The item 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 item 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)

    - #### getItemType

          public ItemType getItemType()

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

    - #### simplify

          public Pattern simplify(ExpressionVisitor visitor)
                           throws XPathException

      Simplify the pattern by applying any context-independent optimisations. Default implementation does nothing.
      Overrides:
        `simplify` in class `Pattern`
      Parameters:
        `visitor` - the expression visitor
      Returns:
        the optimised Pattern
      Throws:
        `XPathException`

    - #### analyze

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

      Type-check the pattern.
      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`

    - #### getNodeKind

          public int getNodeKind()

      Determine the types of nodes to which this pattern applies. Used for optimisation. For patterns that match nodes of several types, return Type.NODE. For patterns that do not match nodes, return -1.
      Overrides:
        `getNodeKind` in class `Pattern`
      Returns:
        the type of node matched by this pattern. e.g. Type.ELEMENT or Type.TEXT

    - #### getFingerprint

          public int getFingerprint()

      Determine the name fingerprint of nodes to which this pattern applies. Used for optimisation.
      Overrides:
        `getFingerprint` in class `Pattern`
      Returns:
        A fingerprint that the nodes must match, or -1 if it can match multiple fingerprints, or it if matches atomic values

    - #### getDefaultPriority

          public double getDefaultPriority()

      Determine the default priority to use if this pattern appears as a match pattern for a template with no explicit priority attribute.
      Overrides:
        `getDefaultPriority` in class `Pattern`
      Returns:
        the default priority for the pattern

    - #### toString

          public String toString()

      Get the original pattern text
      Overrides:
        `toString` in class `Pattern`

    - #### getHostLanguage

          public int getHostLanguage()

      Get the host language (XSLT, XQuery, XPath) used to implement the code in this container
      Specified by:
        `getHostLanguage` in interface `Container`
      Overrides:
        `getHostLanguage` in class `Pattern`
      Returns:
        typically `Configuration.XSLT` or `Configuration.XQUERY`

    - #### 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` - if false, the result is determined strictly according to the W3C "guaranteed streamability rules. If true, Saxon extensions are permitted: that is, constructs may be recognized as motionless by Saxon even if they are not recognized as motionless by the W3C rules.
      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

    - #### matchesBeneathAnchor

          public boolean matchesBeneathAnchor(NodeInfo node,
                                     NodeInfo anchor,
                                     XPathContext context)
                                       throws XPathException

      Determine whether this pattern matches a given Node within the subtree rooted at a given anchor node. This method is used when the pattern is used for streaming.
      Overrides:
        `matchesBeneathAnchor` in class `Pattern`
      Parameters:
        `node` - The NodeInfo representing the Element or other node to be tested against the Pattern
        `anchor` - The anchor node, which must match any AnchorPattern subpattern
        `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)

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