FileDocCategorySizeDatePackage
ValidatorImpl.javaAPI DocApache Xerces 3.0.110610Fri Sep 14 20:33:54 BST 2007org.apache.xerces.jaxp.validation

ValidatorImpl

public final class ValidatorImpl extends Validator implements org.apache.xerces.xs.PSVIProvider

Implementation of Validator for W3C XML Schemas.

author
Kohsuke Kawaguchi
author
Michael Glavassevich, IBM
version
$Id: ValidatorImpl.java 447235 2006-09-18 05:01:44Z mrglavas $

Fields Summary
private static final String
CURRENT_ELEMENT_NODE
Property identifier: Current element node.
private XMLSchemaValidatorComponentManager
fComponentManager
Component manager.
private ValidatorHandlerImpl
fSAXValidatorHelper
SAX validator helper.
private DOMValidatorHelper
fDOMValidatorHelper
DOM validator helper.
private StreamValidatorHelper
fStreamValidatorHelper
Stream validator helper.
private boolean
fConfigurationChanged
Flag for tracking whether features/properties changed since last reset.
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.
Constructors Summary
public ValidatorImpl(XSGrammarPoolContainer grammarContainer)

    
       
        fComponentManager = new XMLSchemaValidatorComponentManager(grammarContainer);
        setErrorHandler(null);
        setResourceResolver(null);
    
Methods Summary
public org.apache.xerces.xs.AttributePSVIgetAttributePSVI(int index)

        return (fSAXValidatorHelper != null) ? fSAXValidatorHelper.getAttributePSVI(index) : null;
    
public org.apache.xerces.xs.AttributePSVIgetAttributePSVIByName(java.lang.String uri, java.lang.String localname)

        return (fSAXValidatorHelper != null) ? fSAXValidatorHelper.getAttributePSVIByName(uri, localname) : null;
    
public org.apache.xerces.xs.ElementPSVIgetElementPSVI()

        return (fSAXValidatorHelper != null) ? fSAXValidatorHelper.getElementPSVI() : null;
    
public org.xml.sax.ErrorHandlergetErrorHandler()

        return fComponentManager.getErrorHandler();
    
public booleangetFeature(java.lang.String name)

        if (name == null) {
            throw new NullPointerException();
        }
        try {
            return fComponentManager.getFeature(name);
        }
        catch (XMLConfigurationException e) {
            final String identifier = e.getIdentifier();
            final String key = e.getType() == XMLConfigurationException.NOT_RECOGNIZED ?
                    "feature-not-recognized" : "feature-not-supported";
            throw new SAXNotRecognizedException(
                    SAXMessageFormatter.formatMessage(Locale.getDefault(), 
                    key, new Object [] {identifier}));
        }
    
public java.lang.ObjectgetProperty(java.lang.String name)

        if (name == null) {
            throw new NullPointerException();
        }
        if (CURRENT_ELEMENT_NODE.equals(name)) {
            return (fDOMValidatorHelper != null) ? 
                    fDOMValidatorHelper.getCurrentElement() : null;
        }
        try {
            return fComponentManager.getProperty(name);
        }
        catch (XMLConfigurationException e) {
            final String identifier = e.getIdentifier();
            final String key = e.getType() == XMLConfigurationException.NOT_RECOGNIZED ?
                    "property-not-recognized" : "property-not-supported";
            throw new SAXNotRecognizedException(
                    SAXMessageFormatter.formatMessage(Locale.getDefault(), 
                    key, new Object [] {identifier}));
        }
    
public org.w3c.dom.ls.LSResourceResolvergetResourceResolver()

        return fComponentManager.getResourceResolver();
    
public voidreset()

        // avoid resetting features and properties if the state the validator
        // is currently in, is the same as it will be after reset.
        if (fConfigurationChanged) {
            fComponentManager.restoreInitialState();
            setErrorHandler(null);
            setResourceResolver(null);
            fConfigurationChanged = false;
            fErrorHandlerChanged = false;
            fResourceResolverChanged = false;
        }
        else {
            if (fErrorHandlerChanged) {
                setErrorHandler(null);
                fErrorHandlerChanged = false;
            }
            if (fResourceResolverChanged) {
                setResourceResolver(null);
                fResourceResolverChanged = false;
            }
        }
    
public voidsetErrorHandler(org.xml.sax.ErrorHandler errorHandler)

        fErrorHandlerChanged = (errorHandler != null);
        fComponentManager.setErrorHandler(errorHandler);
    
public voidsetFeature(java.lang.String name, boolean value)

        if (name == null) {
            throw new NullPointerException();
        }
        try {
            fComponentManager.setFeature(name, value);
        }
        catch (XMLConfigurationException e) {
            final String identifier = e.getIdentifier();
            final String key = e.getType() == XMLConfigurationException.NOT_RECOGNIZED ?
                    "feature-not-recognized" : "feature-not-supported";
            throw new SAXNotRecognizedException(
                    SAXMessageFormatter.formatMessage(Locale.getDefault(), 
                    key, new Object [] {identifier}));
        }
        fConfigurationChanged = true;
    
public voidsetProperty(java.lang.String name, java.lang.Object object)

        if (name == null) {
            throw new NullPointerException();
        }
        if (CURRENT_ELEMENT_NODE.equals(name)) {
            throw new SAXNotSupportedException(
                    SAXMessageFormatter.formatMessage(Locale.getDefault(), 
                    "property-read-only", new Object [] {name}));
        }
        try {
            fComponentManager.setProperty(name, object);
        }
        catch (XMLConfigurationException e) {
            final String identifier = e.getIdentifier();
            final String key = e.getType() == XMLConfigurationException.NOT_RECOGNIZED ?
                    "property-not-recognized" : "property-not-supported";
            throw new SAXNotRecognizedException(
                    SAXMessageFormatter.formatMessage(Locale.getDefault(), 
                    key, new Object [] {identifier}));
        }
        fConfigurationChanged = true;
    
public voidsetResourceResolver(org.w3c.dom.ls.LSResourceResolver resourceResolver)

        fResourceResolverChanged = (resourceResolver != null);
        fComponentManager.setResourceResolver(resourceResolver);
    
public voidvalidate(javax.xml.transform.Source source, javax.xml.transform.Result result)

        if (source instanceof SAXSource) {
            // Hand off to SAX validator helper.
            if (fSAXValidatorHelper == null) {
                fSAXValidatorHelper = new ValidatorHandlerImpl(fComponentManager);
            }
            fSAXValidatorHelper.validate(source, result);
        }
        else if (source instanceof DOMSource) {
            // Hand off to DOM validator helper.
            if (fDOMValidatorHelper == null) {
                fDOMValidatorHelper = new DOMValidatorHelper(fComponentManager);
            }
            fDOMValidatorHelper.validate(source, result);
        }
        else if (source instanceof StreamSource) {
            // Hand off to stream validator helper.
            if (fStreamValidatorHelper == null) {
                fStreamValidatorHelper = new StreamValidatorHelper(fComponentManager);
            }
            fStreamValidatorHelper.validate(source, result);
        }
        // Source parameter cannot be null.
        else if (source == null) {
            throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(), 
                    "SourceParameterNull", null));
        }
        // Source parameter must be a SAXSource, DOMSource or StreamSource
        else {
            throw new IllegalArgumentException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(), 
                    "SourceNotAccepted", new Object [] {source.getClass().getName()}));
        }