All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.msv.verifier.jarv.SchemaImpl Maven / Gradle / Ivy

There is a newer version: 2.2.5.1
Show newest version
/*
 * @(#)$Id: SchemaImpl.java,v 1.5 2003/09/04 20:30:58 kohsuke Exp $
 *
 * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * This software is the proprietary information of Sun Microsystems, Inc.  
 * Use is subject to license terms.
 * 
 */
package com.sun.msv.verifier.jarv;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;

import org.iso_relax.verifier.Schema;
import org.iso_relax.verifier.Verifier;
import org.iso_relax.verifier.VerifierConfigurationException;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

import com.sun.msv.grammar.Grammar;
import com.sun.msv.verifier.IVerifier;

/**
 * base implementation of RELAXFactoryImpl and TREXFactoryImpl
 * 
 * @author Kohsuke KAWAGUCHI
 */
public class SchemaImpl implements Schema
{
    protected final Grammar grammar;
    protected final SAXParserFactory factory;
    
    protected SchemaImpl( Grammar grammar, SAXParserFactory factory,
        boolean _usePanicMode ) {
        
        this.grammar = grammar;
        this.factory = factory;
        this.usePanicMode = _usePanicMode;
    }
    
    public SchemaImpl( Grammar grammar ) {
        this.grammar = grammar;
        this.factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        this.usePanicMode = false;
    }
    
    public Verifier newVerifier() throws VerifierConfigurationException {
        IVerifier core = FactoryImpl.createVerifier(grammar);
        core.setPanicMode(usePanicMode);
        return new VerifierImpl( core, createXMLReader() );
    }
    
    private synchronized XMLReader createXMLReader() throws VerifierConfigurationException {
        // SAXParserFactory is not thread-safe. Thus we need to
        // synchronize this method.
        try {
            return factory.newSAXParser().getXMLReader();
        } catch( SAXException e ) {
            throw new VerifierConfigurationException(e);
        } catch( ParserConfigurationException e ) {
            throw new VerifierConfigurationException(e);
        }
    }
    
    private boolean usePanicMode;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy