com.sun.msv.verifier
Class Verifier

java.lang.Object
  |
  +--com.sun.msv.verifier.AbstractVerifier
        |
        +--com.sun.msv.verifier.Verifier
All Implemented Interfaces:
ContentHandler, DTDHandler, IDContextProvider, IVerifier, ValidationContext, VerifierHandler
Direct Known Subclasses:
IDConstraintChecker, TypeDetector

public class Verifier
extends AbstractVerifier
implements IVerifier

SAX ContentHandler 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

Field Summary
static String ERR_MISSING_ATTRIBUTE
           
static String ERR_UNCOMPLETED_CONTENT
           
static String ERR_UNEXPECTED_ATTRIBUTE
           
static String ERR_UNEXPECTED_ELEMENT
           
static String ERR_UNEXPECTED_STARTTAG
           
static String ERR_UNEXPECTED_TEXT
           
static String ERR_UNSOLD_IDREF
           
static String ERR_UNSOLD_KEYREF
           
 
Constructor Summary
Verifier(DocumentDeclaration documentDecl, ErrorHandler errorHandler)
           
 
Method Summary
 void characters(char[] buf, int start, int len)
           
 void endDocument()
           
 void endElement(String namespaceUri, String localName, String qName)
           
 Object getCurrentElementType()
          returns current element type.
 ErrorHandler getErrorHandler()
           
 Datatype[] getLastCharacterType()
          gets DataType that validated the last characters.
 void ignorableWhitespace(char[] buf, int start, int len)
           
 boolean isValid()
          checks if the document was valid.
static String localizeMessage(String propertyName, Object[] args)
           
 void setErrorHandler(ErrorHandler handler)
           
 void startDocument()
           
 void startElement(String namespaceUri, String localName, String qName, Attributes atts)
           
 
Methods inherited from class com.sun.msv.verifier.AbstractVerifier
endPrefixMapping, getLocator, isNotation, isUnparsedEntity, notationDecl, onID, onIDREF, processingInstruction, resolveNamespacePrefix, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.msv.verifier.IVerifier
getLocator
 
Methods inherited from interface org.xml.sax.ContentHandler
endPrefixMapping, processingInstruction, setDocumentLocator, skippedEntity, startPrefixMapping
 

Field Detail

ERR_UNEXPECTED_TEXT

public static final String ERR_UNEXPECTED_TEXT

ERR_UNEXPECTED_ATTRIBUTE

public static final String ERR_UNEXPECTED_ATTRIBUTE

ERR_MISSING_ATTRIBUTE

public static final String ERR_MISSING_ATTRIBUTE

ERR_UNEXPECTED_STARTTAG

public static final String ERR_UNEXPECTED_STARTTAG

ERR_UNCOMPLETED_CONTENT

public static final String ERR_UNCOMPLETED_CONTENT

ERR_UNEXPECTED_ELEMENT

public static final String ERR_UNEXPECTED_ELEMENT

ERR_UNSOLD_IDREF

public static final String ERR_UNSOLD_IDREF

ERR_UNSOLD_KEYREF

public static final String ERR_UNSOLD_KEYREF
Constructor Detail

Verifier

public Verifier(DocumentDeclaration documentDecl,
                ErrorHandler errorHandler)
Method Detail

getErrorHandler

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

setErrorHandler

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

isValid

public final 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

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.

startElement

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

endElement

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

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).

characters

public void characters(char[] buf,
                       int start,
                       int len)
                throws SAXException
Specified by:
characters in interface ContentHandler

ignorableWhitespace

public void ignorableWhitespace(char[] buf,
                                int start,
                                int len)
                         throws SAXException
Specified by:
ignorableWhitespace in interface ContentHandler

startDocument

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

endDocument

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

localizeMessage

public static String localizeMessage(String propertyName,
                                     Object[] args)