Top Description Inners Fields Constructors Methods
com.sun.msv.verifier

public Class Verifier

extends AbstractVerifier
implements IVerifier
Class Inheritance
All Implemented Interfaces
com.sun.msv.verifier.IVerifier, org.iso_relax.verifier.VerifierHandler, org.xml.sax.ContentHandler
Known Direct Subclasses
com.sun.msv.verifier.identity.IDConstraintChecker, com.sun.msv.verifier.psvi.TypeDetector, com.sun.msv.relaxns.verifier.TREXIslandVerifier
Imports
java.util.Iterator, .Set, org.relaxng.datatype.Datatype, org.xml.sax.Attributes, .ErrorHandler, .SAXException, com.sun.msv.datatype.xsd.StringType, com.sun.msv.grammar.IDContextProvider2, com.sun.msv.util.DatatypeRef, .StartTagInfo, .StringRef

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final DatatypeRef
attributeType

the same instance is reused by the feedAttribute method to reduce the number of the object creation.

private final DatatypeRef
characterType

this field is used to receive type information of character literals.

protected Acceptor
private static final int
protected final DocumentDeclaration
docDecl

Schema object against which the validation will be done

private Set<String>
duplicateIds

Stores all duplicate id values.

public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
protected ErrorHandler
errorHandler

Error handler

protected boolean
hadError

This flag will be set to true if an error is found

private int
initialPanicLevel

Initial panic level when an error is found.

private boolean
isFinished

This flag will be set to true after endDocument method is called.

protected int
panicLevel

Panic level.

pack-priv Verifier.Context
stack

context stack

private final StartTagInfo
sti

An object used to store start tag information.

private int
stringCareLevel

current string care level.

private StringBuffer
text

characters that were read (but not processed)

Inherited from com.sun.msv.verifier.AbstractVerifier:
dummyLocatoridrefsidslocatornamespaceSupportperformIDcheck

Constructor Summary

AccessConstructor and Description
public
Verifier(DocumentDeclaration documentDecl, ErrorHandler errorHandler)

Method Summary

Modifier and TypeMethod and Description
public void
characters(char[]
the characters from the XML document
buf
,
int
the start position in the array
start
,
int
the number of characters to read from the array
len
)

Implements org.xml.sax.ContentHandler.characters.

Receive notification of character data.
public void
endDocument()

Implements org.xml.sax.ContentHandler.endDocument.

Receive notification of the end of a document.
public void
endElement(String
the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed
namespaceUri
,
String
the local name (without prefix), or the empty string if Namespace processing is not being performed
localName
,
String
the qualified XML name (with prefix), or the empty string if qualified names are not available
qName
)

Overrides com.sun.msv.verifier.AbstractVerifier.endElement.

Implements org.xml.sax.ContentHandler.endElement.

Receive notification of the end of an element.
protected Datatype[]
feedAttribute(Acceptor child, String uri, String localName, String qName, String value)

public Object
public final ErrorHandler
public Datatype[]
getLastCharacterType()

Implements com.sun.msv.verifier.IVerifier.getLastCharacterType.

gets DataType that validated the last characters.
public void
ignorableWhitespace(char[]
the characters from the XML document
buf
,
int
the start position in the array
start
,
int
the number of characters to read from the array
len
)

Implements org.xml.sax.ContentHandler.ignorableWhitespace.

Receive notification of ignorable whitespace in element content.
protected void
public final boolean
isValid()

Implements com.sun.msv.verifier.IVerifier.isValid.

checks if the document was valid.
public static String
localizeMessage(String propertyName, Object[] args)

public void
onDuplicateId(String id)

Implements abstract com.sun.msv.verifier.AbstractVerifier.onDuplicateId.

this method is called when a duplicate id value is found.
protected ValidityViolation
onError(StringRef ref, String defaultMsg, ErrorInfo ei)

signals an error.

protected ValidityViolation
protected void
onNextAcceptorReady(StartTagInfo sti, Acceptor nextAcceptor)

this method is called from the startElement method after the tag name is processed and the child acceptor is created.

public final void
public final void
setPanicMode(boolean usePanicMode)

Implements com.sun.msv.verifier.IVerifier.setPanicMode.

Turns on/off the panic mode.
public void
startDocument()

Implements org.xml.sax.ContentHandler.startDocument.

Receive notification of the beginning of a document.
public void
startElement(String
the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed
namespaceUri
,
String
the local name (without prefix), or the empty string if Namespace processing is not being performed
localName
,
String
the qualified name (with prefix), or the empty string if qualified names are not available
qName
,
Attributes
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
atts
)

Overrides com.sun.msv.verifier.AbstractVerifier.startElement.

Implements org.xml.sax.ContentHandler.startElement.

Receive notification of the beginning of an element.
protected void
Inherited from com.sun.msv.verifier.AbstractVerifier:
endPrefixMappinggetBaseUrigetLocatorisNotationisUnparsedEntitynotationDeclonIDprocessingInstructionresolveNamespacePrefixsetDocumentLocatorskippedEntitystartPrefixMappingunparsedEntityDecl

Field Detail

attributeTypeback to summary
private final DatatypeRef attributeType

the same instance is reused by the feedAttribute method to reduce the number of the object creation.

characterTypeback to summary
private final DatatypeRef characterType

this field is used to receive type information of character literals.

currentback to summary
protected Acceptor current
DEFAULT_PANIC_LEVELback to summary
private static final int DEFAULT_PANIC_LEVEL
docDeclback to summary
protected final DocumentDeclaration docDecl

Schema object against which the validation will be done

duplicateIdsback to summary
private Set<String> duplicateIds

Stores all duplicate id values. Errors are reported at the endDocument method because the onDuplicateId method cannot throw an exception.

ERR_DUPLICATE_IDback to summary
public static final String ERR_DUPLICATE_ID
ERR_MISSING_ATTRIBUTEback to summary
public static final String ERR_MISSING_ATTRIBUTE
ERR_UNCOMPLETED_CONTENTback to summary
public static final String ERR_UNCOMPLETED_CONTENT
ERR_UNEXPECTED_ATTRIBUTEback to summary
public static final String ERR_UNEXPECTED_ATTRIBUTE
ERR_UNEXPECTED_ELEMENTback to summary
public static final String ERR_UNEXPECTED_ELEMENT
ERR_UNEXPECTED_STARTTAGback to summary
public static final String ERR_UNEXPECTED_STARTTAG
ERR_UNEXPECTED_TEXTback to summary
public static final String ERR_UNEXPECTED_TEXT
ERR_UNSOLD_IDREFback to summary
public static final String ERR_UNSOLD_IDREF
errorHandlerback to summary
protected ErrorHandler errorHandler

Error handler

hadErrorback to summary
protected boolean hadError

This flag will be set to true if an error is found

initialPanicLevelback to summary
private int initialPanicLevel

Initial panic level when an error is found. If this value is bigger, MSV will take more time to recover from errors, Setting this value to 0 means turning the panic mode off entirely.

isFinishedback to summary
private boolean isFinished

This flag will be set to true after endDocument method is called.

panicLevelback to summary
protected int panicLevel

Panic level. If the level is non-zero, createChildAcceptors will silently recover from error. This effectively suppresses spurious error messages. This value is set to INITIAL_PANIC_LEVEL when first an error is encountered, and is decreased by successful stepForward and createChildAcceptor. This value is also propagated to child acceptors.

stackback to summary
pack-priv Verifier.Context stack

context stack

stiback to summary
private final StartTagInfo sti

An object used to store start tag information. the same object is reused.

stringCareLevelback to summary
private int stringCareLevel

current string care level. See Acceptor.getStringCareLevel

textback to summary
private StringBuffer text

characters that were read (but not processed)

Constructor Detail

Verifierback to summary
public Verifier(DocumentDeclaration documentDecl, ErrorHandler errorHandler)

Method Detail

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

Implements org.xml.sax.ContentHandler.characters.

Doc from org.xml.sax.ContentHandler.characters.

Receive notification of character data.

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.

The application must not attempt to read from the array outside of the specified range.

Individual characters may consist of more than one Java char value. There are two important cases where this happens, because characters can't be represented in just sixteen bits. In one case, characters are represented in a Surrogate Pair, using two special Unicode values. Such characters are in the so-called "Astral Planes", with a code point above U+FFFF. A second case involves composite characters, such as a base character combining with one or more accent characters.

Your code should not assume that algorithms using char-at-a-time idioms will be working in character units; in some cases they will split characters. This is relevant wherever XML permits arbitrary characters, such as attribute values, processing instruction data, and comments as well as in data reported from this method. It's also generally relevant whenever Java code manipulates internationalized text; the issue isn't unique to XML.

Note that some parsers will report whitespace in element content using the ignorableWhitespace method rather than this one (validating parsers must do so).

Parameters
buf:char[]

the characters from the XML document

start:int

the start position in the array

len:int

the number of characters to read from the array

Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
endDocumentback to summary
public void endDocument() throws SAXException

Implements org.xml.sax.ContentHandler.endDocument.

Doc from org.xml.sax.ContentHandler.endDocument.

Receive notification of the end of a document.

This method is invoked by the parser to signal it has reached the end of the document after successfully completing the parsing process. After the event, the parser will return the control to the application.

Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
endElementback to summary
public void endElement(String namespaceUri, String localName, String qName) throws SAXException

Overrides com.sun.msv.verifier.AbstractVerifier.endElement.

Implements org.xml.sax.ContentHandler.endElement.

Doc from org.xml.sax.ContentHandler.endElement.

Receive notification of the end of an element.

The SAX parser will invoke this method at the end of every element in the XML document; there will be a corresponding startElement event for every endElement event (even when the element is empty).

For information on the names, see startElement.

Parameters
namespaceUri:String

the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed

localName:String

the local name (without prefix), or the empty string if Namespace processing is not being performed

qName:String

the qualified XML name (with prefix), or the empty string if qualified names are not available

Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
feedAttributeback to summary
protected Datatype[] feedAttribute(Acceptor child, String uri, String localName, String qName, String value) throws SAXException
getCurrentElementTypeback to summary
public Object getCurrentElementType()

Implements com.sun.msv.verifier.IVerifier.getCurrentElementType.

Doc from com.sun.msv.verifier.IVerifier.getCurrentElementType.

returns current element type. Actual java type depends on the implementation. This method works correctly only when called immediately after handling startElement event.

Returns:Object

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

getErrorHandlerback to summary
public final ErrorHandler getErrorHandler()

Implements com.sun.msv.verifier.IVerifier.getErrorHandler.

getLastCharacterTypeback to summary
public Datatype[] getLastCharacterType()

Implements com.sun.msv.verifier.IVerifier.getLastCharacterType.

Doc from com.sun.msv.verifier.IVerifier.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.

Returns:Datatype[]

null if type-assignment was not possible.

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

Implements org.xml.sax.ContentHandler.ignorableWhitespace.

Doc from org.xml.sax.ContentHandler.ignorableWhitespace.

Receive notification of ignorable whitespace in element content.

Validating Parsers must use this method to report each chunk of whitespace in element content (see the W3C XML 1.0 recommendation, section 2.10): non-validating parsers may also use this method if they are capable of parsing and using content models.

SAX parsers may return all contiguous whitespace in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.

The application must not attempt to read from the array outside of the specified range.

Parameters
buf:char[]

the characters from the XML document

start:int

the start position in the array

len:int

the number of characters to read from the array

Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
initback to summary
protected void init()

Overrides com.sun.msv.verifier.AbstractVerifier.init.

isValidback to summary
public final boolean isValid()

Implements com.sun.msv.verifier.IVerifier.isValid.

Doc from com.sun.msv.verifier.IVerifier.isValid.

checks if the document was valid. This method may not be called before verification was completed.

Returns:boolean

Doc from org.iso_relax.verifier.VerifierHandler.isValid.

true if the document was valid, false if not.

localizeMessageback to summary
public static String localizeMessage(String propertyName, Object[] args)
onDuplicateIdback to summary
public void onDuplicateId(String id)

Implements abstract com.sun.msv.verifier.AbstractVerifier.onDuplicateId.

Doc from com.sun.msv.verifier.AbstractVerifier.onDuplicateId.

this method is called when a duplicate id value is found.

onErrorback to summary
protected ValidityViolation onError(StringRef ref, String defaultMsg, ErrorInfo ei) throws SAXException

signals an error. This method can be overrided by the derived class to provide different behavior.

onErrorback to summary
protected ValidityViolation onError(String msg, ErrorInfo ei) throws SAXException
onNextAcceptorReadyback to summary
protected void onNextAcceptorReady(StartTagInfo sti, Acceptor nextAcceptor) throws SAXException

this method is called from the startElement method after the tag name is processed and the child acceptor is created.

This method is called before the attributes are consumed.

derived class can use this method to do something useful.

setErrorHandlerback to summary
public final void setErrorHandler(ErrorHandler handler)

Implements com.sun.msv.verifier.IVerifier.setErrorHandler.

setPanicModeback to summary
public final void setPanicMode(boolean usePanicMode)

Implements com.sun.msv.verifier.IVerifier.setPanicMode.

Doc from com.sun.msv.verifier.IVerifier.setPanicMode.

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

startDocumentback to summary
public void startDocument() throws SAXException

Implements org.xml.sax.ContentHandler.startDocument.

Doc from org.xml.sax.ContentHandler.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).

Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
startElementback to summary
public void startElement(String namespaceUri, String localName, String qName, Attributes atts) throws SAXException

Overrides com.sun.msv.verifier.AbstractVerifier.startElement.

Implements org.xml.sax.ContentHandler.startElement.

Doc from org.xml.sax.ContentHandler.startElement.

Receive notification of the beginning of an element.

The Parser will invoke this method at the beginning of every element in the XML document; there will be a corresponding endElement event for every startElement event (even when the element is empty). All of the element's content will be reported, in order, before the corresponding endElement event.

This event allows up to three name components for each element:

  1. the Namespace URI;
  2. the local name; and
  3. the qualified (prefixed) name.

Any or all of these may be provided, depending on the values of the http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes properties:

  • the Namespace URI and local name are required when the namespaces property is true (the default), and are optional when the namespaces property is false (if one is specified, both must be);
  • the qualified name is required when the namespace-prefixes property is true, and is optional when the namespace-prefixes property is false (the default).

Note that the attribute list provided will contain only attributes with explicit values (specified or defaulted): #IMPLIED attributes will be omitted. The attribute list will contain attributes used for Namespace declarations (xmlns* attributes) only if the http://xml.org/sax/features/namespace-prefixes property is true (it is false by default, and support for a true value is optional).

Like characters(), attribute values may have characters that need more than one char value.

Parameters
namespaceUri:String

the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed

localName:String

the local name (without prefix), or the empty string if Namespace processing is not being performed

qName:String

the qualified name (with prefix), or the empty string if qualified names are not available

atts:Attributes

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

Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
verifyTextback to summary
protected void verifyText() throws SAXException
com.sun.msv.verifier back to summary

private final Class Verifier.Context

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final Acceptor
pack-priv int
pack-priv final Verifier.Context
pack-priv final int

Constructor Summary

AccessConstructor and Description
pack-priv
Context(Verifier.Context prev, Acceptor acc, int scl, int plv)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

acceptorback to summary
pack-priv final Acceptor acceptor
panicLevelback to summary
pack-priv int panicLevel
previousback to summary
pack-priv final Verifier.Context previous
stringCareLevelback to summary
pack-priv final int stringCareLevel

Constructor Detail

Contextback to summary
pack-priv Context(Verifier.Context prev, Acceptor acc, int scl, int plv)