## com.saxonica.extra
Class WatchManager

    java.lang.Object
      net.sf.saxon.event.SequenceReceiver
          net.sf.saxon.event.ProxyReceiver
              com.saxonica.extra.WatchManager

All Implemented Interfaces:
  javax.xml.transform.Result, Receiver, NamespaceResolver

Direct Known Subclasses:
  ConstraintChecker

    public class WatchManager

extends ProxyReceiver
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 Summary
`protected java.util.Stack` `activeWatchStack`
`protected int` `elementStackTop`
`static java.util.List` `EMPTY_WATCH_LIST`
`protected java.util.List` `watchList`

Fields inherited from class net.sf.saxon.event.ProxyReceiver
`nextReceiver`

Fields inherited from class net.sf.saxon.event.SequenceReceiver
`pipelineConfiguration, previousAtomic, systemId`

Fields inherited from interface javax.xml.transform.Result
`PI_DISABLE_OUTPUT_ESCAPING, PI_ENABLE_OUTPUT_ESCAPING`

Constructor Summary
`WatchManager()` Create a WatchManager

Method Summary
`void` `addWatch(Watch watch)` Add a new Watch.
`void` `attribute(int nameCode, int typeCode, java.lang.CharSequence value, int locationId, int properties)` Notify an attribute
`void` `characters(java.lang.CharSequence chars, int locationId, int properties)` Text node
`void` `comment(java.lang.CharSequence chars, int locationId, int properties)` Output a comment
`void` `endElement()` Notify end of element
`java.lang.String` `getURIForPrefix(java.lang.String prefix, boolean useDefault)` Get the namespace URI corresponding to a given prefix.
`java.util.Iterator` `iteratePrefixes()` Get an iterator over all the prefixes declared in this namespace context.
`void` `namespace(int namespaceCode, int properties)` Notify a namespace
`void` `processingInstruction(java.lang.String target, java.lang.CharSequence data, int locationId, int properties)` Processing Instruction
`void` `startContent()` Start element content (called after all the attributes and namespaces have been processed)
`void` `startElement(int nameCode, int typeCode, int locationId, int properties)` Output element start tag

Methods inherited from class net.sf.saxon.event.ProxyReceiver
`append, close, endDocument, getConfiguration, getDocumentLocator, getNamePool, getUnderlyingReceiver, open, setPipelineConfiguration, setSystemId, setUnderlyingReceiver, setUnparsedEntity, startDocument`

Methods inherited from class net.sf.saxon.event.SequenceReceiver
`getPipelineConfiguration, getSystemId`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### elementStackTop

    protected int elementStackTop

### watchList

    protected java.util.List watchList

### activeWatchStack

    protected java.util.Stack activeWatchStack

### EMPTY_WATCH_LIST

    public static final java.util.List EMPTY_WATCH_LIST

Constructor Detail

### WatchManager

    public WatchManager()

  Create a WatchManager

Method Detail

### startElement

    public void startElement(int nameCode,
                             int typeCode,
                             int locationId,
                             int properties)
                      throws XPathException

  Output element start tag

  Specified by:
    `startElement` in interface `Receiver`
  Overrides:
    `startElement` in class `ProxyReceiver`
  Parameters:
    `nameCode` - integer code identifying the name of the element within the name pool.
    `typeCode` - integer code identifying the element's type within the name pool.
    `locationId` - an integer which can be interpreted using a `LocationProvider` to return information such as line number and system ID. If no location information is available, the value zero is supplied.
    `properties` - properties of the element node
  Throws:
    `XPathException`

### attribute

    public void attribute(int nameCode,
                          int typeCode,
                          java.lang.CharSequence value,
                          int locationId,
                          int properties)
                   throws XPathException

  Notify an attribute

  Specified by:
    `attribute` in interface `Receiver`
  Overrides:
    `attribute` in class `ProxyReceiver`
  Parameters:
    `nameCode` - integer identifying the name of the attribute
    `typeCode` - integer identifying the type annotation (ignored)
    `value` - the value of the attribute
    `properties` - additional properties of the attribute
    `locationId` - an integer which can be interpreted using a `LocationProvider` to return information such as line number and system ID. If no location information is available, the value zero is supplied.
  Throws:
    `XPathException` - On any failure to write the attribute

### namespace

    public void namespace(int namespaceCode,
                          int properties)
                   throws XPathException

  Notify a namespace

  Specified by:
    `namespace` in interface `Receiver`
  Overrides:
    `namespace` in class `ProxyReceiver`
  Parameters:
    `namespaceCode` - the namespace code (identifies the prefix and URI)
    `properties` - properties of this event
  Throws:
    `XPathException`

### characters

    public void characters(java.lang.CharSequence chars,
                           int locationId,
                           int properties)
                    throws XPathException

  Text node

  Specified by:
    `characters` in interface `Receiver`
  Overrides:
    `characters` in class `ProxyReceiver`
  Parameters:
    `chars` - The characters
    `locationId` - an integer which can be interpreted using a `LocationProvider` to return information such as line number and system ID. If no location information is available, the value zero is supplied.
    `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`

### endElement

    public void endElement()
                    throws XPathException

  Notify end of element

  Specified by:
    `endElement` in interface `Receiver`
  Overrides:
    `endElement` in class `ProxyReceiver`
  Throws:
    `XPathException`

### comment

    public void comment(java.lang.CharSequence chars,
                        int locationId,
                        int properties)
                 throws XPathException

  Output a comment

  Specified by:
    `comment` in interface `Receiver`
  Overrides:
    `comment` in class `ProxyReceiver`
  Parameters:
    `chars` - The content of the comment
    `locationId` - an integer which can be interpreted using a `LocationProvider` to return information such as line number and system ID. If no location information is available, the value zero is supplied.
    `properties` - Additional information about the comment. The following bits are defined:
  CHECKED
    Comment is known to be legal (e.g. doesn't contain "--")
  Throws:
    `XPathException`

### processingInstruction

    public void processingInstruction(java.lang.String target,
                                      java.lang.CharSequence data,
                                      int locationId,
                                      int properties)
                               throws XPathException

  Processing Instruction

  Specified by:
    `processingInstruction` in interface `Receiver`
  Overrides:
    `processingInstruction` in class `ProxyReceiver`
  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` - an integer which can be interpreted using a `LocationProvider` to return information such as line number and system ID. If no location information is available, the value zero is supplied.
    `properties` - Additional information about the PI. The following bits are defined:
  CHECKED
    Data is known to be legal (e.g. doesn't contain "?>")
  Throws:
    `XPathException`

### startContent

    public void startContent()
                      throws XPathException

  Start element content (called after all the attributes and namespaces have been processed)

  Specified by:
    `startContent` in interface `Receiver`
  Overrides:
    `startContent` in class `ProxyReceiver`
  Throws:
    `XPathException`

### addWatch

    public void addWatch(Watch watch)

  Add a new Watch. This is associated with the current level in the element stack, and is automatically dropped when the current element goes out of scope.

  Parameters:
    `watch` - the watch to be added

### getURIForPrefix

    public java.lang.String getURIForPrefix(java.lang.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 java.util.Iterator 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`

Copyright (c) Saxonica Limited. All rights reserved.