com.saxonica.validate

## Class ContentValidator

- java.lang.Object
- - net.sf.saxon.event.SequenceReceiver
  - - net.sf.saxon.event.ProxyReceiver
    - - com.saxonica.validate.ValidatingFilter
      - - com.saxonica.validate.ContentValidator

- All Implemented Interfaces:
    Result, Receiver
  Direct Known Subclasses:
    AttributeValidator, LaxValidator, SkipValidator

      public abstract class ContentValidator
      extends ValidatingFilter

  This class is an abstract superclass for all the validators. The class includes factory methods for constructing a validator.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ContentValidator` | `childValidator`
    `protected boolean` | `nil`
    `static int` | `NIL_ALLOWED` Constant indicating that xsi:nil is allowed and active.
    `static int` | `NIL_DISALLOWED` Constant indicating that xsi:nil is disallowed.
    `static int` | `NIL_IGNORED` Constant indicating that xsi:nil is allowed but ignored; this is true when we are validating against a type, rather than against an element declaration
    `protected List<String>` | `pendingMessages`

    - ### Fields inherited from class com.saxonica.validate.ValidatingFilter

      `locallyInvalid`

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

    Constructors
    Constructor and Description
    `ContentValidator(Receiver next)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `endDocument()` Notify the end of a document node
    `protected SchemaType` | `getAnnotation()` Get the type annotation code to be used on elements validated by this validator
    `protected abstract ContentValidator` | `getChildValidator()` Get a validator to handle the children of the current element.
    `int` | `getContainingElement()` Get the fingerprint of the name of the element being validated (for diagnostics).
    `int` | `getContainingElementLocationId()` Get the location ID of the element being validated
    `protected String` | `getContainingElementName()` Get the containing element name, for use in error messages.
    `protected ElementDecl` | `getElementDeclaration()` Get the element declaration that this validator is validating against
    `NamespaceResolver` | `getNamespaceResolver()` Get the namespace resolver
    `int` | `getNillability()` Determine whether this type permits xsi:nil = true BlockCom
    `abstract SchemaType` | `getSchemaType()` Get the schema type against which we are validating, if any
    `boolean` | `isNil()` Determine whether xsi:nil = true was set on this element
    `protected void` | `makeChildValidator(ElementDecl decl, int nameCode, int locationId, int process)` Make a validator for the children of the element whose start tag is currently being processed.
    `static ContentValidator` | `makeValidator(ElementDecl decl, int nameCode, int locationId, ValidationContext validationContext, SchemaType governingType, int validation, PipelineConfiguration pipe, Receiver nextReceiver)` Factory method to make a validator for a particular element
    `static ContentValidator` | `makeValidatorForType(ElementDecl elementDecl, SchemaType schemaType, PipelineConfiguration pipe, Receiver nextReceiver)` Factory method to create a validator for elements of a given type
    `protected void` | `setAnnotation(SchemaType annotation)` Set the type annotation code to be allocated by this validator
    `void` | `setContainingElement(int fingerprint, int locationId)` Set the fingerprint identifying the name of the containing element (for diagnostics)
    `protected void` | `setElementDeclaration(ElementDecl decl)` Set the element declaration that this validator is validating against
    `void` | `setNillability(int nillability)` Set whether this type permits xsi:nil = true
    `void` | `startElement(NodeName nameCode, SchemaType typeCode, int locationId, int properties)` Handle the start tag for a child element of the element being validated

    - ### Methods inherited from class com.saxonica.validate.ValidatingFilter

      `append, getConstraintChecker, getStartTagBuffer, getValidationContext, reportIfInvalid, reportValidationError, setConstraintChecker, setStartTagBuffer, setValidationContext, usesTypeAnnotations`

    - ### Methods inherited from class net.sf.saxon.event.ProxyReceiver

      `attribute, characters, close, comment, endElement, getNamePool, getUnderlyingReceiver, namespace, open, processingInstruction, setPipelineConfiguration, setSystemId, setUnderlyingReceiver, setUnparsedEntity, startContent, startDocument`

    - ### Methods inherited from class net.sf.saxon.event.SequenceReceiver

      `append, getConfiguration, getPipelineConfiguration, getSystemId`

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

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

- - ### Field Detail

    - #### NIL_IGNORED

          public static final int NIL_IGNORED

      Constant indicating that xsi:nil is allowed but ignored; this is true when we are validating against a type, rather than against an element declaration
      See Also:
        Constant Field Values

    - #### NIL_ALLOWED

          public static final int NIL_ALLOWED

      Constant indicating that xsi:nil is allowed and active. That is, we are validating against an element declaration that specifies nillable=true
      See Also:
        Constant Field Values

    - #### NIL_DISALLOWED

          public static final int NIL_DISALLOWED

      Constant indicating that xsi:nil is disallowed. That is, we are validating against an element declaration that specifies nillable=false
      See Also:
        Constant Field Values

    - #### childValidator

          protected ContentValidator childValidator

    - #### nil

          protected boolean nil

    - #### pendingMessages

          protected List<String> pendingMessages

  - ### Constructor Detail

    - #### ContentValidator

          public ContentValidator(Receiver next)

  - ### Method Detail

    - #### setContainingElement

          public void setContainingElement(int fingerprint,
                                  int locationId)

      Set the fingerprint identifying the name of the containing element (for diagnostics)
      Parameters:
        `fingerprint` - identifies the name of the containing element
        `locationId` - identifies the location of the containing element

    - #### setElementDeclaration

          protected void setElementDeclaration(ElementDecl decl)

      Set the element declaration that this validator is validating against
      Parameters:
        `decl` - the element declaration

    - #### getElementDeclaration

          protected ElementDecl getElementDeclaration()

      Get the element declaration that this validator is validating against
      Returns:
        the element declaration

    - #### getContainingElement

          public int getContainingElement()

      Get the fingerprint of the name of the element being validated (for diagnostics).
      Returns:
        the fingerprint, or -1 if not available.

    - #### getContainingElementLocationId

          public int getContainingElementLocationId()

      Get the location ID of the element being validated
      Returns:
        the location ID, or 0 if not available

    - #### getContainingElementName

          protected String getContainingElementName()

      Get the containing element name, for use in error messages.
      Returns:
        the name of the containing element (plus surrounding punctuation), or the string "element" if not available

    - #### getSchemaType

          public abstract SchemaType getSchemaType()

      Get the schema type against which we are validating, if any
      Returns:
        the schema type that this validator is validating against, or null

    - #### setAnnotation

          protected final void setAnnotation(SchemaType annotation)

      Set the type annotation code to be allocated by this validator
      Parameters:
        `annotation` - the integer fingerprint of the name of the type

    - #### getAnnotation

          protected final SchemaType getAnnotation()

      Get the type annotation code to be used on elements validated by this validator
      Returns:
        the integer fingerprint of the name of the type

    - #### getNamespaceResolver

          public NamespaceResolver getNamespaceResolver()

      Get the namespace resolver
      Returns:
        the namespace resolver

    - #### setNillability

          public void setNillability(int nillability)

      Set whether this type permits xsi:nil = true
      Parameters:
        `nillability` - one of `NIL_IGNORED`, `NIL_ALLOWED`, `NIL_DISALLOWED`

    - #### getNillability

          public int getNillability()

      Determine whether this type permits xsi:nil = true BlockCom
      Returns:
        one of `NIL_IGNORED`, `NIL_ALLOWED`, `NIL_DISALLOWED`

    - #### isNil

          public boolean isNil()

      Determine whether xsi:nil = true was set on this element
      Returns:
        true if xsi:nil="true" was set

    - #### startElement

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

      Handle the start tag for a child element of the element being validated
      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` - if an error occurs

    - #### makeValidator

          public static ContentValidator makeValidator(ElementDecl decl,
                                       int nameCode,
                                       int locationId,
                                       ValidationContext validationContext,
                                       SchemaType governingType,
                                       int validation,
                                       PipelineConfiguration pipe,
                                       Receiver nextReceiver)
                                                throws ValidationException

      Factory method to make a validator for a particular element
      Parameters:
        `decl` - the element declaration to validate against. May be null.
        `nameCode` - the name of the element (used only for diagnostics)
        `locationId` - the location of the element, or of the stylesheet instruction that generated this element (or zero)
        `validationContext` - information about the validation episode
        `governingType` - the type identified by xsi:type, if specified; otherwise null
        `validation` - the validation mode (strict, lax, preserve, strip)
        `pipe` - the pipeline configuration
        `nextReceiver` - the next receiver in the pipeline
      Returns:
        a Validator suitable for validating the content of this element
      Throws:
        `ValidationException` - if a validator cannot be created, for example because neither an element declaration nor a governing type is supplied

    - #### getChildValidator

          protected abstract ContentValidator getChildValidator()

      Get a validator to handle the children of the current element. This is called immediately on return from the startElement call that starts this element.
      Returns:
        the validator to be used to handle the children

    - #### makeValidatorForType

          public static ContentValidator makeValidatorForType(ElementDecl elementDecl,
                                              SchemaType schemaType,
                                              PipelineConfiguration pipe,
                                              Receiver nextReceiver)
                                                       throws ValidationException

      Factory method to create a validator for elements of a given type
      Parameters:
        `elementDecl` - the element declaration if available, otherwise null (there will be no element declaration, for example, when doing lax validation against an xsi:type)
        `schemaType` - the simple or complex type against which the content of the element is to be validated
        `pipe` - the pipeline configuration
        `nextReceiver` - the next receiver in the pipeline
      Returns:
        a Validator that can sit in the event pipeline to perform local validation of elements declared to have this type
      Throws:
        `ValidationException` - if a validator cannot be constructed, for example because the requested type is xs:untypedAtomic

    - #### endDocument

          public void endDocument()
                           throws XPathException

      Notify the end of a document node
      Specified by:
        `endDocument` in interface `Receiver`
      Overrides:
        `endDocument` in class `ProxyReceiver`
      Throws:
        `XPathException` - if an error occurs

    - #### makeChildValidator

          protected void makeChildValidator(ElementDecl decl,
                                int nameCode,
                                int locationId,
                                int process)
                                     throws XPathException

      Make a validator for the children of the element whose start tag is currently being processed. This will always set some kind of validator for the children in the field childValidator, even if the method fails
      Parameters:
        `decl` - the element declaration for this element, if applicable
        `nameCode` - the name of this element, used for diagnostics
        `locationId` - location information, used for diagnostics
      Throws:
        `XPathException` - if a validation error occurs and if recovery from validation errors has not been requested. The error will always have been reported.

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