Class AnchorPattern

  • All Implemented Interfaces:
    ExportAgent, Locatable, IdentityComparable, Traceable
    Direct Known Subclasses:
    CurrentGroupPattern

    public class AnchorPattern
    extends Pattern
    This is a special pattern that matches the "anchor node". It is used for the selectors that arise when evaluating XPath expressions in streaming mode; the anchor node is the context node for the streamed XPath evaluation. Given a streamed evaluation of an expression such as ./BOOKS/BOOK/PRICE, the way we evaluate this is to turn it into a pattern, which is then tested against all descendant nodes. Conceptually the pattern is $A/BOOKS/BOOK/PRICE, where $A is referred to as the anchor node. When we evaluate the pattern against (say) a PRICE element, the match will only succeed if the name of the element is "PRICE" and its ancestors are, in order, a BOOK element, a BOOKS element, and the anchor node $A.
    • Constructor Detail

      • AnchorPattern

        protected AnchorPattern()
    • Method Detail

      • getUType

        public UType getUType()
        Get a UType indicating which kinds of items this Pattern can match.
        Specified by:
        getUType in class Pattern
        Returns:
        a UType indicating all the primitive types of item that the pattern can match.
      • typeCheck

        public Pattern typeCheck​(ExpressionVisitor visitor,
                                 ContextItemStaticInfo contextItemType)
                          throws XPathException
        Type-check the pattern.
        Overrides:
        typeCheck 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 - if an error is discovered during this phase (typically a type error)
      • 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)
      • matches

        public boolean matches​(Item item,
                               XPathContext context)
                        throws XPathException
        Determine whether this Pattern matches the given Node. 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 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)
      • getItemType

        public ItemType getItemType()
        Get a NodeTest that all the nodes matching this pattern must satisfy
        Specified by:
        getItemType in class Pattern
        Returns:
        a NodeTest, as specific as possible, which all the matching nodes satisfy
      • reconstruct

        public java.lang.String reconstruct()
        Description copied from class: Pattern
        Reconstruct a string representation of the pattern from its compiled form, in cases where the original text is not available
        Overrides:
        reconstruct in class Pattern
      • export

        public void export​(ExpressionPresenter presenter)
                    throws XPathException
        Description copied from class: Expression
        Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.
        Specified by:
        export in interface ExportAgent
        Specified by:
        export in class Pattern
        Parameters:
        presenter - the expression presenter used to display the structure
        Throws:
        XPathException - if the export fails, for example if an expression is found that won't work in the target environment.
      • copy

        public Pattern copy​(RebindingMap rebindings)
        Copy an AnchorPattern. Since there is only one, return the same.
        Specified by:
        copy in class Pattern
        Parameters:
        rebindings - variables that need to be re-bound
        Returns:
        the original nodeTest