org.apache.xmlbeans.impl.validator

## Class ValidatingXMLStreamReader

- java.lang.Object
- - javax.xml.stream.util.StreamReaderDelegate
  - - org.apache.xmlbeans.impl.validator.ValidatingXMLStreamReader

- All Implemented Interfaces:
    XMLStreamConstants, XMLStreamReader
  Direct Known Subclasses:
    ValidatingInfoXMLStreamReader

      public class ValidatingXMLStreamReader
      extends StreamReaderDelegate
      implements XMLStreamReader

  This class is a wrapper over a generic XMLStreamReader that provides validation. There are 3 cases:
  1) the XMLStreamReader represents a document, it contains only one element document - in this case the user schema type should be null or it should be a document SchemaType
  2) the XMLStreamReader represents an xml-fragment (content only) - must have at least one user type or xsi:type
  a) it has an xsi:type - if user schema type is available it has to be a base type of xsi:type
  b) it doesn't have xsi:type - user must provide a schema type otherwise will error and will not do validation
  3) the XMLStreamReader represents a global attribute - i.e. user schema type is null and only one attribute
  Author:
    Cezar Andrei (cezar.andrei at bea.com) Date: Feb 13, 2004

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Validator` | `_validator`

    - ### Fields inherited from interface javax.xml.stream.XMLStreamConstants

      `ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ValidatingXMLStreamReader()` Default constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Object` | `getProperty(String s)`
    `void` | `init(XMLStreamReader xsr, boolean startWithCurrentEvent, SchemaType contentType, SchemaTypeLoader stl, XmlOptions options, Collection errorListener)` Used in case of reusing the same ValidatinXMLStreamReader object
    `boolean` | `isValid()`
    `int` | `next()`
    `protected void` | `validate_attribute(int attIndex)`
    `protected void` | `validate_attributes(int attCount)`

    - ### Methods inherited from class javax.xml.stream.util.StreamReaderDelegate

      `close, getAttributeCount, getAttributeLocalName, getAttributeName, getAttributeNamespace, getAttributePrefix, getAttributeType, getAttributeValue, getAttributeValue, getCharacterEncodingScheme, getElementText, getEncoding, getEventType, getLocalName, getLocation, getName, getNamespaceContext, getNamespaceCount, getNamespacePrefix, getNamespaceURI, getNamespaceURI, getNamespaceURI, getParent, getPIData, getPITarget, getPrefix, getText, getTextCharacters, getTextCharacters, getTextLength, getTextStart, getVersion, hasName, hasNext, hasText, isAttributeSpecified, isCharacters, isEndElement, isStandalone, isStartElement, isWhiteSpace, nextTag, require, setParent, standaloneSet`

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

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

    - ### Methods inherited from interface javax.xml.stream.XMLStreamReader

      `close, getAttributeCount, getAttributeLocalName, getAttributeName, getAttributeNamespace, getAttributePrefix, getAttributeType, getAttributeValue, getAttributeValue, getCharacterEncodingScheme, getElementText, getEncoding, getEventType, getLocalName, getLocation, getName, getNamespaceContext, getNamespaceCount, getNamespacePrefix, getNamespaceURI, getNamespaceURI, getNamespaceURI, getPIData, getPITarget, getPrefix, getText, getTextCharacters, getTextCharacters, getTextLength, getTextStart, getVersion, hasName, hasNext, hasText, isAttributeSpecified, isCharacters, isEndElement, isStandalone, isStartElement, isWhiteSpace, nextTag, require, standaloneSet`

- - ### Field Detail

    - #### _validator

          protected Validator _validator

  - ### Constructor Detail

    - #### ValidatingXMLStreamReader

          public ValidatingXMLStreamReader()

      Default constructor. Use init(...) to set the params. See `init(javax.xml.stream.XMLStreamReader, boolean, org.apache.xmlbeans.SchemaType, org.apache.xmlbeans.SchemaTypeLoader, org.apache.xmlbeans.XmlOptions, java.util.Collection)`

  - ### Method Detail

    - #### init

          public void init(XMLStreamReader xsr,
                           boolean startWithCurrentEvent,
                           SchemaType contentType,
                           SchemaTypeLoader stl,
                           XmlOptions options,
                           Collection errorListener)

      Used in case of reusing the same ValidatinXMLStreamReader object
      Parameters:
        `xsr` - The stream to be validated
        `startWithCurrentEvent` - Validation will start if true with the current event or if false with the next event in the stream
        `contentType` - The schemaType of the content. This can be null for document and global Att validation
        `stl` - SchemaTypeLoader context of validation
        `options` - Validator options
        `errorListener` - Errors and warnings listener

    - #### getProperty

          public Object getProperty(String s)
                             throws IllegalArgumentException

      Specified by:
        `getProperty` in interface `XMLStreamReader`
      Overrides:
        `getProperty` in class `StreamReaderDelegate`
      Throws:
        `IllegalArgumentException`

    - #### next

          public int next()
                   throws XMLStreamException

      Specified by:
        `next` in interface `XMLStreamReader`
      Overrides:
        `next` in class `StreamReaderDelegate`
      Throws:
        `XMLStreamException`

    - #### validate_attributes

          protected void validate_attributes(int attCount)

    - #### validate_attribute

          protected void validate_attribute(int attIndex)

    - #### isValid

          public boolean isValid()

      Returns:
        Returns the validation state up to this point. NOTE: At least one START ELEMENT should have been consumed for a valid value to be returned.