Top Description Fields Constructors Methods
org.apache.xerces.jaxp.validation

pack-priv final Class ValidatorImpl

extends Validator
implements PSVIProvider
Class Inheritance
All Implemented Interfaces
org.apache.xerces.xs.PSVIProvider
Imports
java.io.IOException, javax.xml.transform.Result, .Source, javax.xml.transform.dom.DOMResult, .DOMSource, javax.xml.transform.sax.SAXResult, .SAXSource, javax.xml.transform.stax.StAXResult, .StAXSource, javax.xml.transform.stream.StreamResult, .StreamSource, javax.xml.validation.Validator, org.apache.xerces.impl.Constants, org.apache.xerces.util.SAXMessageFormatter, org.apache.xerces.xni.parser.XMLConfigurationException, org.apache.xerces.xs.AttributePSVI, .ElementPSVI, .PSVIProvider, org.w3c.dom.ls.LSResourceResolver, org.xml.sax.ErrorHandler, .SAXException, .SAXNotRecognizedException, .SAXNotSupportedException

Implementation of Validator for W3C XML Schemas.

Authors
Kohsuke Kawaguchi, Michael Glavassevich, IBM
Version
$Id: ValidatorImpl.java 713638 2008-11-13 04:42:18Z mrglavas $

Field Summary

Modifier and TypeField and Description
private static final String
CURRENT_ELEMENT_NODE

Property identifier: Current element node.

private final XMLSchemaValidatorComponentManager
fComponentManager

Component manager.

private boolean
fConfigurationChanged

Flag for tracking whether features/properties changed since last reset.

private DOMValidatorHelper
fDOMValidatorHelper

DOM validator helper.

private boolean
fErrorHandlerChanged

Flag for tracking whether the error handler changed since last reset.

private boolean
fResourceResolverChanged

Flag for tracking whether the resource resolver changed since last reset.

private ValidatorHandlerImpl
fSAXValidatorHelper

SAX validator helper.

private StAXValidatorHelper
fStAXValidatorHelper

StAX validator helper.

private StreamValidatorHelper
fStreamValidatorHelper

Stream validator helper.

private static final String
JAXP_SOURCE_RESULT_FEATURE_PREFIX

JAXP Source/Result feature prefix.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public AttributePSVI
getAttributePSVI(int
The attribute index.
index
)

Implements org.apache.xerces.xs.PSVIProvider.getAttributePSVI.

Provides AttributePSVI given the index of an attribute information item in the current element's attribute list.
public AttributePSVI
getAttributePSVIByName(String
The namespace name of an attribute.
uri
,
String
The local name of an attribute.
localname
)

Implements org.apache.xerces.xs.PSVIProvider.getAttributePSVIByName.

Provides AttributePSVI given the namespace name and the local name of an attribute information item in the current element's attribute list.
public ElementPSVI
getElementPSVI()

Implements org.apache.xerces.xs.PSVIProvider.getElementPSVI.

Provides the post schema validation item for the current element information item.
public ErrorHandler
getErrorHandler()

Implements abstract javax.xml.validation.Validator.getErrorHandler.

Gets the current ErrorHandler set to this Validator.
public boolean
getFeature(String
The feature name, which is a non-null fully-qualified URI.
name
)

Overrides javax.xml.validation.Validator.getFeature.

Look up the value of a feature flag.
public Object
getProperty(String
The property name, which is a non-null fully-qualified URI.
name
)

Overrides javax.xml.validation.Validator.getProperty.

Look up the value of a property.
public LSResourceResolver
public void
reset()

Implements abstract javax.xml.validation.Validator.reset.

Reset this Validator to its original configuration.
public void
setErrorHandler(ErrorHandler
A new error handler to be set. This parameter can be null.
errorHandler
)

Implements abstract javax.xml.validation.Validator.setErrorHandler.

Sets the ErrorHandler to receive errors encountered during the validate method invocation.
public void
setFeature(String
The feature name, which is a non-null fully-qualified URI.
name
,
boolean
The requested value of the feature (true or false).
value
)

Overrides javax.xml.validation.Validator.setFeature.

Set the value of a feature flag.
public void
setProperty(String
The property name, which is a non-null fully-qualified URI.
name
,
Object
The requested value for the property.
object
)

Overrides javax.xml.validation.Validator.setProperty.

Set the value of a property.
public void
setResourceResolver(LSResourceResolver
A new resource resolver to be set. This parameter can be null.
resourceResolver
)

Implements abstract javax.xml.validation.Validator.setResourceResolver.

Sets the LSResourceResolver to customize resource resolution while in a validation episode.
public void
validate(Source
XML to be validated. Must be an XML document or XML element and must not be null. For backwards compatibility, the results of attempting to validate anything other than a document or element are implementation-dependent. Implementations must either recognize and process the input or throw an IllegalArgumentException.
source
,
Result
The Result object that receives (possibly augmented) XML. This parameter can be null if the caller is not interested in it. Note that when a DOMResult is used, a validator might just pass the same DOM node from DOMSource to DOMResult (in which case source.getNode()==result.getNode()), it might copy the entire DOM tree, or it might alter the node given by the source.
result
)

Implements abstract javax.xml.validation.Validator.validate.

Validates the specified input and send the augmented validation result to the specified output.
Inherited from javax.xml.validation.Validator:
validate

Field Detail

CURRENT_ELEMENT_NODEback to summary
private static final String CURRENT_ELEMENT_NODE

Property identifier: Current element node.

fComponentManagerback to summary
private final XMLSchemaValidatorComponentManager fComponentManager

Component manager.

fConfigurationChangedback to summary
private boolean fConfigurationChanged

Flag for tracking whether features/properties changed since last reset.

fDOMValidatorHelperback to summary
private DOMValidatorHelper fDOMValidatorHelper

DOM validator helper.

fErrorHandlerChangedback to summary
private boolean fErrorHandlerChanged

Flag for tracking whether the error handler changed since last reset.

fResourceResolverChangedback to summary
private boolean fResourceResolverChanged

Flag for tracking whether the resource resolver changed since last reset.

fSAXValidatorHelperback to summary
private ValidatorHandlerImpl fSAXValidatorHelper

SAX validator helper.

fStAXValidatorHelperback to summary
private StAXValidatorHelper fStAXValidatorHelper

StAX validator helper.

fStreamValidatorHelperback to summary
private StreamValidatorHelper fStreamValidatorHelper

Stream validator helper.

JAXP_SOURCE_RESULT_FEATURE_PREFIXback to summary
private static final String JAXP_SOURCE_RESULT_FEATURE_PREFIX

JAXP Source/Result feature prefix.

Constructor Detail

ValidatorImplback to summary
public ValidatorImpl(XSGrammarPoolContainer grammarContainer)

Method Detail

getAttributePSVIback to summary
public AttributePSVI getAttributePSVI(int index)

Implements org.apache.xerces.xs.PSVIProvider.getAttributePSVI.

Doc from org.apache.xerces.xs.PSVIProvider.getAttributePSVI.

Provides AttributePSVI given the index of an attribute information item in the current element's attribute list. The method must be called by an application while in the scope of the methods which report the start and end of an element at a point where the attribute list is available. For example, for SAX the method must be called while in the scope of the document handler's startElement call. If the method is called outside of the specified scope, the return value is undefined.

Parameters
index:int

The attribute index.

Returns:AttributePSVI

The post schema validation properties of the attribute.

getAttributePSVIByNameback to summary
public AttributePSVI getAttributePSVIByName(String uri, String localname)

Implements org.apache.xerces.xs.PSVIProvider.getAttributePSVIByName.

Doc from org.apache.xerces.xs.PSVIProvider.getAttributePSVIByName.

Provides AttributePSVI given the namespace name and the local name of an attribute information item in the current element's attribute list. The method must be called by an application while in the scope of the methods which report the start and end of an element at a point where the attribute list is available. For example, for SAX the method must be called while in the scope of the document handler's startElement call. If the method is called outside of the specified scope, the return value is undefined.

Parameters
uri:String

The namespace name of an attribute.

localname:String

The local name of an attribute.

Returns:AttributePSVI

The post schema validation properties of the attribute.

getElementPSVIback to summary
public ElementPSVI getElementPSVI()

Implements org.apache.xerces.xs.PSVIProvider.getElementPSVI.

Doc from org.apache.xerces.xs.PSVIProvider.getElementPSVI.

Provides the post schema validation item for the current element information item. The method must be called by an application while in the scope of the methods which report the start and end of an element. For example, for SAX the method must be called within the scope of the document handler's startElement or endElement call. If the method is called outside of the specified scope, the return value is undefined.

Returns:ElementPSVI

The post schema validation infoset for the current element. If an element information item is valid, then in the post-schema-validation infoset the following properties must be available for the element information item: The following properties are available in the scope of the method that reports the start of an element: {element declaration}, {validation context}, {notation}. The {schema information} property is available for the validation root. The {error codes} property is available if any errors occured during validation. The following properties are available in the scope of the method that reports the end of an element: {nil}, {schema specified}, {normalized value},{ member type definition}, {validity}, {validation attempted} . If the declaration has a value constraint, the property {schema default} is available. The {error codes} property is available if any errors occured during validation.

Note

some processors may choose to provide all the PSVI properties in the scope of the method that reports the end of an element.

getErrorHandlerback to summary
public ErrorHandler getErrorHandler()

Implements abstract javax.xml.validation.Validator.getErrorHandler.

Doc from javax.xml.validation.Validator.getErrorHandler.

Gets the current ErrorHandler set to this Validator.

Returns:ErrorHandler

This method returns the object that was last set through the setErrorHandler(ErrorHandler) method, or null if that method has never been called since this Validator has created.

getFeatureback to summary
public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException

Overrides javax.xml.validation.Validator.getFeature.

Doc from javax.xml.validation.Validator.getFeature.

Look up the value of a feature flag.

The feature name is any fully-qualified URI. It is possible for a Validator to recognize a feature name but temporarily be unable to return its value. Some feature values may be available only in specific contexts, such as before, during, or after a validation.

Implementors are free (and encouraged) to invent their own features, using names built on their own URIs.

Parameters
name:String

The feature name, which is a non-null fully-qualified URI.

Returns:boolean

The current value of the feature (true or false).

Exceptions
SAXNotRecognizedException:
If the feature value can't be assigned or retrieved.
SAXNotSupportedException:
When the Validator recognizes the feature name but cannot determine its value at this time.
getPropertyback to summary
public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException

Overrides javax.xml.validation.Validator.getProperty.

Doc from javax.xml.validation.Validator.getProperty.

Look up the value of a property.

The property name is any fully-qualified URI. It is possible for a Validator to recognize a property name but temporarily be unable to return its value. Some property values may be available only in specific contexts, such as before, during, or after a validation.

Validators are not required to recognize any specific property names.

Implementors are free (and encouraged) to invent their own properties, using names built on their own URIs.

Parameters
name:String

The property name, which is a non-null fully-qualified URI.

Returns:Object

The current value of the property.

Exceptions
SAXNotRecognizedException:
If the property value can't be assigned or retrieved.
SAXNotSupportedException:
When the XMLReader recognizes the property name but cannot determine its value at this time.
getResourceResolverback to summary
public LSResourceResolver getResourceResolver()

Implements abstract javax.xml.validation.Validator.getResourceResolver.

Doc from javax.xml.validation.Validator.getResourceResolver.

Gets the current LSResourceResolver set to this Validator.

Returns:LSResourceResolver

This method returns the object that was last set through the setResourceResolver(LSResourceResolver) method, or null if that method has never been called since this Validator has created.

resetback to summary
public void reset()

Implements abstract javax.xml.validation.Validator.reset.

Doc from javax.xml.validation.Validator.reset.

Reset this Validator to its original configuration.

Validator is reset to the same state as when it was created with Schema#newValidator(). reset() is designed to allow the reuse of existing Validators thus saving resources associated with the creation of new Validators.

The reset Validator is not guaranteed to have the same LSResourceResolver or ErrorHandler Objects, e.g. Object#equals(Object obj). It is guaranteed to have a functionally equal LSResourceResolver and ErrorHandler.

setErrorHandlerback to summary
public void setErrorHandler(ErrorHandler errorHandler)

Implements abstract javax.xml.validation.Validator.setErrorHandler.

Doc from javax.xml.validation.Validator.setErrorHandler.

Sets the ErrorHandler to receive errors encountered during the validate method invocation.

Error handler can be used to customize the error handling process during a validation. When an ErrorHandler is set, errors found during the validation will be first sent to the ErrorHandler.

The error handler can abort further validation immediately by throwing SAXException from the handler. Or for example it can print an error to the screen and try to continue the validation by returning normally from the ErrorHandler

If any Throwable is thrown from an ErrorHandler, the caller of the validate method will be thrown the same Throwable object.

Validator is not allowed to throw SAXException without first reporting it to ErrorHandler.

When the ErrorHandler is null, the implementation will behave as if the following ErrorHandler is set:

class DraconianErrorHandler implements ErrorHandler {
    public void fatalError( org.xml.sax.SAXParseException e ) throws SAXException {
        throw e;
    }
    public void error( org.xml.sax.SAXParseException e ) throws SAXException {
        throw e;
    }
    public void warning( org.xml.sax.SAXParseException e ) throws SAXException {
        // noop
    }
}

When a new Validator object is created, initially this field is set to null.

Parameters
errorHandler:ErrorHandler

A new error handler to be set. This parameter can be null.

setFeatureback to summary
public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException

Overrides javax.xml.validation.Validator.setFeature.

Doc from javax.xml.validation.Validator.setFeature.

Set the value of a feature flag.

Feature can be used to control the way a Validator parses schemas, although Validators are not required to recognize any specific feature names.

The feature name is any fully-qualified URI. It is possible for a Validator to expose a feature value but to be unable to change the current value. Some feature values may be immutable or mutable only in specific contexts, such as before, during, or after a validation.

Parameters
name:String

The feature name, which is a non-null fully-qualified URI.

value:boolean

The requested value of the feature (true or false).

Exceptions
SAXNotRecognizedException:
If the feature value can't be assigned or retrieved.
SAXNotSupportedException:
When the Validator recognizes the feature name but cannot set the requested value.
setPropertyback to summary
public void setProperty(String name, Object object) throws SAXNotRecognizedException, SAXNotSupportedException

Overrides javax.xml.validation.Validator.setProperty.

Doc from javax.xml.validation.Validator.setProperty.

Set the value of a property.

The property name is any fully-qualified URI. It is possible for a Validator to recognize a property name but to be unable to change the current value. Some property values may be immutable or mutable only in specific contexts, such as before, during, or after a validation.

All implementations that implement JAXP 1.5 or newer are required to support the javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD and javax.xml.XMLConstants#ACCESS_EXTERNAL_SCHEMA properties.

Parameters
name:String

The property name, which is a non-null fully-qualified URI.

object:Object

The requested value for the property.

Exceptions
SAXNotRecognizedException:
If the property value can't be assigned or retrieved.
SAXNotSupportedException:
When the Validator recognizes the property name but cannot set the requested value.
setResourceResolverback to summary
public void setResourceResolver(LSResourceResolver resourceResolver)

Implements abstract javax.xml.validation.Validator.setResourceResolver.

Doc from javax.xml.validation.Validator.setResourceResolver.

Sets the LSResourceResolver to customize resource resolution while in a validation episode.

Validator uses a LSResourceResolver when it needs to locate external resources while a validation, although exactly what constitutes "locating external resources" is up to each schema language.

When the LSResourceResolver is null, the implementation will behave as if the following LSResourceResolver is set:

class DumbLSResourceResolver implements LSResourceResolver {
    public org.w3c.dom.ls.LSInput resolveResource(
        String publicId, String systemId, String baseURI) {

        return null; // always return null
    }
}

If a LSResourceResolver throws a RuntimeException (or instances of its derived classes), then the Validator will abort the parsing and the caller of the validate method will receive the same RuntimeException.

When a new Validator object is created, initially this field is set to null.

Parameters
resourceResolver:LSResourceResolver

A new resource resolver to be set. This parameter can be null.

validateback to summary
public void validate(Source source, Result result) throws SAXException, IOException

Implements abstract javax.xml.validation.Validator.validate.

Doc from javax.xml.validation.Validator.validate.

Validates the specified input and send the augmented validation result to the specified output.

This method places the following restrictions on the types of the Source/Result accepted.

Source / Result Accepted
javax.xml.transform.stream.StreamSource javax.xml.transform.sax.SAXSource javax.xml.transform.dom.DOMSource javax.xml.transform.stax.StAXSource
null OK OK OK OK
javax.xml.transform.stream.StreamResult OK IllegalArgumentException IllegalArgumentException IllegalArgumentException
javax.xml.transform.sax.SAXResult IllegalArgumentException OK IllegalArgumentException IllegalArgumentException
javax.xml.transform.dom.DOMResult IllegalArgumentException IllegalArgumentException OK IllegalArgumentException
javax.xml.transform.stax.StAXResult IllegalArgumentException IllegalArgumentException IllegalArgumentException OK

To validate one Source into another kind of Result, use the identity transformer (see javax.xml.transform.TransformerFactory#newTransformer()).

Errors found during the validation is sent to the specified ErrorHandler.

If a document is valid, or if a document contains some errors but none of them were fatal and the ErrorHandler didn't throw any exception, then the method returns normally.

Parameters
source:Source

XML to be validated. Must be an XML document or XML element and must not be null. For backwards compatibility, the results of attempting to validate anything other than a document or element are implementation-dependent. Implementations must either recognize and process the input or throw an IllegalArgumentException.

result:Result

The Result object that receives (possibly augmented) XML. This parameter can be null if the caller is not interested in it. Note that when a DOMResult is used, a validator might just pass the same DOM node from DOMSource to DOMResult (in which case source.getNode()==result.getNode()), it might copy the entire DOM tree, or it might alter the node given by the source.

Exceptions
SAXException:
If the ErrorHandler throws a SAXException or if a fatal error is found and the ErrorHandler returns normally.
IOException:
If the validator is processing a SAXSource and the underlying org.xml.sax.XMLReader throws an IOException.