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

public Class IDConstraintChecker

extends Verifier
Class Inheritance
Imports
java.util.Map, .Set, .Vector, org.relaxng.datatype.Datatype, org.xml.sax.ErrorHandler, .Locator, .SAXException, com.sun.msv.grammar.xmlschema.ElementDeclExp, .IdentityConstraint, .KeyRefConstraint, .XMLSchemaGrammar, com.sun.msv.util.LightStack, .StartTagInfo, com.sun.msv.verifier.Acceptor, .ErrorInfo, .ValidityViolation, .Verifier, com.sun.msv.verifier.regexp.xmlschema.XSREDocDecl

Verifier with XML Schema-related enforcement.

This class can be used in the same way as Verifier. This class also checks XML Schema's identity constraint.

Author
Kohsuke KAWAGUCHI

Field Summary

Modifier and TypeField and Description
private final Map<IdentityConstraint, LightStack>
activeScopes

a map from IdentityConstraint to a LightStack of SelectorMatcher.

public static final String
public static final String
public static final String
public static final String
public static final String
protected final XMLSchemaGrammar
grammar

the grammar object against which we are validating.

private final Map<SelectorMatcher, Set<Object>>
keyValues

a map from SelectorMatcher to set of KeyValues.

protected final Vector<Matcher>
matchers

active mathcers.

private final Map<SelectorMatcher, SelectorMatcher>
referenceScope

a map from keyref SelectorMatcher to key/unique SelectorMatcher.

Inherited from com.sun.msv.verifier.Verifier:
currentdocDeclERR_DUPLICATE_IDERR_MISSING_ATTRIBUTEERR_UNCOMPLETED_CONTENTERR_UNEXPECTED_ATTRIBUTEERR_UNEXPECTED_ELEMENTERR_UNEXPECTED_STARTTAGERR_UNEXPECTED_TEXTERR_UNSOLD_IDREFerrorHandlerhadErrorpanicLevel

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
add(Matcher matcher)

protected boolean

Returns:

true if this is a new value.
addKeyValue
(SelectorMatcher scope, KeyValue value)

adds a new KeyValue to the value set.

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
)

Overrides com.sun.msv.verifier.Verifier.characters.

Implements org.xml.sax.ContentHandler.characters.

Receive notification of character data.
public void
endDocument()

Overrides com.sun.msv.verifier.Verifier.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.Verifier.endElement.

Implements org.xml.sax.ContentHandler.endElement.

Receive notification of the end of an element.
protected Datatype[]
protected SelectorMatcher
protected KeyValue[]
getKeyValues(SelectorMatcher scope)

gets the all KeyValues that were added within the specified scope.

public static String
localizeMessage(String propertyName, Object arg)

public static String
protected void
onNextAcceptorReady(StartTagInfo sti, Acceptor next)

Overrides com.sun.msv.verifier.Verifier.onNextAcceptorReady.

this method is called from the startElement method after the tag name is processed and the child acceptor is created.
protected void
protected void
protected void
remove(Matcher matcher)

protected void
reportError(ErrorInfo ei, String propKey, Object[] args)

reports an error.

protected void
reportError(Locator loc, ErrorInfo ei, String propKey, Object[] args)

public void
startDocument()

Overrides com.sun.msv.verifier.Verifier.startDocument.

Implements org.xml.sax.ContentHandler.startDocument.

Receive notification of the beginning of a document.
Inherited from com.sun.msv.verifier.Verifier:
getCurrentElementTypegetErrorHandlergetLastCharacterTypeignorableWhitespaceinitisValidonDuplicateIdonErroronErrorsetErrorHandlersetPanicModestartElementverifyText

Field Detail

activeScopesback to summary
private final Map<IdentityConstraint, LightStack> activeScopes

a map from IdentityConstraint to a LightStack of SelectorMatcher. Each stack top keeps the currently active scope for the given IdentityConstraint.

ERR_DOUBLE_MATCHback to summary
public static final String ERR_DOUBLE_MATCH
ERR_NOT_UNIQUEback to summary
public static final String ERR_NOT_UNIQUE
ERR_NOT_UNIQUE_DIAGback to summary
public static final String ERR_NOT_UNIQUE_DIAG
ERR_UNDEFINED_KEYback to summary
public static final String ERR_UNDEFINED_KEY
ERR_UNMATCHED_KEY_FIELDback to summary
public static final String ERR_UNMATCHED_KEY_FIELD
grammarback to summary
protected final XMLSchemaGrammar grammar

the grammar object against which we are validating.

keyValuesback to summary
private final Map<SelectorMatcher, Set<Object>> keyValues

a map from SelectorMatcher to set of KeyValues. One SelectorMatcher correponds to one scope of the identity constraint.

matchersback to summary
protected final Vector<Matcher> matchers

active mathcers.

referenceScopeback to summary
private final Map<SelectorMatcher, SelectorMatcher> referenceScope

a map from keyref SelectorMatcher to key/unique SelectorMatcher. Given a keyref scope, this map stores which key scope should it refer to.

Constructor Detail

IDConstraintCheckerback to summary
public IDConstraintChecker(XMLSchemaGrammar grammar, ErrorHandler errorHandler)

Method Detail

addback to summary
protected void add(Matcher matcher)
addKeyValueback to summary
protected boolean addKeyValue(SelectorMatcher scope, KeyValue value)

adds a new KeyValue to the value set.

Returns:boolean

true if this is a new value.

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

Overrides com.sun.msv.verifier.Verifier.characters.

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

Overrides com.sun.msv.verifier.Verifier.endDocument.

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

Overrides com.sun.msv.verifier.Verifier.feedAttribute.

getActiveScopeback to summary
protected SelectorMatcher getActiveScope(IdentityConstraint c)
getKeyValuesback to summary
protected KeyValue[] getKeyValues(SelectorMatcher scope)

gets the all KeyValues that were added within the specified scope.

localizeMessageback to summary
public static String localizeMessage(String propertyName, Object arg)
localizeMessageback to summary
public static String localizeMessage(String propertyName, Object[] args)

Hides com.sun.msv.verifier.Verifier.localizeMessage.

onNextAcceptorReadyback to summary
protected void onNextAcceptorReady(StartTagInfo sti, Acceptor next) throws SAXException

Overrides com.sun.msv.verifier.Verifier.onNextAcceptorReady.

Doc from com.sun.msv.verifier.Verifier.onNextAcceptorReady.

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.

popActiveScopeback to summary
protected void popActiveScope(IdentityConstraint c, SelectorMatcher matcher)
pushActiveScopeback to summary
protected void pushActiveScope(IdentityConstraint c, SelectorMatcher matcher)
removeback to summary
protected void remove(Matcher matcher)
reportErrorback to summary
protected void reportError(ErrorInfo ei, String propKey, Object[] args) throws SAXException

reports an error.

reportErrorback to summary
protected void reportError(Locator loc, ErrorInfo ei, String propKey, Object[] args) throws SAXException
startDocumentback to summary
public void startDocument() throws SAXException

Overrides com.sun.msv.verifier.Verifier.startDocument.

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