Search in sources :

Example 1 with Config

use of com.sun.tools.jxc.gen.config.Config in project jaxb-ri by eclipse-ee4j.

the class ConfigReader method parseAndGetConfig.

/**
 * Parses an xml config file and returns a Config object.
 *
 * @param xmlFile
 *        The xml config file which is passed by the user to annotation processing
 * @return
 *        A non null Config object
 */
private Config parseAndGetConfig(File xmlFile, ErrorHandler errorHandler, boolean disableSecureProcessing) throws SAXException, IOException {
    XMLReader reader;
    try {
        SAXParserFactory factory = XmlFactory.createParserFactory(disableSecureProcessing);
        reader = factory.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException e) {
        // in practice this will never happen
        throw new Error(e);
    }
    NGCCRuntimeEx runtime = new NGCCRuntimeEx(errorHandler);
    // set up validator
    ValidatorHandler validator = configSchema.newValidator();
    validator.setErrorHandler(errorHandler);
    // the validator will receive events first, then the parser.
    reader.setContentHandler(new ForkContentHandler(validator, runtime));
    reader.setErrorHandler(errorHandler);
    Config config = new Config(runtime);
    runtime.setRootHandler(config);
    reader.parse(new InputSource(xmlFile.toURI().toURL().toExternalForm()));
    runtime.reset();
    return config;
}
Also used : InputSource(org.xml.sax.InputSource) ValidatorHandler(javax.xml.validation.ValidatorHandler) Config(com.sun.tools.jxc.gen.config.Config) ForkContentHandler(com.sun.tools.xjc.util.ForkContentHandler) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

Config (com.sun.tools.jxc.gen.config.Config)1 ForkContentHandler (com.sun.tools.xjc.util.ForkContentHandler)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 ValidatorHandler (javax.xml.validation.ValidatorHandler)1 InputSource (org.xml.sax.InputSource)1 XMLReader (org.xml.sax.XMLReader)1