com.sun.msv.verifier

Class Verifier

Implemented Interfaces:
ContentHandler, DTDHandler, IDContextProvider2, IVerifier, ValidationContext, VerifierHandler
Known Direct 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_DUPLICATE_ID
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

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
onDuplicateId(String id)
this method is called when a duplicate id value is found.
void
setErrorHandler(ErrorHandler handler)
void
setPanicMode(boolean usePanicMode)
Turns on/off the panic mode.
void
startDocument()
void
startElement(String namespaceUri, String localName, String qName, Attributes atts)

Methods inherited from class com.sun.msv.verifier.AbstractVerifier

endElement, endPrefixMapping, getBaseUri, getLocator, isNotation, isUnparsedEntity, notationDecl, onID, processingInstruction, resolveNamespacePrefix, setDocumentLocator, skippedEntity, startElement, startPrefixMapping, unparsedEntityDecl

Field Details

ERR_DUPLICATE_ID

public static final String ERR_DUPLICATE_ID

ERR_MISSING_ATTRIBUTE

public static final String ERR_MISSING_ATTRIBUTE

ERR_UNCOMPLETED_CONTENT

public static final String ERR_UNCOMPLETED_CONTENT

ERR_UNEXPECTED_ATTRIBUTE

public static final String ERR_UNEXPECTED_ATTRIBUTE

ERR_UNEXPECTED_ELEMENT

public static final String ERR_UNEXPECTED_ELEMENT

ERR_UNEXPECTED_STARTTAG

public static final String ERR_UNEXPECTED_STARTTAG

ERR_UNEXPECTED_TEXT

public static final String ERR_UNEXPECTED_TEXT

ERR_UNSOLD_IDREF

public static final String ERR_UNSOLD_IDREF

Constructor Details

Verifier

public Verifier(DocumentDeclaration documentDecl,
                ErrorHandler errorHandler)

Method Details

characters

public void characters(char[] buf,
                       int start,
                       int len)
            throws SAXException

endDocument

public void endDocument()
            throws SAXException

endElement

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

getCurrentElementType

public Object getCurrentElementType()
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
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).

getErrorHandler

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

getLastCharacterType

public Datatype[] getLastCharacterType()
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
Returns:
null if type-assignment was not possible.

ignorableWhitespace

public void ignorableWhitespace(char[] buf,
                                int start,
                                int len)
            throws SAXException

isValid

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

localizeMessage

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

onDuplicateId

public void onDuplicateId(String id)
this method is called when a duplicate id value is found.

setErrorHandler

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

setPanicMode

public final void setPanicMode(boolean usePanicMode)
Turns on/off the panic mode. Panic mode is on by default. Turning it on is good for general use. It prevents false error messages to appear.

However, turning it off is sometimes useful, when you are sure that the structure of the document is almost valid (e.g., validating a document generated by an application or when you are sure about the validity of the structure and only interested in validating datatypes,)

Specified by:
setPanicMode in interface IVerifier

startDocument

public void startDocument()
            throws SAXException

startElement

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