Java Code Examples for com.sun.xml.internal.bind.api.ErrorListener

Following code examples demonstrate how to use com.sun.xml.internal.bind.api.ErrorListenerfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use com.sun.xml.internal.bind.api.ErrorListenerand various code implementation of this class.

    public void generateSchema(SchemaOutputResolver outputResolver) throws IOException {
        if(outputResolver==null)
            throw new IOException(Messages.NULL_OUTPUT_RESOLVER.format());

        final SAXParseException[] e = new SAXParseException[1];
        final SAXParseException[] w = new SAXParseException[1];

        createSchemaGenerator().write(outputResolver, new ErrorListener() {
            public void error(SAXParseException exception) {
                e[0] = exception;
            }

            public void fatalError(SAXParseException exception) {
                e[0] = exception;
            }

            public void warning(SAXParseException exception) {
                w[0] = exception;
            }

            public void info(SAXParseException exception) {}
        });

        if (e[0]!=null) {
            IOException x = new IOException(Messages.FAILED_TO_GENERATE_SCHEMA.format());
            x.initCause(e[0]);
            throw x;
        }
        if (w[0]!=null) {
            IOException x = new IOException(Messages.ERROR_PROCESSING_SCHEMA.format());
            x.initCause(w[0]);
            throw x;
        }
    } 


Advertisement
Javadoc
Implemented by the driver of the compiler engine to handle errors found during the compiliation. r>
This class implements ErrorHandler so it can be passed to anywhere where ErrorHandler is expected.

However, to make the error handling easy (and make it work with visitor patterns nicely), this interface is not allowed to abort the processing. It merely receives errors. @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) @since 2.1 EA2

Read More
Advertisement