List of usage examples for javax.xml.bind UnmarshalException getCause
@Override
public Throwable getCause()
From source file:com.sap.prd.mobile.ios.mios.xcodeprojreader.jaxb.JAXBPlistParserTest.java
@Test public void convertOpenStepToXML() throws Exception { JAXBPlistParser parser = new JAXBPlistParser(); try {/*from w ww . j a va2s . c om*/ parser.load(fileNameOpenStep); Assert.fail(); } catch (javax.xml.bind.UnmarshalException e) { if (!(e.getCause().getClass() == SAXParseException.class)) { Assert.fail(); } } File xmlProj = File.createTempFile("project", ".pbxproj"); xmlProj.deleteOnExit(); try { parser.convert(fileNameOpenStep, xmlProj.getAbsolutePath()); Plist plist = parser.load(xmlProj.getAbsolutePath()); assertEquals("1.0", plist.getVersion()); } catch (UnsupportedOperationException ex) { // If we are running on a non Mac OS X system an UnsupportedOperationException is expected assertFalse("The convert function should only fail on non Mac OS X systems", SystemUtils.IS_OS_MAC_OSX); assertTrue("Wrong UnsupportedOperationException message", ex.getMessage().contains("Mac OS X")); } }
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> * /*from w w w .ja v a 2s . 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); } }