Class WatchManager

java.lang.Object
net.sf.saxon.event.SequenceReceiver
com.saxonica.ee.stream.watch.WatchManager
All Implemented Interfaces:
Result, Receiver, NamespaceResolver
Direct Known Subclasses:
ConstraintChecker

public class WatchManager extends SequenceReceiver implements NamespaceResolver
This class sits on a push pipeline and evaluates the passing element and attribute nodes. One or more Watch objects can be registered with the pipeline at any time; element and attribute events are notified to the active Watch objects. A watch that is added immediately after a startElement call is automatically dropped at the corresponding endElement call. If a Watch matches a startElement call, then it becomes an active Watch; it is automatically deactivated (but not dropped) at the corresponding endElement call.

A Watch is not itself a receiver, but it can nominate a Receiver to receive all events while it is active. It will stop receiving events when it is deactivated.

  • Field Details

  • Constructor Details

    • WatchManager

      public WatchManager(PipelineConfiguration pipe)
      Create a WatchManager
      Parameters:
      pipe - the pipeline configuration
  • Method Details

    • setXPathContext

      public void setXPathContext(XPathContext context)
    • getXPathContext

      public XPathContext getXPathContext()
    • setOutputter

      public void setOutputter(Outputter outputter)
    • getOutputter

      public Outputter getOutputter()
    • setPipelineConfiguration

      public void setPipelineConfiguration(PipelineConfiguration pipelineConfiguration)
      Description copied from interface: Receiver
      Set the pipeline configuration
      Specified by:
      setPipelineConfiguration in interface Receiver
      Overrides:
      setPipelineConfiguration in class SequenceReceiver
      Parameters:
      pipelineConfiguration - the pipeline configuration
    • isSkipValidation

      protected boolean isSkipValidation()
    • append

      public void append(Item item, Location locationId, int copyNamespaces) throws XPathException
      Append an arbitrary item (node or atomic value) to the output
      Specified by:
      append in interface Receiver
      Specified by:
      append in class SequenceReceiver
      Parameters:
      item - the item to be appended
      locationId - the location of the calling instruction, for diagnostics
      copyNamespaces - if the item is an element node, this indicates whether its namespaces need to be copied. Values are ReceiverOption.ALL_NAMESPACES; the default (0) means
      Throws:
      XPathException - if an error occurs
    • close

      public void close() throws XPathException
      Notify the end of the event stream
      Specified by:
      close in interface Receiver
      Throws:
      XPathException - if an error occurs
    • startDocument

      public void startDocument(int properties) throws XPathException
      Start of a document node.
      Specified by:
      startDocument in interface Receiver
      Parameters:
      properties - properties of the document node
      Throws:
      XPathException - if an error occurs
    • startElement

      public void startElement(NodeName elementName, SchemaType typeCode, AttributeMap attributes, NamespaceMap namespaces, Location location, int properties) throws XPathException
      Output element start tag
      Specified by:
      startElement in interface Receiver
      Parameters:
      elementName - the name of the element.
      typeCode - the type annotation of the element.
      attributes - the attributes of this element
      namespaces - the in-scope namespaces of this element: generally this is all the in-scope namespaces, without relying on inheriting namespaces from parent elements
      location - an object providing information about the module, line, and column where the node originated
      properties - bit-significant properties of the element node. If there are no relevant properties, zero is supplied. The definitions of the bits are in class ReceiverOption
      Throws:
      XPathException - if an error occurs
    • restartElement

      public void restartElement(Watch watch) throws XPathException
      During schema validation, the startElement() event is emitted before we can examine all the streamed assertions that might apply to that element. So this method can be used to process a Watch against the most recent start element event, on the basis that we might have missed it the first time round.
      Throws:
      XPathException
    • getDepth

      public int getDepth()
    • getCurrentNode

      public FleetingParentNode getCurrentNode()
    • getCurrentEventNumber

      public long getCurrentEventNumber()
    • addPrearrangedWatches

      protected void addPrearrangedWatches() throws XPathException
      Throws:
      XPathException
    • characters

      public void characters(UnicodeString chars, Location locationId, int properties) throws XPathException
      Text node
      Specified by:
      characters in interface Receiver
      Parameters:
      chars - The characters
      locationId - provides information such as line number and system ID.
      properties - Bit significant value. The following bits are defined:
      DISABLE_ESCAPING
      Disable escaping for this text node
      USE_CDATA
      Output as a CDATA section
      Throws:
      XPathException - if an error occurs
    • endElement

      public void endElement() throws XPathException
      Notify end of element
      Specified by:
      endElement in interface Receiver
      Throws:
      XPathException - if an error occurs
    • endDocument

      public void endDocument() throws XPathException
      Notify the end of a document node
      Specified by:
      endDocument in interface Receiver
      Throws:
      XPathException - if an error occurs
    • comment

      public void comment(UnicodeString chars, Location locationId, int properties) throws XPathException
      Output a comment
      Specified by:
      comment in interface Receiver
      Parameters:
      chars - The content of the comment
      locationId - provides information such as line number and system ID.
      properties - Additional information about the comment.
      Throws:
      XPathException - if an error occurs
    • processingInstruction

      public void processingInstruction(String target, UnicodeString data, Location locationId, int properties) throws XPathException
      Processing Instruction
      Specified by:
      processingInstruction in interface Receiver
      Parameters:
      target - The PI name. This must be a legal name (it will not be checked).
      data - The data portion of the processing instruction
      locationId - provides information such as line number and system ID.
      properties - Additional information about the PI.
      Throws:
      XPathException - if an error occurs
    • setUnparsedEntity

      public void setUnparsedEntity(String name, String systemID, String publicID) throws XPathException
      Notify an unparsed entity URI.
      Specified by:
      setUnparsedEntity in interface Receiver
      Overrides:
      setUnparsedEntity in class SequenceReceiver
      Parameters:
      name - The name of the unparsed entity
      systemID - The system identifier of the unparsed entity
      publicID - The public identifier of the unparsed entity
      Throws:
      XPathException - if an error occurs
    • addWatch

      public void addWatch(Watch watch, boolean autoClose) throws XPathException
      Add a new Watch. This is associated with the current level in the element stack, and is automatically closed and dropped when the current element goes out of scope.
      Parameters:
      watch - the watch to be added
      autoClose - set to true if the watch is to be automatically opened as soon as it is registered, and is to be automatically closed when it goes out of scope.
      Throws:
      XPathException - if any error occurs
    • removeWatch

      public void removeWatch(Watch watch)
      Remove a watch
      Parameters:
      watch - the watch to be removed. No error occurs if the watch is unknown or inactive.
    • getURIForPrefix

      public NamespaceUri getURIForPrefix(String prefix, boolean useDefault)
      Get the namespace URI corresponding to a given prefix. Return null if the prefix is not in scope.
      Specified by:
      getURIForPrefix in interface NamespaceResolver
      Parameters:
      prefix - the namespace prefix. May be the zero-length string, indicating that there is no prefix. This indicates either the default namespace or the null namespace, depending on the value of useDefault.
      useDefault - true if the default namespace is to be used when the prefix is "". If false, the method returns "" when the prefix is "".
      Returns:
      the uri for the namespace, or null if the prefix is not in scope. The "null namespace" is represented by the pseudo-URI "".
    • iteratePrefixes

      public Iterator<String> iteratePrefixes()
      Description copied from interface: NamespaceResolver
      Get an iterator over all the prefixes declared in this namespace context. This will include the default namespace (prefix="") and the XML namespace where appropriate
      Specified by:
      iteratePrefixes in interface NamespaceResolver
      Returns:
      an iterator over all the prefixes for which a namespace binding exists, including the zero-length string to represent the null/absent prefix if it is bound
    • usesTypeAnnotations

      public boolean usesTypeAnnotations()
      Ask whether this Receiver (or the downstream pipeline) makes any use of the type annotations supplied on element and attribute events
      Specified by:
      usesTypeAnnotations in interface Receiver
      Returns:
      true if the Receiver makes any use of this information. If false, the caller may supply untyped nodes instead of supplying the type annotation
    • allowsEarlyExit

      public boolean allowsEarlyExit()
    • getDocumentNode

      public FleetingDocumentNode getDocumentNode()
    • getMultiAccumulatorWatch

      public MultiAccumulatorWatch getMultiAccumulatorWatch()
    • watchAccumulators

      public void watchAccumulators(MultiAccumulatorWatch multiWatch) throws XPathException
      Throws:
      XPathException
    • startGroupingScope

      public WatchManager.GroupingScope startGroupingScope()
      Called during a partitioning for-each-group whenever a new group is started
    • endGroupingScope

      public void endGroupingScope(WatchManager.GroupingScope current) throws XPathException
      Called during a partitioning for-each-group whenever a group is closed
      Throws:
      XPathException - if a failure occurs
    • startCapturingGroupingWatches

      public void startCapturingGroupingWatches(WatchManager.GroupingScope scope)
    • stopCapturingGroupingWatches

      public void stopCapturingGroupingWatches(WatchManager.GroupingScope scope)