Class ValidatorHandlerImpl
- All Implemented Interfaces:
ContentHandler
,DTDHandler
,LexicalHandler
A ValidatorHandler is the front end to a rather complex pipeline. The ValidatorHandler is the first stage in the pipeline: it receives events from a SAX parser or other source of SAX events. The next stage is a ReceivingContentHandler, which translates SAX events into Receiver events. This is followed by a number of Receivers to do the validation (actually a stack of Receivers, since a new ComplexContentValidator is added each time a new element starts). The last Receiver is the finalProxy: this translates Receiver events back into SAX2 events, for delivery to the user's ContentHandler.
The user's ContentHandler has access to a TypeInfoProvider that gives information about the types of elements and attributes. This information is passed down the Receiver pipeline in the form of typeCodes associated with element and attribute events. The TypeInfoProvider is part of the finalProxy, which saves the type information locally and returns it to the user's ContentHandler on request. The TypeInfo objects supplied by the TypeInfoProvider are in fact the schema components representing the type, as a SchemaType object.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
characters
(char[] ch, int start, int length) Receive notification of character data.void
comment
(char[] ch, int start, int length) Report an XML comment anywhere in the document.void
endCDATA()
Report the end of a CDATA section.void
Receive notification of the end of a document.void
endDTD()
Report the end of DTD declarations.void
endElement
(String uri, String localName, String qName) Receive notification of the end of an element.void
Report the end of an entity.void
endPrefixMapping
(String prefix) End the scope of a prefix-URI mapping.Get the Configuration objectGets theContentHandler
which receives the augmented validation result.Gets the currentErrorHandler
getProperty
(String name) Look up the value of a property.Gets the currentLSResourceResolver
Obtains theTypeInfoProvider
implementation of thisValidatorHandler
.void
ignorableWhitespace
(char[] ch, int start, int length) Receive notification of ignorable whitespace in element content.void
notationDecl
(String name, String publicId, String systemId) Receive notification of a notation declaration event.void
processingInstruction
(String target, String data) Receive notification of a processing instruction.void
setContentHandler
(ContentHandler receiver) Sets theContentHandler
which receives the augmented validation result.void
setDocumentLocator
(Locator locator) Receive an object for locating the origin of SAX document events.void
setErrorHandler
(ErrorHandler errorHandler) Sets theErrorHandler
to receive errors encountered during the validation.void
setFinalProxy
(TypedContentHandler proxy) Set the TypedContentHandler that acts as the final stage in this pipeline, receiving typed events from the validator stackvoid
Set the pipeline configuration used by this validator handlervoid
setProperty
(String name, Object object) Set the value of a property.void
Get the ReceivingContentHandler that receives the SAX events at the start of this pipelinevoid
setResourceResolver
(LSResourceResolver resourceResolver) Sets theLSResourceResolver
to customize resource resolution while in a validation episode.void
skippedEntity
(String name) Receive notification of a skipped entity.void
Report the start of a CDATA section.void
Receive notification of the beginning of a document.void
Report the start of DTD declarations, if any.void
startElement
(String uri, String localName, String qName, Attributes atts) Receive notification of the beginning of an element.void
startEntity
(String name) Report the beginning of some internal and external XML entities.void
startPrefixMapping
(String prefix, String uri) Begin the scope of a prefix-URI Namespace mapping.void
unparsedEntityDecl
(String name, String publicId, String systemId, String notationName) Receive notification of an unparsed entity declaration event.Methods inherited from class javax.xml.validation.ValidatorHandler
getFeature, setFeature
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Constructor Details
-
ValidatorHandlerImpl
public ValidatorHandlerImpl()
-
-
Method Details
-
setPipelineConfiguration
Set the pipeline configuration used by this validator handler- Parameters:
pipe
- the pipeline configuration
-
setReceivingContentHandler
Get the ReceivingContentHandler that receives the SAX events at the start of this pipeline- Parameters:
rch
- the ReceivingContentHandler
-
setFinalProxy
Set the TypedContentHandler that acts as the final stage in this pipeline, receiving typed events from the validator stack- Parameters:
proxy
- the TypedContentHandler at the end of the pipeline
-
setContentHandler
Sets theContentHandler
which receives the augmented validation result.A
ValidatorHandler
may buffer events to certain extent, but to allowValidatorHandler
to be used by a parser, the following requirement has to be met.- When
ContentHandler.startElement(String, String, String, Attributes)
,ContentHandler.endElement(String, String, String)
,ContentHandler.startDocument()
, orContentHandler.endDocument()
are invoked on aValidatorHandler
, the same method on the user-specifiedContentHandler
must be invoked for the same event before the callback returns.
The Saxon implementation does not meet this requirement. StartElement events are buffered until the first thing following the attributes is encountered.
- Specified by:
setContentHandler
in classValidatorHandler
- Parameters:
receiver
- AContentHandler
or a null value.
- When
-
getContentHandler
Gets theContentHandler
which receives the augmented validation result.- Specified by:
getContentHandler
in classValidatorHandler
- Returns:
- This method returns the object that was last set through
the
setContentHandler(org.xml.sax.ContentHandler)
method, or null if that method has never been called since thisValidatorHandler
has created. - See Also:
-
setErrorHandler
Sets theErrorHandler
to receive errors encountered during the validation.- Specified by:
setErrorHandler
in classValidatorHandler
- Parameters:
errorHandler
- A new error handler to be set. This parameter can be null.
-
getErrorHandler
Gets the currentErrorHandler
- Specified by:
getErrorHandler
in classValidatorHandler
- Returns:
- This method returns the object that was last set through
the
setErrorHandler(org.xml.sax.ErrorHandler)
method, or null if that method has never been called - See Also:
-
setResourceResolver
Sets theLSResourceResolver
to customize resource resolution while in a validation episode. This method has no effect other than to affect the result ofgetResourceResolver()
, since no resources will be fetched in the course of XSD validation.- Specified by:
setResourceResolver
in classValidatorHandler
- Parameters:
resourceResolver
- A new resource resolver to be set. This parameter can be null.
-
getResourceResolver
Gets the currentLSResourceResolver
- Specified by:
getResourceResolver
in classValidatorHandler
- Returns:
- This method returns the object that was last set through
the
setResourceResolver(org.w3c.dom.ls.LSResourceResolver)
method, or null if that method has never been called
-
getTypeInfoProvider
Obtains theTypeInfoProvider
implementation of thisValidatorHandler
. The obtainedTypeInfoProvider
can be queried during a parse to access the type information determined by the validator.- Specified by:
getTypeInfoProvider
in classValidatorHandler
- Returns:
- A non-null valid
TypeInfoProvider
.
-
setDocumentLocator
Receive an object for locating the origin of SAX document events.- Specified by:
setDocumentLocator
in interfaceContentHandler
- Parameters:
locator
- an object that can return the location of any SAX document event- See Also:
-
getProperty
Look up the value of a property.The property name is any fully-qualified URI. It is possible for a
ValidatorHandler
to recognize a property name but temporarily be unable to return its value. Some property values may be available only in specific contexts, such as before, during, or after a validation.Validator
s are not required to recognize any specific property names.In the Saxon implementation, the property names that are recognized are the same as the attribute names recognised by a
TransformerFactory
. These are listed as constant fields in the classFeatureKeys
- Overrides:
getProperty
in classValidatorHandler
- Parameters:
name
- The property name, which is a non-null fully-qualified URI.- Returns:
- The current value of the property.
- Throws:
SAXNotRecognizedException
- If the property value can't be assigned or retrieved.SAXNotSupportedException
- When the XMLReader recognizes the property name but cannot determine its value at this time.NullPointerException
- When the name parameter is null.- See Also:
-
setProperty
public void setProperty(String name, Object object) throws SAXNotRecognizedException, SAXNotSupportedException Set the value of a property.The property name is any fully-qualified URI. It is possible for a
ValidatorHandler
to recognize a property name but to be unable to change the current value. Some property values may be immutable or mutable only in specific contexts, such as before, during, or after a validation.In the Saxon implementation, the property names that are recognized are the same as the attribute names recognised by a
TransformerFactory
. These are listed as constant fields in the classFeatureKeys
- Overrides:
setProperty
in classValidatorHandler
- Parameters:
name
- The property name, which is a non-null fully-qualified URI.object
- The requested value for the property.- Throws:
SAXNotRecognizedException
- If the property value can't be assigned or retrieved.SAXNotSupportedException
- When theValidator
recognizes the property name but cannot set the requested value.NullPointerException
- When the name parameter is null.
-
getConfiguration
Get the Configuration object- Returns:
- the Configuration, which will always be schema-aware
-
startDocument
Receive notification of the beginning of a document.The SAX parser will invoke this method only once, before any other event callbacks (except for
setDocumentLocator
).- Specified by:
startDocument
in interfaceContentHandler
- Throws:
SAXException
- any SAX exception, possibly wrapping another exception- See Also:
-
endDocument
Receive notification of the end of a document.- Specified by:
endDocument
in interfaceContentHandler
- Throws:
SAXException
- any SAX exception, possibly wrapping another exception
-
startPrefixMapping
Begin the scope of a prefix-URI Namespace mapping.There should never be start/endPrefixMapping events for the "xml" prefix, since it is predeclared and immutable.
- Specified by:
startPrefixMapping
in interfaceContentHandler
- Parameters:
prefix
- the Namespace prefix being declared. An empty string is used for the default element namespace, which has no prefix.uri
- the Namespace URI the prefix is mapped to- Throws:
SAXException
- the client may throw an exception during processing- See Also:
-
endPrefixMapping
End the scope of a prefix-URI mapping.- Specified by:
endPrefixMapping
in interfaceContentHandler
- Parameters:
prefix
- the prefix that was being mapped. This is the empty string when a default mapping scope ends.- Throws:
SAXException
- the client may throw an exception during processing
-
startElement
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException Receive notification of the beginning of an element.- Specified by:
startElement
in interfaceContentHandler
- Parameters:
uri
- the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performedlocalName
- the local name (without prefix), or the empty string if Namespace processing is not being performedqName
- the qualified name (with prefix), or the empty string if qualified names are not availableatts
- the attributes attached to the element. If there are no attributes, it shall be an empty Attributes object. The value of this object after startElement returns is undefined- Throws:
SAXException
- any SAX exception, possibly wrapping another exception
-
endElement
Receive notification of the end of an element.- Specified by:
endElement
in interfaceContentHandler
- Throws:
SAXException
-
characters
Receive notification of character data.- Specified by:
characters
in interfaceContentHandler
- Throws:
SAXException
-
ignorableWhitespace
Receive notification of ignorable whitespace in element content.- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Throws:
SAXException
-
processingInstruction
Receive notification of a processing instruction.- Specified by:
processingInstruction
in interfaceContentHandler
- Throws:
SAXException
-
skippedEntity
Receive notification of a skipped entity.- Specified by:
skippedEntity
in interfaceContentHandler
- Throws:
SAXException
-
startDTD
Report the start of DTD declarations, if any.- Specified by:
startDTD
in interfaceLexicalHandler
- Throws:
SAXException
-
endDTD
Report the end of DTD declarations.- Specified by:
endDTD
in interfaceLexicalHandler
- Throws:
SAXException
-
startEntity
Report the beginning of some internal and external XML entities.- Specified by:
startEntity
in interfaceLexicalHandler
- Throws:
SAXException
-
endEntity
Report the end of an entity.- Specified by:
endEntity
in interfaceLexicalHandler
- Throws:
SAXException
-
startCDATA
Report the start of a CDATA section.- Specified by:
startCDATA
in interfaceLexicalHandler
- Throws:
SAXException
-
endCDATA
Report the end of a CDATA section.- Specified by:
endCDATA
in interfaceLexicalHandler
- Throws:
SAXException
-
comment
Report an XML comment anywhere in the document.- Specified by:
comment
in interfaceLexicalHandler
- Throws:
SAXException
-
notationDecl
Receive notification of a notation declaration event.- Specified by:
notationDecl
in interfaceDTDHandler
- Throws:
SAXException
-
unparsedEntityDecl
public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName) throws SAXException Receive notification of an unparsed entity declaration event.- Specified by:
unparsedEntityDecl
in interfaceDTDHandler
- Throws:
SAXException
-