Class ValidatorHandlerImpl
- java.lang.Object
-
- javax.xml.validation.ValidatorHandler
-
- com.saxonica.ee.jaxp.ValidatorHandlerImpl
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler,org.xml.sax.DTDHandler,org.xml.sax.ext.LexicalHandler
public class ValidatorHandlerImpl extends javax.xml.validation.ValidatorHandler implements org.xml.sax.ContentHandler, org.xml.sax.ext.LexicalHandler, org.xml.sax.DTDHandlerThe is the Saxon implementation of the JAXP 1.3 ValidatorHandler interface. It is a SAX ContentHandler that accepts events from an XML parser (or elsewhere), validates them, reports any errors, and passes the events on to another ContentHandler. The events that are passed on will be augmented with extra elements and attributes that expand default values defined in the schema. In addition, the receiving ContentHandler has access to a TypeInfoProvider that gives information about the type of the current element or attribute event.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 Constructor Description ValidatorHandlerImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcharacters(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.voidendDocument()Receive notification of the end of a document.voidendDTD()Report the end of DTD declarations.voidendElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)Receive notification of the end of an element.voidendEntity(java.lang.String name)Report the end of an entity.voidendPrefixMapping(java.lang.String prefix)End the scope of a prefix-URI mapping.EnterpriseConfigurationgetConfiguration()Get the Configuration objectorg.xml.sax.ContentHandlergetContentHandler()Gets theContentHandlerwhich receives the augmented validation result.org.xml.sax.ErrorHandlergetErrorHandler()Gets the currentErrorHandlerjava.lang.ObjectgetProperty(java.lang.String name)Look up the value of a property.org.w3c.dom.ls.LSResourceResolvergetResourceResolver()Gets the currentLSResourceResolverjavax.xml.validation.TypeInfoProvidergetTypeInfoProvider()Obtains theTypeInfoProviderimplementation of thisValidatorHandler.voidignorableWhitespace(char[] ch, int start, int length)Receive notification of ignorable whitespace in element content.voidnotationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)Receive notification of a notation declaration event.voidprocessingInstruction(java.lang.String target, java.lang.String data)Receive notification of a processing instruction.voidsetContentHandler(org.xml.sax.ContentHandler receiver)Sets theContentHandlerwhich receives the augmented validation result.voidsetDocumentLocator(org.xml.sax.Locator locator)Receive an object for locating the origin of SAX document events.voidsetErrorHandler(org.xml.sax.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 stackvoidsetPipelineConfiguration(PipelineConfiguration pipe)Set the pipeline configuration used by this validator handlervoidsetProperty(java.lang.String name, java.lang.Object object)Set the value of a property.voidsetReceivingContentHandler(ReceivingContentHandler rch)Get the ReceivingContentHandler that receives the SAX events at the start of this pipelinevoidsetResourceResolver(org.w3c.dom.ls.LSResourceResolver resourceResolver)Sets theLSResourceResolverto customize resource resolution while in a validation episode.voidskippedEntity(java.lang.String name)Receive notification of a skipped entity.voidstartCDATA()Report the start of a CDATA section.voidstartDocument()Receive notification of the beginning of a document.voidstartDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)Report the start of DTD declarations, if any.voidstartElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)Receive notification of the beginning of an element.voidstartEntity(java.lang.String name)Report the beginning of some internal and external XML entities.voidstartPrefixMapping(java.lang.String prefix, java.lang.String uri)Begin the scope of a prefix-URI Namespace mapping.voidunparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)Receive notification of an unparsed entity declaration event.
-
-
-
Method Detail
-
setPipelineConfiguration
public void setPipelineConfiguration(PipelineConfiguration pipe)
Set the pipeline configuration used by this validator handler- Parameters:
pipe- the pipeline configuration
-
setReceivingContentHandler
public void setReceivingContentHandler(ReceivingContentHandler rch)
Get the ReceivingContentHandler that receives the SAX events at the start of this pipeline- Parameters:
rch- the ReceivingContentHandler
-
setFinalProxy
public void setFinalProxy(TypedContentHandler proxy)
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
public void setContentHandler(org.xml.sax.ContentHandler receiver)
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 classjavax.xml.validation.ValidatorHandler- Parameters:
receiver- AContentHandleror a null value.
- When
-
getContentHandler
public org.xml.sax.ContentHandler getContentHandler()
Gets theContentHandlerwhich receives the augmented validation result.- Specified by:
getContentHandlerin classjavax.xml.validation.ValidatorHandler- 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:
setContentHandler(org.xml.sax.ContentHandler)
-
setErrorHandler
public void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
Sets theErrorHandlerto receive errors encountered during the validation.- Specified by:
setErrorHandlerin classjavax.xml.validation.ValidatorHandler- Parameters:
errorHandler- A new error handler to be set. This parameter can be null.
-
getErrorHandler
public org.xml.sax.ErrorHandler getErrorHandler()
Gets the currentErrorHandler- Specified by:
getErrorHandlerin classjavax.xml.validation.ValidatorHandler- 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:
setErrorHandler(org.xml.sax.ErrorHandler)
-
setResourceResolver
public void setResourceResolver(org.w3c.dom.ls.LSResourceResolver resourceResolver)
Sets theLSResourceResolverto customize resource resolution while in a validation episode.- Specified by:
setResourceResolverin classjavax.xml.validation.ValidatorHandler- Parameters:
resourceResolver- A new resource resolver to be set. This parameter can be null.
-
getResourceResolver
public org.w3c.dom.ls.LSResourceResolver getResourceResolver()
Gets the currentLSResourceResolver- Specified by:
getResourceResolverin classjavax.xml.validation.ValidatorHandler- 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
public javax.xml.validation.TypeInfoProvider getTypeInfoProvider()
Obtains theTypeInfoProviderimplementation of thisValidatorHandler. The obtainedTypeInfoProvidercan be queried during a parse to access the type information determined by the validator.- Specified by:
getTypeInfoProviderin classjavax.xml.validation.ValidatorHandler- Returns:
- A non-null valid
TypeInfoProvider.
-
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator locator)
Receive an object for locating the origin of SAX document events.- Specified by:
setDocumentLocatorin interfaceorg.xml.sax.ContentHandler- Parameters:
locator- an object that can return the location of any SAX document event- See Also:
Locator
-
getProperty
public java.lang.Object getProperty(java.lang.String name) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedExceptionLook 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 classjavax.xml.validation.ValidatorHandler- Parameters:
name- The property name, which is a non-null fully-qualified URI.- Returns:
- The current value of the property.
- Throws:
org.xml.sax.SAXNotRecognizedException- If the property value can't be assigned or retrieved.org.xml.sax.SAXNotSupportedException- When the XMLReader recognizes the property name but cannot determine its value at this time.java.lang.NullPointerException- When the name parameter is null.- See Also:
setProperty(String, Object)
-
setProperty
public void setProperty(java.lang.String name, java.lang.Object object) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedExceptionSet 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 classjavax.xml.validation.ValidatorHandler- Parameters:
name- The property name, which is a non-null fully-qualified URI.object- The requested value for the property.- Throws:
org.xml.sax.SAXNotRecognizedException- If the property value can't be assigned or retrieved.org.xml.sax.SAXNotSupportedException- When theValidatorrecognizes the property name but cannot set the requested value.java.lang.NullPointerException- When the name parameter is null.
-
getConfiguration
public EnterpriseConfiguration getConfiguration()
Get the Configuration object- Returns:
- the Configuration, which will always be schema-aware
-
startDocument
public void startDocument() throws org.xml.sax.SAXExceptionReceive 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 interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException- any SAX exception, possibly wrapping another exception- See Also:
endDocument()
-
endDocument
public void endDocument() throws org.xml.sax.SAXExceptionReceive notification of the end of a document.- Specified by:
endDocumentin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException- any SAX exception, possibly wrapping another exception
-
startPrefixMapping
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws org.xml.sax.SAXExceptionBegin 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 interfaceorg.xml.sax.ContentHandler- 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:
org.xml.sax.SAXException- the client may throw an exception during processing- See Also:
endPrefixMapping(java.lang.String),startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
-
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXExceptionEnd the scope of a prefix-URI mapping.- Specified by:
endPrefixMappingin interfaceorg.xml.sax.ContentHandler- Parameters:
prefix- the prefix that was being mapped. This is the empty string when a default mapping scope ends.- Throws:
org.xml.sax.SAXException- the client may throw an exception during processing
-
startElement
public void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts) throws org.xml.sax.SAXExceptionReceive notification of the beginning of an element.- Specified by:
startElementin interfaceorg.xml.sax.ContentHandler- 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:
org.xml.sax.SAXException- any SAX exception, possibly wrapping another exception
-
endElement
public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXExceptionReceive notification of the end of an element.- Specified by:
endElementin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
characters
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXExceptionReceive notification of character data.- Specified by:
charactersin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXExceptionReceive notification of ignorable whitespace in element content.- Specified by:
ignorableWhitespacein interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
processingInstruction
public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXExceptionReceive notification of a processing instruction.- Specified by:
processingInstructionin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
skippedEntity
public void skippedEntity(java.lang.String name) throws org.xml.sax.SAXExceptionReceive notification of a skipped entity.- Specified by:
skippedEntityin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
startDTD
public void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXExceptionReport the start of DTD declarations, if any.- Specified by:
startDTDin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
endDTD
public void endDTD() throws org.xml.sax.SAXExceptionReport the end of DTD declarations.- Specified by:
endDTDin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
startEntity
public void startEntity(java.lang.String name) throws org.xml.sax.SAXExceptionReport the beginning of some internal and external XML entities.- Specified by:
startEntityin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
endEntity
public void endEntity(java.lang.String name) throws org.xml.sax.SAXExceptionReport the end of an entity.- Specified by:
endEntityin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
startCDATA
public void startCDATA() throws org.xml.sax.SAXExceptionReport the start of a CDATA section.- Specified by:
startCDATAin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
endCDATA
public void endCDATA() throws org.xml.sax.SAXExceptionReport the end of a CDATA section.- Specified by:
endCDATAin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
comment
public void comment(char[] ch, int start, int length) throws org.xml.sax.SAXExceptionReport an XML comment anywhere in the document.- Specified by:
commentin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
notationDecl
public void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXExceptionReceive notification of a notation declaration event.- Specified by:
notationDeclin interfaceorg.xml.sax.DTDHandler- Throws:
org.xml.sax.SAXException
-
unparsedEntityDecl
public void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName) throws org.xml.sax.SAXExceptionReceive notification of an unparsed entity declaration event.- Specified by:
unparsedEntityDeclin interfaceorg.xml.sax.DTDHandler- Throws:
org.xml.sax.SAXException
-
-