Search in sources :

Example 1 with Ring

use of com.sun.tools.xjc.reader.Ring in project jaxb-ri by eclipse-ee4j.

the class BGMBuilder method build.

/**
 * Entry point.
 */
public static Model build(XSSchemaSet _schemas, JCodeModel codeModel, ErrorReceiver _errorReceiver, Options opts) {
    // set up a ring
    final Ring old = Ring.begin();
    try {
        ErrorReceiverFilter ef = new ErrorReceiverFilter(_errorReceiver);
        Ring.add(XSSchemaSet.class, _schemas);
        Ring.add(codeModel);
        Model model = new Model(opts, codeModel, null, /*set later*/
        opts.classNameAllocator, _schemas);
        Ring.add(model);
        Ring.add(ErrorReceiver.class, ef);
        Ring.add(CodeModelClassFactory.class, new CodeModelClassFactory(ef));
        BGMBuilder builder = new BGMBuilder(opts.defaultPackage, opts.defaultPackage2, opts.isExtensionMode(), opts.getFieldRendererFactory(), opts.activePlugins);
        builder._build();
        if (ef.hadError())
            return null;
        else
            return model;
    } finally {
        Ring.end(old);
    }
}
Also used : ErrorReceiverFilter(com.sun.tools.xjc.util.ErrorReceiverFilter) CodeModelClassFactory(com.sun.tools.xjc.util.CodeModelClassFactory) Ring(com.sun.tools.xjc.reader.Ring) Model(com.sun.tools.xjc.model.Model) JCodeModel(com.sun.codemodel.JCodeModel)

Example 2 with Ring

use of com.sun.tools.xjc.reader.Ring in project jaxb-ri by eclipse-ee4j.

the class TDTDReader method parse.

/**
 * Parses DTD grammar and a binding information into BGM.
 *
 * <p>
 * This method is just a utility method that covers 80% of the use
 * cases.
 *
 * @param    bindingInfo
 *        binding information file, if any. Can be null.
 */
public static Model parse(InputSource dtd, InputSource bindingInfo, ErrorReceiver errorReceiver, Options opts) {
    try {
        // set up a ring
        final Ring old = Ring.begin();
        try {
            ErrorReceiverFilter ef = new ErrorReceiverFilter(errorReceiver);
            JCodeModel cm = new JCodeModel();
            Model model = new Model(opts, cm, NameConverter.standard, opts.classNameAllocator, null);
            Ring.add(cm);
            Ring.add(model);
            Ring.add(ErrorReceiver.class, ef);
            TDTDReader reader = new TDTDReader(ef, opts, bindingInfo);
            DTDParser parser = new DTDParser();
            parser.setDtdHandler(reader);
            if (opts.entityResolver != null)
                parser.setEntityResolver(opts.entityResolver);
            try {
                parser.parse(dtd);
            } catch (SAXParseException e) {
                // this error was already handled by GrammarReaderController
                return null;
            }
            Ring.get(ModelChecker.class).check();
            if (ef.hadError())
                return null;
            else
                return model;
        } finally {
            Ring.end(old);
        }
    } catch (IOException | SAXException e) {
        errorReceiver.error(new SAXParseException2(e.getMessage(), null, e));
        return null;
    } catch (AbortException e) {
        // parsing was aborted but the error was already reported
        return null;
    }
}
Also used : SAXParseException2(com.sun.istack.SAXParseException2) IOException(java.io.IOException) JCodeModel(com.sun.codemodel.JCodeModel) SAXException(org.xml.sax.SAXException) ModelChecker(com.sun.tools.xjc.reader.ModelChecker) ErrorReceiverFilter(com.sun.tools.xjc.util.ErrorReceiverFilter) Ring(com.sun.tools.xjc.reader.Ring) SAXParseException(org.xml.sax.SAXParseException) Model(com.sun.tools.xjc.model.Model) JCodeModel(com.sun.codemodel.JCodeModel) DTDParser(com.sun.xml.dtdparser.DTDParser) AbortException(com.sun.tools.xjc.AbortException)

Aggregations

JCodeModel (com.sun.codemodel.JCodeModel)2 Model (com.sun.tools.xjc.model.Model)2 Ring (com.sun.tools.xjc.reader.Ring)2 ErrorReceiverFilter (com.sun.tools.xjc.util.ErrorReceiverFilter)2 SAXParseException2 (com.sun.istack.SAXParseException2)1 AbortException (com.sun.tools.xjc.AbortException)1 ModelChecker (com.sun.tools.xjc.reader.ModelChecker)1 CodeModelClassFactory (com.sun.tools.xjc.util.CodeModelClassFactory)1 DTDParser (com.sun.xml.dtdparser.DTDParser)1 IOException (java.io.IOException)1 SAXException (org.xml.sax.SAXException)1 SAXParseException (org.xml.sax.SAXParseException)1