Interface ValidationContext


  • public interface ValidationContext
    Interface that defines functionality exposed by the "owner" of the content to validate (usually a stream reader or stream writer) to validators, needed in addition to actually validatable content, for succesful validation. It also defines methods needed for infoset augmentation some validators do, such as adding default values to attributes. Some of functionality is optional (for example, writer may not have any useful location information).

    The functionality included is close to the minimal subset of functionality needed to support 3 main streamable schema languages (DTD, W3C Schema, Relax NG).

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      int addDefaultAttribute​(java.lang.String localName, java.lang.String uri, java.lang.String prefix, java.lang.String value)
      An optional method that can be used to add a new attribute value for an attribute that was not yet contained by the container, as part of using attribute default value mechanism.
      int findAttributeIndex​(java.lang.String nsURI, java.lang.String localName)  
      int getAttributeCount()
      This method returns number of attributes accessible from within currently active start element.
      java.lang.String getAttributeLocalName​(int index)  
      java.lang.String getAttributeNamespace​(int index)  
      java.lang.String getAttributePrefix​(int index)  
      java.lang.String getAttributeType​(int index)  
      java.lang.String getAttributeValue​(int index)  
      java.lang.String getAttributeValue​(java.lang.String nsURI, java.lang.String localName)  
      java.lang.String getBaseUri()  
      javax.xml.namespace.QName getCurrentElementName()
      Method that can be used to access name information of the innermost (top) element in the element stack.
      java.lang.String getNamespaceURI​(java.lang.String prefix)
      Method that can be called by the validator to resolve a namespace prefix of the currently active top-level element.
      javax.xml.stream.Location getValidationLocation()
      Method that will return the location that best represents current location within document to be validated, if such information is available.
      java.lang.String getXmlVersion()
      Method that validator can call to figure out which xml version document being validated declared (if none, "1.0" is assumed as per xml specifications 1.0 and 1.1).
      boolean isNotationDeclared​(java.lang.String name)  
      boolean isUnparsedEntityDeclared​(java.lang.String name)  
      void reportProblem​(XMLValidationProblem problem)
      Method called by the validator, upon encountering a validation problem.
    • Method Detail

      • getXmlVersion

        java.lang.String getXmlVersion()
        Method that validator can call to figure out which xml version document being validated declared (if none, "1.0" is assumed as per xml specifications 1.0 and 1.1).
        Returns:
        Xml version of the document: currently has to be either "1.0" or "1.1".
      • getCurrentElementName

        javax.xml.namespace.QName getCurrentElementName()
        Method that can be used to access name information of the innermost (top) element in the element stack.
        Returns:
        Name of the element at the top of the current element stack, if any. During validation calls it refers to the element being processed (start or end tag), or its parent (when processing text nodes), or null (in document prolog and epilog).
      • getNamespaceURI

        java.lang.String getNamespaceURI​(java.lang.String prefix)
        Method that can be called by the validator to resolve a namespace prefix of the currently active top-level element. This may be necessary for things like DTD validators (which may need to heuristically guess proper namespace URI of attributes, esp. ones with default values).
      • getAttributeLocalName

        java.lang.String getAttributeLocalName​(int index)
      • getAttributeNamespace

        java.lang.String getAttributeNamespace​(int index)
      • getAttributePrefix

        java.lang.String getAttributePrefix​(int index)
      • getAttributeValue

        java.lang.String getAttributeValue​(int index)
      • getAttributeValue

        java.lang.String getAttributeValue​(java.lang.String nsURI,
                                           java.lang.String localName)
      • getAttributeType

        java.lang.String getAttributeType​(int index)
      • findAttributeIndex

        int findAttributeIndex​(java.lang.String nsURI,
                               java.lang.String localName)
        Returns:
        Index of the specified attribute, if one present; -1 otherwise.
      • isNotationDeclared

        boolean isNotationDeclared​(java.lang.String name)
        Returns:
        True, if a notation with specified name has been declared in the document being validated; false if not.
      • isUnparsedEntityDeclared

        boolean isUnparsedEntityDeclared​(java.lang.String name)
        Returns:
        True, if an unparsed entity with specified name has been declared in the document being validated; false if not.
      • getBaseUri

        java.lang.String getBaseUri()
        Returns:
        Base URI active in the current location of the document being validated, if known; null to indicate no base URI known.
      • getValidationLocation

        javax.xml.stream.Location getValidationLocation()
        Method that will return the location that best represents current location within document to be validated, if such information is available.

        Note: it is likely that even when a location is known, it may not be very accurate; for example, when attributes are validated, it is possible that they all would point to a single location that may point to the start of the element that contains attributes.

      • reportProblem

        void reportProblem​(XMLValidationProblem problem)
                    throws javax.xml.stream.XMLStreamException
        Method called by the validator, upon encountering a validation problem. Implementations are encouraged to allow an optional ValidationProblemHandler be set by the application, to define handling.

        Note: Stax2 version 2 only allowed throwing instances of XMLValidationProblem; version 3 allows generic base class to be thrown, to support other interfaces such as basic Stax interface XMLReporter.

        Throws:
        javax.xml.stream.XMLStreamException
      • addDefaultAttribute

        int addDefaultAttribute​(java.lang.String localName,
                                java.lang.String uri,
                                java.lang.String prefix,
                                java.lang.String value)
                         throws javax.xml.stream.XMLStreamException
        An optional method that can be used to add a new attribute value for an attribute that was not yet contained by the container, as part of using attribute default value mechanism. Optional here means that it is possible that no operation is actually done by the context object. This would be the case, for example, when validation is done on the writer side: since default attributes are implied by a DTD, they should not be added to the output.

        Note: caller has to ensure that the addition would not introduce a duplicate; attribute container implementation is not required to do any validation on attribute name (local name, prefix, uri) or value.

        Returns:
        Index of the newly added attribute, if operation was succesful; -1 if not.
        Throws:
        javax.xml.stream.XMLStreamException