Class 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 Details

    • childValidator

      protected ContentValidator childValidator
    • nilled

      protected boolean nilled
    • pendingMessages

      protected List<String> pendingMessages
  • Constructor Details

    • ContentValidator

      public ContentValidator(Receiver next)
  • Method Details

    • setContainingElement

      public void setContainingElement(StructuredQName name, Location locationId)
      Set the name of the containing element (for diagnostics)
      Parameters:
      name - 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 StructuredQName getContainingElement()
      Get the name of the element being validated (for diagnostics).
      Returns:
      the element name, or null if not available.
    • getContainingElementLocationId

      public Location getContainingElementLocationId()
      Get the location of the element being validated
      Returns:
      the location, 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(ContentValidator.Nillability nillability)
      Set whether this type permits xsi:nil = true
      Parameters:
      nillability - one of ContentValidator.Nillability.IGNORED, ContentValidator.Nillability.ALLOWED, ContentValidator.Nillability.DISALLOWED
    • getNillability

      public ContentValidator.Nillability getNillability()
      Determine whether this type permits xsi:nil = true BlockCom
      Returns:
      one of ContentValidator.Nillability.IGNORED, ContentValidator.Nillability.ALLOWED, ContentValidator.Nillability.DISALLOWED
    • setNilled

      public void setNilled(boolean nilled)
      Tell this validator whether xsi:nil="true" was specified on the element being validated
      Parameters:
      nilled - true if xsi:nil="true" was specified on the element being validated
    • isNilled

      public boolean isNilled()
      Determine whether xsi:nil = true was set on this element
      Returns:
      true if xsi:nil="true" was set
    • startElement

      public void startElement(NodeName elemName, SchemaType type, AttributeMap attributes, NamespaceMap namespaces, Location location, 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:
      elemName - the name of the element.
      type - 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
    • makeValidator

      public static ContentValidator makeValidator(ElementDecl decl, StructuredQName elementName, Location locationId, ValidationContext validationContext, SchemaType governingType, int validation, PipelineConfiguration pipe, Receiver nextReceiver, List<ValidationFailure> failures) throws MissingComponentException
      Factory method to make a validator for a particular element
      Parameters:
      decl - the element declaration to validate against. May be null.
      elementName - 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
      failures - a list which the method will populate with ValidationFailure objects in the event that a validity error is detected. (This is used to avoid throwing exceptions in the case where validation failures are a normal event)
      Returns:
      a Validator suitable for validating the content of this element
      Throws:
      MissingComponentException
    • 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, List<ValidationFailure> failures) throws MissingComponentException
      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
      failures - a list which the method will populate with any validity errors discovered by the method
      Returns:
      a Validator that can sit in the event pipeline to perform local validation of elements declared to have this type, or null if any validity errors were found
      Throws:
      MissingComponentException - if validation requires components that are missing from the schema. Note that unresolved references are errors only if the component is actually used, so they are detected during validation.
    • 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, StructuredQName elementName, Location 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
      elementName - 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.
    • validateAttributes

      public AttributeMap validateAttributes(AttributeMap attributes, List<NamespaceBinding> additionalNamespaces) throws XPathException
      Throws:
      XPathException
    • checkNoChildrenWhenNil

      protected void checkNoChildrenWhenNil(Location location) throws XPathException
      A child element was encountered; check that this does not conflict with an xsi:nil=true attribute
      Parameters:
      location - the location to be used in any error report
      Throws:
      XPathException - if processing should terminate, for example because of too many errors
    • checkNoCharactersWhenNil

      protected void checkNoCharactersWhenNil(Location location) throws XPathException
      Character content was encountered; check that this does not conflict with an xsi:nil=true attribute
      Parameters:
      location - the location to be used in any error report
      Throws:
      XPathException - if processing should terminate, for example because of too many errors