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

StAXValidatorHelper

public final class StAXValidatorHelper extends Object implements ValidatorHelper

A validator helper for StAXSources.

author
Sunitha Reddy

Fields Summary
private XMLSchemaValidatorComponentManager
fComponentManager
Component manager.
private Transformer
identityTransformer1
private TransformerHandler
identityTransformer2
private ValidatorHandlerImpl
handler
Constructors Summary
public StAXValidatorHelper(XMLSchemaValidatorComponentManager componentManager)
Creates a new instance of StaxValidatorHelper

    
           
       
        fComponentManager = componentManager;
    
Methods Summary
public voidvalidate(javax.xml.transform.Source source, javax.xml.transform.Result result)

        
        if (result == null || result instanceof StAXResult) {
         
            if( identityTransformer1==null ) {
                try {
                    SAXTransformerFactory tf = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
                    identityTransformer1 = tf.newTransformer();
                    identityTransformer2 = tf.newTransformerHandler();
                } catch (TransformerConfigurationException e) {
                    // this is impossible, but again better safe than sorry
                    throw new TransformerFactoryConfigurationError(e);
                }
            }

            if( result!=null ) {
                handler = new ValidatorHandlerImpl(fComponentManager);
                handler.setContentHandler(identityTransformer2);
                identityTransformer2.setResult(result);
            }

            try {
                identityTransformer1.transform( source, new SAXResult(handler) );
            } catch (TransformerException e) {
                if( e.getException() instanceof SAXException )
                    throw (SAXException)e.getException();
                throw new SAXException(e);
            } finally {
                handler.setContentHandler(null);
            }
            return;
        }
        throw new IllegalArgumentException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(), 
                "SourceResultMismatch", 
                new Object [] {source.getClass().getName(), result.getClass().getName()}));