## com.saxonica.validate
Class SelectorWatch

    java.lang.Object
      com.saxonica.validate.AbstractWatch
          com.saxonica.validate.SelectorWatch

All Implemented Interfaces:
  Watch

Direct Known Subclasses:
  KeySelectorWatch, RefSelectorWatch

    public abstract class SelectorWatch

extends AbstractWatch
implements Watch

A Watch represents a class that is interested in looking at nodes for the purpose of evaluating uniqueness and key constraints. A SelectorWatch looks for the nodes that match the selector in a unique, key, or keyref constraint. There are two concrete subclasses: one for key/unique, the other for keyref

Constructor Summary
`SelectorWatch(ConstraintChecker checker, IdentityConstraint uniqueConstraint)`

Method Summary
`void` `addFieldValue(Value[] currentRow, int column, Value value, boolean nillableElement, long locationId)` The addFieldValue method is a callback from the FieldWatch created when this SelectorWatch is activated.
`protected void` `checkRow(Value[] currentRow, boolean isTarget, int locationId)` Method to check that a row (that is, the collection of fields corresponding to one selected node) is valid.
`void` `close()` The close() method is called immediately before the Watch is destroyed, that is, when the element whose declaration scopes the constraint implemented by this Watch goes out of scope.
`protected String` `displayRow(Value[] row)` Internal method to display the contents of a row, for diagnostics
`void` `endSelectedParentNode(int locationId)` Signal that the endElement event has occurred for the element whose startElement event caused the Watch to be activated.
`IdentityConstraint` `getIdentityConstraint()` Get the identityConstraint implemented by this SelectorWatch
`protected void` `reportValidationError(ValidationException err, long locationId)` Report a validation error
`protected void` `reportValidationError(ValidationException err, SourceLocator locator)` Report a validation error
`Receiver` `startSelectedParentNode(FleetingNode node, int locationId)` Signal that an element has been found that matches the selection that this Watch is looking for.

Methods inherited from class com.saxonica.validate.AbstractWatch
`getAnchorNode, getNamespaceResolver, getPipelineConfiguration, getSelection, notifySelectedLeafNode, open, setAnchorNode, setNamespaceResolver, setPipelineConfiguration, setSelection`

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

Methods inherited from interface com.saxonica.stream.watch.Watch
`getAnchorNode, getNamespaceResolver, getPipelineConfiguration, getSelection, notifySelectedLeafNode, open, setAnchorNode, setNamespaceResolver, setPipelineConfiguration, setSelection`

Constructor Detail

### SelectorWatch

    public SelectorWatch(ConstraintChecker checker,
                         IdentityConstraint uniqueConstraint)

Method Detail

### getIdentityConstraint

    public IdentityConstraint getIdentityConstraint()

  Get the identityConstraint implemented by this SelectorWatch

### startSelectedParentNode

    public Receiver startSelectedParentNode(FleetingNode node,
                                            int locationId)
                                     throws XPathException

  Signal that an element has been found that matches the selection that this Watch is looking for. This method is called by the ConstraintChecker while processing the startElement event that matches the selection. For this purpose, any attributes selected by the last step in the selection are ignored

  Specified by:
    `startSelectedParentNode` in interface `Watch`
  Parameters:
    `node` - the element or document node whose start event has been matched
    `locationId` - the location associated with the element or document node (may be the location of the instruction that created it)
  Returns:
    a Receiver to be notified of events for the subtree rooted at the element matched by this Watch. A SelectorWatch does not require such notification, so it returns null. @param locationId
  Throws:
    `ValidationException` - May be raised if the constraint implemented by this Watch is violated
    `XPathException`

### endSelectedParentNode

    public void endSelectedParentNode(int locationId)
                               throws ValidationException

  Signal that the endElement event has occurred for the element whose startElement event caused the Watch to be activated.

  Specified by:
    `endSelectedParentNode` in interface `Watch`
  Parameters:
    `locationId` - the location of the element
  Throws:
    `ValidationException` - May be raised if the constraint implemented by this Watch is violated @param locationId

### close

    public void close()
               throws ValidationException

  The close() method is called immediately before the Watch is destroyed, that is, when the element whose declaration scopes the constraint implemented by this Watch goes out of scope.

  Specified by:
    `close` in interface `Watch`
  Overrides:
    `close` in class `AbstractWatch`
  Throws:
    `ValidationException`

### addFieldValue

    public void addFieldValue(Value[] currentRow,
                              int column,
                              Value value,
                              boolean nillableElement,
                              long locationId)
                       throws ValidationException

  The addFieldValue method is a callback from the FieldWatch created when this SelectorWatch is activated. It indicates that a value for one of the fields participating in this constraint has been encountered.

  Parameters:
    `currentRow` - identifying the node to which this field value applies
    `column` - identifies which of the fields participating in this constraint the value relates to
    `value` - The value of the field that was encountered
    `nillableElement` - True if the field represents a nillable element
    `locationId` - the location of the data in the source document
  Throws:
    `ValidationException` - May be raised if the value of the field violates the constraint

### checkRow

    protected void checkRow(Value[] currentRow,
                            boolean isTarget,
                            int locationId)
                     throws ValidationException

  Method to check that a row (that is, the collection of fields corresponding to one selected node) is valid.

  Parameters:
    `currentRow` - the values of the set of fields
    `isTarget` - set to true if this is a value of the key referred to by a key reference, rather than a value for this constraint's own selected fields.
    `locationId` - identifies the location of the selected node
  Throws:
    `ValidationException` - is raised if the value of the row (that is, the combination of fields) violates the constraint

### displayRow

    protected String displayRow(Value[] row)

  Internal method to display the contents of a row, for diagnostics

### reportValidationError

    protected void reportValidationError(ValidationException err,
                                         long locationId)
                                  throws ValidationException

  Report a validation error

  Parameters:
    `err` - The validation exception
    `locationId` - identifies the location in the source document or stylesheet/query where the validation error was detected
  Throws:
    `ValidationException`

### reportValidationError

    protected void reportValidationError(ValidationException err,
                                         SourceLocator locator)
                                  throws ValidationException

  Report a validation error

  Parameters:
    `err` - The validation exception
    `locator` - identifies the location in the source document or stylesheet/query where the validation error was detected
  Throws:
    `ValidationException`

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