Example usage for org.xml.sax SAXParseException getClass

List of usage examples for org.xml.sax SAXParseException getClass

Introduction

In this page you can find the example usage for org.xml.sax SAXParseException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.intermine.modelviewer.jaxb.ConfigParser.java

/**
 * This method is a legacy of trying to persuade JAXB to read Intermine
 * files of all types, using all sorts of tricks to get it to work with
 * documents without schema declarations, documents with schema declarations,
 * documents without proper namespace declarations etc.
 * <p>It is no longer used, but remains here for the lessons learned.</p>
 * /* w  w  w. ja  va  2 s. c o  m*/
 * @param context The type of objects expected from the XML file.
 * @param file The file to load.
 * 
 * @return The Object created as a result of reading the file.
 * Its type will depend on <code>context</code>.
 * 
 * @throws JAXBException if there is a problem when unmarshalling.
 * @throws SAXException if there is a problem parsing with SAX.
 * @throws ParserConfigurationException if there is a configuration problem with
 * the SAX system.
 * @throws IOException if there is a low level I/O problem.
 */
protected Object twoPassUnmarshall(Context context, File file)
        throws JAXBException, SAXException, ParserConfigurationException, IOException {
    Unmarshaller unmarshall = jaxbContexts.get(context).createUnmarshaller();
    //unmarshall.setSchema(schemas.get(context));

    try {
        Source source = getSource(file, null);
        return unmarshall.unmarshal(source);
    } catch (UnmarshalException e) {
        if (e.getCause() == null) {
            logger.warn("Failed to unmarshall " + file + ": " + e.getMessage());
        } else {
            try {
                throw e.getCause();
            } catch (SAXParseException e2) {
                logger.warn("Failed to unmarshall " + file + ": " + e2.getMessage());
                logger.debug("", e2);
            } catch (Throwable e2) {
                logger.warn("Unexpected root exception while unmarshalling " + file + ": "
                        + e2.getClass().getName());
                throw e;
            }
        }

        /*
         * This one would try to replace namespaces for JAXB. Unfortunately this
         * too is too strict.
         * 
        String namespace = namespaces.get(context);
                
        // Try filtering the XML by adding the appropriate namespace.
        try {
        Source source = getSource(file, namespace);
        return unmarshall.unmarshal(source);
        } catch (UnmarshalException e2) {
        // Throw the original exception - it's really the one that nags
        // about the namespace.
        throw e;
        }
        */

        return saxParse(context, file);
    }
}