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 TypeMethodDescriptionvoidcharacters(char[] ch, int start, int length) Receive notification of character data.voidcomment(char[] ch, int start, int length) Report an XML comment anywhere in the document.voidendCDATA()Report the end of a CDATA section.voidReceive notification of the end of a document.voidendDTD()Report the end of DTD declarations.voidendElement(String uri, String localName, String qName) Receive notification of the end of an element.voidReport the end of an entity.voidendPrefixMapping(String prefix) End the scope of a prefix-URI mapping.Get the Configuration objectGets theContentHandlerwhich receives the augmented validation result.Gets the currentErrorHandlergetProperty(String name) Look up the value of a property.Gets the currentLSResourceResolverObtains theTypeInfoProviderimplementation of thisValidatorHandler.voidignorableWhitespace(char[] ch, int start, int length) Receive notification of ignorable whitespace in element content.voidnotationDecl(String name, String publicId, String systemId) Receive notification of a notation declaration event.voidprocessingInstruction(String target, String data) Receive notification of a processing instruction.voidsetContentHandler(ContentHandler receiver) Sets theContentHandlerwhich receives the augmented validation result.voidsetDocumentLocator(Locator locator) Receive an object for locating the origin of SAX document events.voidsetErrorHandler(ErrorHandler errorHandler) Sets theErrorHandlerto receive errors encountered during the validation.voidsetFinalProxy(TypedContentHandler proxy) Set the TypedContentHandler that acts as the final stage in this pipeline, receiving typed events from the validator stackvoidSet the pipeline configuration used by this validator handlervoidsetProperty(String name, Object object) Set the value of a property.voidGet the ReceivingContentHandler that receives the SAX events at the start of this pipelinevoidsetResourceResolver(LSResourceResolver resourceResolver) Sets theLSResourceResolverto customize resource resolution while in a validation episode.voidskippedEntity(String name) Receive notification of a skipped entity.voidReport the start of a CDATA section.voidReceive notification of the beginning of a document.voidReport the start of DTD declarations, if any.voidstartElement(String uri, String localName, String qName, Attributes atts) Receive notification of the beginning of an element.voidstartEntity(String name) Report the beginning of some internal and external XML entities.voidstartPrefixMapping(String prefix, String uri) Begin the scope of a prefix-URI Namespace mapping.voidunparsedEntityDecl(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, setFeatureMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 theContentHandlerwhich receives the augmented validation result.A
ValidatorHandlermay buffer events to certain extent, but to allowValidatorHandlerto 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-specifiedContentHandlermust 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:
setContentHandlerin classValidatorHandler- Parameters:
receiver- AContentHandleror a null value.
- When
-
getContentHandler
Gets theContentHandlerwhich receives the augmented validation result.- Specified by:
getContentHandlerin 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 thisValidatorHandlerhas created. - See Also:
-
setErrorHandler
Sets theErrorHandlerto receive errors encountered during the validation.- Specified by:
setErrorHandlerin classValidatorHandler- Parameters:
errorHandler- A new error handler to be set. This parameter can be null.
-
getErrorHandler
Gets the currentErrorHandler- Specified by:
getErrorHandlerin 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 theLSResourceResolverto 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:
setResourceResolverin classValidatorHandler- Parameters:
resourceResolver- A new resource resolver to be set. This parameter can be null.
-
getResourceResolver
Gets the currentLSResourceResolver- Specified by:
getResourceResolverin 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 theTypeInfoProviderimplementation of thisValidatorHandler. The obtainedTypeInfoProvidercan be queried during a parse to access the type information determined by the validator.- Specified by:
getTypeInfoProviderin classValidatorHandler- Returns:
- A non-null valid
TypeInfoProvider.
-
setDocumentLocator
Receive an object for locating the origin of SAX document events.- Specified by:
setDocumentLocatorin 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
ValidatorHandlerto 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.Validators 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:
getPropertyin 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
ValidatorHandlerto 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:
setPropertyin 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 theValidatorrecognizes 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:
startDocumentin interfaceContentHandler- Throws:
SAXException- any SAX exception, possibly wrapping another exception- See Also:
-
endDocument
Receive notification of the end of a document.- Specified by:
endDocumentin 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:
startPrefixMappingin 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:
endPrefixMappingin 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:
startElementin 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:
endElementin interfaceContentHandler- Throws:
SAXException
-
characters
Receive notification of character data.- Specified by:
charactersin interfaceContentHandler- Throws:
SAXException
-
ignorableWhitespace
Receive notification of ignorable whitespace in element content.- Specified by:
ignorableWhitespacein interfaceContentHandler- Throws:
SAXException
-
processingInstruction
Receive notification of a processing instruction.- Specified by:
processingInstructionin interfaceContentHandler- Throws:
SAXException
-
skippedEntity
Receive notification of a skipped entity.- Specified by:
skippedEntityin interfaceContentHandler- Throws:
SAXException
-
startDTD
Report the start of DTD declarations, if any.- Specified by:
startDTDin interfaceLexicalHandler- Throws:
SAXException
-
endDTD
Report the end of DTD declarations.- Specified by:
endDTDin interfaceLexicalHandler- Throws:
SAXException
-
startEntity
Report the beginning of some internal and external XML entities.- Specified by:
startEntityin interfaceLexicalHandler- Throws:
SAXException
-
endEntity
Report the end of an entity.- Specified by:
endEntityin interfaceLexicalHandler- Throws:
SAXException
-
startCDATA
Report the start of a CDATA section.- Specified by:
startCDATAin interfaceLexicalHandler- Throws:
SAXException
-
endCDATA
Report the end of a CDATA section.- Specified by:
endCDATAin interfaceLexicalHandler- Throws:
SAXException
-
comment
Report an XML comment anywhere in the document.- Specified by:
commentin interfaceLexicalHandler- Throws:
SAXException
-
notationDecl
Receive notification of a notation declaration event.- Specified by:
notationDeclin 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:
unparsedEntityDeclin interfaceDTDHandler- Throws:
SAXException
-