FileDocCategorySizeDatePackage
ValidatorImpl.javaAPI DocJava SE 6 API10127Tue Jun 10 00:22:48 BST 2008com.sun.org.apache.xerces.internal.jaxp.validation

ValidatorImpl

public final class ValidatorImpl extends Validator implements PSVIProvider

Implementation of Validator for W3C XML Schemas.

author
Kohsuke Kawaguchi
author
Michael Glavassevich, IBM
author
Sunitha Reddy
version
$Id: ValidatorImpl.java,v 1.3 2005/09/26 13:02:52 sunithareddy Exp $

Fields Summary
private XMLSchemaValidatorComponentManager
fComponentManager
Component manager.
private ValidatorHandlerImpl
fSAXValidatorHelper
SAX validator helper.
private DOMValidatorHelper
fDOMValidatorHelper
DOM validator helper.
private StreamValidatorHelper
fStreamValidatorHelper
Stream validator helper.
private StAXValidatorHelper
fStaxValidatorHelper
StAX 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 com.sun.org.apache.xerces.internal.xs.AttributePSVIgetAttributePSVI(int index)

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

        return (fSAXValidatorHelper != null) ? fSAXValidatorHelper.getAttributePSVIByName(uri, localname) : null;
    
public com.sun.org.apache.xerces.internal.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();
        }
        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();
        }
        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);
        }
        else if (source instanceof StAXSource) {
            // Hand off to stax validator helper.
            if (fStaxValidatorHelper == null) {
                fStaxValidatorHelper = new StAXValidatorHelper(fComponentManager);
            }
            fStaxValidatorHelper.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()}));
        }