Search in sources :

Example 1 with XMLParser

use of com.sun.xml.xsom.parser.XMLParser in project jaxb-ri by eclipse-ee4j.

the class ModelLoader method createXSOMSpeculative.

/**
 * Parses schemas directly into XSOM by assuming that there's
 * no external annotations.
 * <p>
 * When an external annotation is found, a {@link SpeculationFailure} is thrown,
 * and we will do it all over again by using the slow way.
 */
private XSSchemaSet createXSOMSpeculative() throws SAXException, SpeculationFailure {
    // check if the schema contains external binding files. If so, speculation is a failure.
    XMLParser parser = new XMLParser() {

        private final JAXPParser base = new JAXPParser(XmlFactory.createParserFactory(opt.disableXmlSecurity));

        @Override
        public void parse(InputSource source, ContentHandler handler, ErrorHandler errorHandler, EntityResolver entityResolver) throws SAXException, IOException {
            // set up the chain of handlers.
            handler = wrapBy(new SpeculationChecker(), handler);
            handler = wrapBy(new VersionChecker(null, errorReceiver, entityResolver), handler);
            base.parse(source, handler, errorHandler, entityResolver);
        }

        /**
         * Wraps the specified content handler by a filter.
         * It is little awkward to use a helper implementation class like XMLFilterImpl
         * as the method parameter, but this simplifies the code.
         */
        private ContentHandler wrapBy(XMLFilterImpl filter, ContentHandler handler) {
            filter.setContentHandler(handler);
            return filter;
        }
    };
    XSOMParser reader = createXSOMParser(parser);
    // parse source grammars
    for (InputSource value : opt.getGrammars()) reader.parse(value);
    return reader.getResult();
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) InputSource(org.xml.sax.InputSource) VersionChecker(com.sun.tools.xjc.reader.internalizer.VersionChecker) XSOMParser(com.sun.xml.xsom.parser.XSOMParser) XMLFilterImpl(org.xml.sax.helpers.XMLFilterImpl) JAXPParser(com.sun.xml.xsom.parser.JAXPParser) EntityResolver(org.xml.sax.EntityResolver) XMLParser(com.sun.xml.xsom.parser.XMLParser) ContentHandler(org.xml.sax.ContentHandler)

Aggregations

VersionChecker (com.sun.tools.xjc.reader.internalizer.VersionChecker)1 JAXPParser (com.sun.xml.xsom.parser.JAXPParser)1 XMLParser (com.sun.xml.xsom.parser.XMLParser)1 XSOMParser (com.sun.xml.xsom.parser.XSOMParser)1 ContentHandler (org.xml.sax.ContentHandler)1 EntityResolver (org.xml.sax.EntityResolver)1 ErrorHandler (org.xml.sax.ErrorHandler)1 InputSource (org.xml.sax.InputSource)1 XMLFilterImpl (org.xml.sax.helpers.XMLFilterImpl)1