}
/** Translate a JAXB unmarshal exception into something legible. */
private static <T> InvalidDataException translateJaxbUnmarshalError(Class<T> type, JAXBException e) {
boolean added = false;
InvalidDataException invalid = getUnmarshalError(type, e);
// This was developed through trial-and-error. I don't know how well it will hold up in the future.
if (e.getCause() != null && e.getLinkedException() != null) {
try {
throw e.getLinkedException();
} catch (org.xml.sax.SAXParseException sax) {
String message = "Line " + sax.getLineNumber() + ", column " + sax.getColumnNumber() + ": " + e.getCause().getMessage();
invalid.getDetails().addMessage(ERROR_KEY, message);
added = true;
} catch (Throwable other) { }
}
if (!added && e.getCause() != null && e.getCause().getMessage() != null) {
invalid.getDetails().addMessage(ERROR_KEY, e.getCause().getMessage());
added = true;
}
if (!added && e.getMessage() != null) {
invalid.getDetails().addMessage(ERROR_KEY, e.getMessage());
added = true;
}
return invalid;
}