Top Description Fields Constructors Methods
com.ctc.wstx.msv

public final Class GenericMsvValidator

extends XMLValidator
implements IDContextProvider2, XMLStreamConstants
Class Inheritance
All Implemented Interfaces
javax.xml.stream.XMLStreamConstants, com.sun.msv.grammar.IDContextProvider2, org.relaxng.datatype.ValidationContext
Imports
java.util.*, javax.xml.namespace.QName, javax.xml.stream.Location, .XMLStreamConstants, .XMLStreamException, org.codehaus.stax2.validation.*, org.relaxng.datatype.Datatype, com.sun.msv.grammar.IDContextProvider2, com.sun.msv.util.DatatypeRef, .StartTagInfo, .StringRef, com.sun.msv.verifier.Acceptor, .DocumentDeclaration, com.sun.msv.verifier.regexp.StringToken, com.ctc.wstx.util.ElementId, .ElementIdMap, .PrefixedName, .TextAccumulator

Generic validator instance to be used for all Multi-Schema Validator backed implementations. A common class can be used since functionality is almost identical between variants (RNG, W3C SChema); minor differences that exist can be configured by settings provided.

Note about id context provider interface: while it'd be nice to separate that part out, it is unfortunately closely tied to the validation process. Hence it's directly implemented by this class.

Field Summary

Modifier and TypeField and Description
pack-priv final ArrayList<Object>
pack-priv final AttributeProxy
mAttributeProxy

This object provides limited access to attribute values of the currently validated element.

pack-priv final ValidationContext
pack-priv Acceptor
pack-priv String
pack-priv String
pack-priv final StringRef
pack-priv ElementIdMap
mIdDefs

Map that contains information about element id (values of attributes or textual content with type ID) declarations and references

pack-priv final XMLValidationSchema
pack-priv XMLValidationProblem
mProblem

Sometimes a problem object has to be temporarily stored, and only reported later on.

pack-priv final StartTagInfo
mStartTag

StartTagInfo instance need not be thread-safe, and it is not immutable so let's reuse one instance during a single validation.

protected String
mStartTagPrefix

Since `StartTagInfo` has no place for prefix, hold reference to one here

pack-priv final TextAccumulator
pack-priv final DocumentDeclaration
Inherited from org.codehaus.stax2.validation.XMLValidator:
CONTENT_ALLOW_ANY_TEXTCONTENT_ALLOW_NONECONTENT_ALLOW_UNDEFINEDCONTENT_ALLOW_VALIDATABLE_TEXTCONTENT_ALLOW_WSCONTENT_ALLOW_WS_NONSTRICT

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private String
_name(QName qn, String prefix, String suffix)

private QName
_qname(String ns, String local, String prefix)

private QName
pack-priv void
public String
getAttributeType(int index)

Implements abstract org.codehaus.stax2.validation.XMLValidator.getAttributeType.

Method for getting schema-specified type of an attribute, if information is available.

pack-priv PrefixedName
public String
getBaseUri()

Implements org.relaxng.datatype.ValidationContext.getBaseUri.

Returns the base URI of the context.

pack-priv PrefixedName
public int
getIdAttrIndex()

Implements abstract org.codehaus.stax2.validation.XMLValidator.getIdAttrIndex.

Method for finding out the index of the attribute that is of type ID; derived from DTD, W4C Schema, or some other validation source.

public int
getNotationAttrIndex()

Implements abstract org.codehaus.stax2.validation.XMLValidator.getNotationAttrIndex.

Method for finding out the index of the attribute (collected using the attribute collector; having DTD/Schema-derived info in same order) that is of type NOTATION.

public XMLValidationSchema
getSchema()

Implements abstract org.codehaus.stax2.validation.XMLValidator.getSchema.

Returns the schema instance that created this validator object, if known (and applicable).

public boolean
isNotation(String notationName)

Implements org.relaxng.datatype.ValidationContext.isNotation.

Checks if a notation is declared with the specified name.

public boolean
isUnparsedEntity(String entityName)

Implements org.relaxng.datatype.ValidationContext.isUnparsedEntity.

Checks if an unparsed entity is declared with the specified name.

public void
onID(Datatype datatype, StringToken idToken)

Implements com.sun.msv.grammar.IDContextProvider2.onID.

Note

we have to throw a dummy marker exception, which merely signals that a validation problem is to be reported.

private void
reportError(StringRef errorRef, int type, QName name)

private void
private void
public String
resolveNamespacePrefix(String prefix)

Implements org.relaxng.datatype.ValidationContext.resolveNamespacePrefix.

Resolves a namespace prefix to the corresponding namespace URI.

public String
validateAttribute(String localName, String uri, String prefix, String value)

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateAttribute.

Callback method called on validator to give it a chance to validate the value of an attribute, as well as to normalize its value if appropriate (remove leading/trailing/intervening white space for certain token types etc.).

public String
validateAttribute(String localName, String uri, String prefix, char[]
Character array that contains value (possibly along with some other text)
valueChars
,
int
Index of the first character of the value in in valueChars array
valueStart
,
int
Index of the character AFTER the last character; so that the length of the value String is valueEnd - valueStart
valueEnd
)

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateAttribute.

Callback method called on validator to give it a chance to validate the value of an attribute, as well as to normalize its value if appropriate (remove leading/trailing/intervening white space for certain token types etc.).

public int
validateElementAndAttributes()

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateElementAndAttributes.

Method called after calling validateAttribute on all attributes (if any), but before starting to handle element content.

public int

Returns:

Validation state that should be effective for the parent element state
validateElementEnd
(String localName, String uri, String prefix)

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateElementEnd.

Method called right after encountering an element close tag.

public void
validateElementStart(String localName, String uri, String prefix)

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateElementStart.

Method called to update information about the newly encountered (start) element.

public void
validateText(String
Text content to validate
text
,
boolean
Whether this text content is the last text segment before a close element; true if it is, false if it is not, or no determination can be made. Can be used for optimizing validation -- if this is true, no text needs to be buffered since no more will be sent before the current element closes.
lastTextSegment
)

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateText.

Method called to validate textual content.

public void
validateText(char[]
Character array that contains text content to validate
cbuf
,
int
Index of the first character of the content to validate
textStart
,
int
Character following the last character of the content to validate (that is, length of content to validate is textEnd - textStart).
textEnd
,
boolean
Whether this text content is the last text segment before a close element; true if it is, false if it is not, or no determination can be made. Can be used for optimizing validation -- if this is true, no text needs to be buffered since no more will be sent before the current element closes.
lastTextSegment
)

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateText.

Method called to validate textual content.

public void
validationCompleted(boolean
Flag that indicates whether this method was called by the context due to the end of the stream (true); or by an application requesting end of validation (false).
eod
)

Implements abstract org.codehaus.stax2.validation.XMLValidator.validationCompleted.

Method called when the validation is completed; either due to the input stream ending, or due to an explicit 'stop validation' request by the application (via context object).

Inherited from org.codehaus.stax2.validation.XMLValidator:
getSchemaType

Field Detail

mAcceptorsback to summary
pack-priv final ArrayList<Object> mAcceptors
mAttributeProxyback to summary
pack-priv final AttributeProxy mAttributeProxy

This object provides limited access to attribute values of the currently validated element.

mContextback to summary
pack-priv final ValidationContext mContext
mCurrAcceptorback to summary
pack-priv Acceptor mCurrAcceptor
mCurrAttrLocalNameback to summary
pack-priv String mCurrAttrLocalName
mCurrAttrPrefixback to summary
pack-priv String mCurrAttrPrefix
mErrorRefback to summary
pack-priv final StringRef mErrorRef
mIdDefsback to summary
pack-priv ElementIdMap mIdDefs

Map that contains information about element id (values of attributes or textual content with type ID) declarations and references

mParentSchemaback to summary
pack-priv final XMLValidationSchema mParentSchema
mProblemback to summary
pack-priv XMLValidationProblem mProblem

Sometimes a problem object has to be temporarily stored, and only reported later on. This happens when exceptions can not be thrown via code outside of Woodstox (like validation methods in MSV that do callbacks).

mStartTagback to summary
pack-priv final StartTagInfo mStartTag

StartTagInfo instance need not be thread-safe, and it is not immutable so let's reuse one instance during a single validation.

mStartTagPrefixback to summary
protected String mStartTagPrefix

Since `StartTagInfo` has no place for prefix, hold reference to one here

mTextAccumulatorback to summary
pack-priv final TextAccumulator mTextAccumulator
mVGMback to summary
pack-priv final DocumentDeclaration mVGM

Constructor Detail

GenericMsvValidatorback to summary
public GenericMsvValidator(XMLValidationSchema parent, ValidationContext ctxt, DocumentDeclaration vgm)

Method Detail

_nameback to summary
private String _name(QName qn, String prefix, String suffix)
_qnameback to summary
private QName _qname(String ns, String local, String prefix)
_startTagAsQNameback to summary
private QName _startTagAsQName()
doValidateTextback to summary
pack-priv void doValidateText(TextAccumulator textAcc) throws XMLStreamException
getAttributeTypeback to summary
public String getAttributeType(int index)

Implements abstract org.codehaus.stax2.validation.XMLValidator.getAttributeType.

Doc from org.codehaus.stax2.validation.XMLValidator.getAttributeType.

Method for getting schema-specified type of an attribute, if information is available. If not, validators can return null to explicitly indicate no information was available.

Annotations
@Override
getAttrPNameback to summary
pack-priv PrefixedName getAttrPName()
getBaseUriback to summary
public String getBaseUri()

Implements org.relaxng.datatype.ValidationContext.getBaseUri.

Doc from org.relaxng.datatype.ValidationContext.getBaseUri.

Returns the base URI of the context. The null string may be returned if no base URI is known.

Annotations
@Override
getElementPNameback to summary
pack-priv PrefixedName getElementPName()
getIdAttrIndexback to summary
public int getIdAttrIndex()

Implements abstract org.codehaus.stax2.validation.XMLValidator.getIdAttrIndex.

Doc from org.codehaus.stax2.validation.XMLValidator.getIdAttrIndex.

Method for finding out the index of the attribute that is of type ID; derived from DTD, W4C Schema, or some other validation source. Usually schemas explicitly specifies that at most one attribute can have this type for any element.

Returns:int

Index of the attribute with type ID, in the current element, if one exists: -1 otherwise

Annotations
@Override
getNotationAttrIndexback to summary
public int getNotationAttrIndex()

Implements abstract org.codehaus.stax2.validation.XMLValidator.getNotationAttrIndex.

Doc from org.codehaus.stax2.validation.XMLValidator.getNotationAttrIndex.

Method for finding out the index of the attribute (collected using the attribute collector; having DTD/Schema-derived info in same order) that is of type NOTATION. DTD explicitly specifies that at most one attribute can have this type for any element.

Returns:int

Index of the attribute with type NOTATION, in the current element, if one exists: -1 otherwise

Annotations
@Override
getSchemaback to summary
public XMLValidationSchema getSchema()

Implements abstract org.codehaus.stax2.validation.XMLValidator.getSchema.

Doc from org.codehaus.stax2.validation.XMLValidator.getSchema.

Returns the schema instance that created this validator object, if known (and applicable). May return null for some instances: specifically, ValidatorPair will return null since it 'contains' multiple validators and generally does not have just one parent or owner schema.

Annotations
@Override
isNotationback to summary
public boolean isNotation(String notationName)

Implements org.relaxng.datatype.ValidationContext.isNotation.

Doc from org.relaxng.datatype.ValidationContext.isNotation.

Checks if a notation is declared with the specified name.

Returns:boolean

true if the DTD has a notation declaration for the specified name. false otherwise.

Annotations
@Override
isUnparsedEntityback to summary
public boolean isUnparsedEntity(String entityName)

Implements org.relaxng.datatype.ValidationContext.isUnparsedEntity.

Doc from org.relaxng.datatype.ValidationContext.isUnparsedEntity.

Checks if an unparsed entity is declared with the specified name.

Returns:boolean

true if the DTD has an unparsed entity declaration for the specified name. false otherwise.

Annotations
@Override
onIDback to summary
public void onID(Datatype datatype, StringToken idToken) throws IllegalArgumentException

Implements com.sun.msv.grammar.IDContextProvider2.onID.

Note

we have to throw a dummy marker exception, which merely signals that a validation problem is to be reported. This is obviously messy, but has to do for now.

Annotations
@Override
reportErrorback to summary
private void reportError(StringRef errorRef, int type, QName name) throws XMLStreamException
reportErrorback to summary
private void reportError(String msg) throws XMLStreamException
reportErrorback to summary
private void reportError(String msg, Location loc) throws XMLStreamException
resolveNamespacePrefixback to summary
public String resolveNamespacePrefix(String prefix)

Implements org.relaxng.datatype.ValidationContext.resolveNamespacePrefix.

Doc from org.relaxng.datatype.ValidationContext.resolveNamespacePrefix.

Resolves a namespace prefix to the corresponding namespace URI. This method is used for validating the QName type, for example.

If the prefix is "" (empty string), it indicates an unprefixed value. The callee should resolve it as for an unprefixed element, rather than for an unprefixed attribute.

If the prefix is "xml", then the callee must resolve this prefix into "http://www.w3.org/XML/1998/namespace", as defined in the XML Namespaces Recommendation.

Returns:String

namespace URI of this prefix. If the specified prefix is not declared, the implementation must return null.

Annotations
@Override
validateAttributeback to summary
public String validateAttribute(String localName, String uri, String prefix, String value) throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateAttribute.

Doc from org.codehaus.stax2.validation.XMLValidator.validateAttribute.

Callback method called on validator to give it a chance to validate the value of an attribute, as well as to normalize its value if appropriate (remove leading/trailing/intervening white space for certain token types etc.).

Returns:String

Null, if the passed value is fine as is; or a String, if it needs to be replaced. In latter case, caller will replace the value before passing it to other validators. Also, if the attribute value is accessible via caller (as is the case for stream readers), caller should return this value, instead of the original one.

Annotations
@Override
validateAttributeback to summary
public String validateAttribute(String localName, String uri, String prefix, char[] valueChars, int valueStart, int valueEnd) throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateAttribute.

Doc from org.codehaus.stax2.validation.XMLValidator.validateAttribute.

Callback method called on validator to give it a chance to validate the value of an attribute, as well as to normalize its value if appropriate (remove leading/trailing/intervening white space for certain token types etc.).

Parameters
valueChars:char[]

Character array that contains value (possibly along with some other text)

valueStart:int

Index of the first character of the value in in valueChars array

valueEnd:int

Index of the character AFTER the last character; so that the length of the value String is valueEnd - valueStart

Returns:String

Null, if the passed value is fine as is; or a String, if it needs to be replaced. In latter case, caller will replace the value before passing it to other validators. Also, if the attribute value is accessible via caller (as is the case for stream readers), caller should return this value, instead of the original one.

Annotations
@Override
validateElementAndAttributesback to summary
public int validateElementAndAttributes() throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateElementAndAttributes.

Doc from org.codehaus.stax2.validation.XMLValidator.validateElementAndAttributes.

Method called after calling validateAttribute on all attributes (if any), but before starting to handle element content.

Returns:int

One of CONTENT_ALLOW_ constants, to indicate what kind of textual content is allowed at the scope returned to after the element has closed.

Annotations
@Override
validateElementEndback to summary
public int validateElementEnd(String localName, String uri, String prefix) throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateElementEnd.

Doc from org.codehaus.stax2.validation.XMLValidator.validateElementEnd.

Method called right after encountering an element close tag.

Returns:int

Validation state that should be effective for the parent element state

Annotations
@Override
validateElementStartback to summary
public void validateElementStart(String localName, String uri, String prefix) throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateElementStart.

Method called to update information about the newly encountered (start) element. At this point namespace information has been resolved, but no DTD validation has been done. Validator is to do these validations, including checking for attribute value (and existence) compatibility.

Annotations
@Override
validateTextback to summary
public void validateText(String text, boolean lastTextSegment) throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateText.

Doc from org.codehaus.stax2.validation.XMLValidator.validateText.

Method called to validate textual content.

Note

this method is only guaranteed to be called when validateElementAndAttributes() for the currently open element returned CONTENT_ALLOW_VALIDATABLE_TEXT (or, in case of mixed content, validateElementEnd, for the last enclosed element). Otherwise, validator context may choose not to call the method as an optimization.

Parameters
text:String

Text content to validate

lastTextSegment:boolean

Whether this text content is the last text segment before a close element; true if it is, false if it is not, or no determination can be made. Can be used for optimizing validation -- if this is true, no text needs to be buffered since no more will be sent before the current element closes.

Annotations
@Override
validateTextback to summary
public void validateText(char[] cbuf, int textStart, int textEnd, boolean lastTextSegment) throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validateText.

Doc from org.codehaus.stax2.validation.XMLValidator.validateText.

Method called to validate textual content.

Note

this method is only guaranteed to be called when validateElementAndAttributes() for the currently open element returned CONTENT_ALLOW_VALIDATABLE_TEXT (or, in case of mixed content, validateElementEnd, for the last enclosed element). Otherwise, validator context may choose not to call the method as an optimization.

Parameters
cbuf:char[]

Character array that contains text content to validate

textStart:int

Index of the first character of the content to validate

textEnd:int

Character following the last character of the content to validate (that is, length of content to validate is textEnd - textStart).

lastTextSegment:boolean

Whether this text content is the last text segment before a close element; true if it is, false if it is not, or no determination can be made. Can be used for optimizing validation -- if this is true, no text needs to be buffered since no more will be sent before the current element closes.

Annotations
@Override
validationCompletedback to summary
public void validationCompleted(boolean eod) throws XMLStreamException

Implements abstract org.codehaus.stax2.validation.XMLValidator.validationCompleted.

Doc from org.codehaus.stax2.validation.XMLValidator.validationCompleted.

Method called when the validation is completed; either due to the input stream ending, or due to an explicit 'stop validation' request by the application (via context object).

Parameters
eod:boolean

Flag that indicates whether this method was called by the context due to the end of the stream (true); or by an application requesting end of validation (false).

Annotations
@Override