com.sun.msv.verifier
Class VerifierFilter

java.lang.Object
  |
  +--org.xml.sax.helpers.XMLFilterImpl
        |
        +--com.sun.msv.verifier.VerifierFilter
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler, IVerifier, VerifierHandler, XMLFilter, XMLReader

public class VerifierFilter
extends XMLFilterImpl
implements IVerifier

SAX XMLFilter that verifies incoming SAX event stream. This object can be reused to validate multiple documents. Just be careful NOT to use the same object to validate more than one documents at the same time.

Author:
Kohsuke KAWAGUCHI

Constructor Summary
VerifierFilter(DocumentDeclaration documentDecl, ErrorHandler errorHandler)
           
VerifierFilter(IVerifier verifier)
           
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void endDocument()
           
 void endElement(String namespaceURI, String localName, String qName)
           
 void endPrefixMapping(String prefix)
           
 Object getCurrentElementType()
          returns current element type.
 ErrorHandler getErrorHandler()
           
 Datatype[] getLastCharacterType()
          gets DataType that validated the last characters.
 Locator getLocator()
           
 IVerifier getVerifier()
           
 void ignorableWhitespace(char[] ch, int start, int length)
           
 boolean isValid()
          checks if the document was valid.
 void processingInstruction(String target, String data)
           
 void setDocumentLocator(Locator locator)
           
 void setErrorHandler(ErrorHandler handler)
           
 void skippedEntity(String name)
           
 void startDocument()
           
 void startElement(String namespaceURI, String localName, String qName, Attributes atts)
           
 void startPrefixMapping(String prefix, String uri)
           
 
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl
error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getFeature, getParent, getProperty, notationDecl, parse, parse, resolveEntity, setContentHandler, setDTDHandler, setEntityResolver, setFeature, setParent, setProperty, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VerifierFilter

public VerifierFilter(IVerifier verifier)
Parameters:
verifier - Verifier object that performs actual validation.

VerifierFilter

public VerifierFilter(DocumentDeclaration documentDecl,
                      ErrorHandler errorHandler)
Method Detail

isValid

public boolean isValid()
Description copied from interface: IVerifier
checks if the document was valid. This method may not be called before verification was completed.
Specified by:
isValid in interface IVerifier

getCurrentElementType

public Object getCurrentElementType()
Description copied from interface: IVerifier
returns current element type. Actual java type depends on the implementation. This method works correctly only when called immediately after handling startElement event.
Specified by:
getCurrentElementType in interface IVerifier
Following copied from interface: com.sun.msv.verifier.IVerifier
Returns:
null this method returns null when it doesn't support type-assignment feature, or type-assignment is impossible for the current element (for example due to the ambiguous grammar).

getLastCharacterType

public Datatype[] getLastCharacterType()
Description copied from interface: IVerifier
gets DataType that validated the last characters.

This method works correctly only when called immediately after startElement and endElement method. When called, this method returns DataType object that validated the last character literals.

For RELAX NG grammar, this method can return an array of length 2 or more. This happens when the last character matches <list> pattern. In that case, each type corresponds to each token (where tokens are the white-space separation of the last characters).

For any other grammar, this method always returns an array of length 1 (or null, if the type assignment failed).

So when you are using VerifierFilter, you can call this method only in your startElement and endElement method.

Specified by:
getLastCharacterType in interface IVerifier
Following copied from interface: com.sun.msv.verifier.IVerifier
Returns:
null if type-assignment was not possible.

getLocator

public final Locator getLocator()
Specified by:
getLocator in interface IVerifier

getErrorHandler

public final ErrorHandler getErrorHandler()
Specified by:
getErrorHandler in interface IVerifier
Overrides:
getErrorHandler in class XMLFilterImpl

setErrorHandler

public final void setErrorHandler(ErrorHandler handler)
Specified by:
setErrorHandler in interface IVerifier
Overrides:
setErrorHandler in class XMLFilterImpl

getVerifier

public IVerifier getVerifier()

setDocumentLocator

public void setDocumentLocator(Locator locator)
Specified by:
setDocumentLocator in interface ContentHandler
Overrides:
setDocumentLocator in class XMLFilterImpl

startDocument

public void startDocument()
                   throws SAXException
Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class XMLFilterImpl

endDocument

public void endDocument()
                 throws SAXException
Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class XMLFilterImpl

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
Specified by:
startPrefixMapping in interface ContentHandler
Overrides:
startPrefixMapping in class XMLFilterImpl

endPrefixMapping

public void endPrefixMapping(String prefix)
                      throws SAXException
Specified by:
endPrefixMapping in interface ContentHandler
Overrides:
endPrefixMapping in class XMLFilterImpl

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String qName,
                         Attributes atts)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class XMLFilterImpl

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String qName)
                throws SAXException
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class XMLFilterImpl

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Specified by:
characters in interface ContentHandler
Overrides:
characters in class XMLFilterImpl

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Specified by:
ignorableWhitespace in interface ContentHandler
Overrides:
ignorableWhitespace in class XMLFilterImpl

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
Specified by:
processingInstruction in interface ContentHandler
Overrides:
processingInstruction in class XMLFilterImpl

skippedEntity

public void skippedEntity(String name)
                   throws SAXException
Specified by:
skippedEntity in interface ContentHandler
Overrides:
skippedEntity in class XMLFilterImpl