List of usage examples for javax.xml.bind JAXBException getLinkedException
public Throwable getLinkedException()
From source file:Main.java
public static JAXBException convert(final JAXBException e) { return new JAXBException(getMessage(e), e.getLinkedException()); }
From source file:Main.java
public static String getMessage(final JAXBException e) { String ret = e.getMessage();// ww w. j av a2 s .c o m if (ret == null && e.getLinkedException() != null) { ret = e.getLinkedException().getMessage(); } return ret; }
From source file:com.bitplan.jaxb.JaxbFactory.java
/** * unmarshal the given string s using the unmarshaller u * //from w ww. j ava 2 s .c o m * @param u * @param s * @return - the Object of Type T * @throws Exception */ @SuppressWarnings("unchecked") public T fromString(Unmarshaller u, String s) throws Exception { // unmarshal the string to a Java object of type <T> (classOfT has the // runtime type) StringReader stringReader = new StringReader(s.trim()); T result = null; // this step will convert from xml text to Java Object try { Object unmarshalResult = u.unmarshal(stringReader); if (classOfT.isInstance(unmarshalResult)) { result = (T) unmarshalResult; } else { String type = "null"; if (unmarshalResult != null) { type = unmarshalResult.getClass().getName(); } String msg = "unmarshalling returned " + type + " but " + classOfT.getName() + " was expected"; throw new Exception(msg); } } catch (JAXBException jex) { Throwable ex = jex; if (jex.getLinkedException() != null) { ex = jex.getLinkedException(); } String msg = "JAXBException: " + ex.getMessage(); LOGGER.log(Level.SEVERE, msg); LOGGER.log(Level.SEVERE, s); throw (new Exception(msg, ex)); } return result; }
From source file:hydrograph.ui.propertywindow.widgets.customwidgets.schema.GridRowLoader.java
/** * The method exports schema rows from schema grid into schema file. * //from w ww . j a va 2 s . c o m */ public void exportXMLfromGridRowsWithoutMessage(List<GridRow> schemaGridRowList) { Schema schema = new Schema(); fields = new Fields(); try { if (StringUtils.isNotBlank(schemaFile.getPath())) { exportFile(schemaGridRowList, schema); } else { logger.error(Messages.EXPORT_XML_EMPTY_FILENAME); throw new Exception(Messages.EXPORT_XML_EMPTY_FILENAME); } } catch (JAXBException e) { showMessageBox( Messages.EXPORT_XML_ERROR + " -\n" + ((e.getCause() != null) ? e.getLinkedException().getMessage() : e.getMessage()), "Error", SWT.ERROR); logger.error(Messages.EXPORT_XML_ERROR); } catch (Exception e) { showMessageBox(Messages.EXPORT_XML_ERROR + " -\n" + e.getMessage(), "Error", SWT.ERROR); logger.error(Messages.EXPORT_XML_ERROR); } }
From source file:hydrograph.ui.propertywindow.widgets.customwidgets.schema.GridRowLoader.java
/** * The method exports schema rows from schema grid into schema file. * /*from w w w .j a v a 2 s .c o m*/ */ public void exportXMLfromGridRows(List<GridRow> schemaGridRowList) { Schema schema = new Schema(); fields = new Fields(); try { if (StringUtils.isNotBlank(schemaFile.getPath())) { if (!schemaFile.getName().contains(".")) { logger.error(Messages.EXPORT_XML_IMPROPER_EXTENSION); throw new Exception(Messages.EXPORT_XML_IMPROPER_EXTENSION); } if (!(schemaFile.getPath().endsWith(".schema")) && !(schemaFile.getPath().endsWith(".xml"))) { logger.error(Messages.EXPORT_XML_INCORRECT_FILE); throw new Exception(Messages.EXPORT_XML_INCORRECT_FILE); } exportFile(schemaGridRowList, schema); showMessageBox(Messages.EXPORTED_SCHEMA, "Information", SWT.ICON_INFORMATION); } else { logger.error(Messages.EXPORT_XML_EMPTY_FILENAME); throw new Exception(Messages.EXPORT_XML_EMPTY_FILENAME); } } catch (JAXBException e) { showMessageBox( Messages.EXPORT_XML_ERROR + " -\n" + ((e.getCause() != null) ? e.getLinkedException().getMessage() : e.getMessage()), "Error", SWT.ERROR); logger.error(Messages.EXPORT_XML_ERROR); } catch (Exception e) { showMessageBox(Messages.EXPORT_XML_ERROR + " -\n" + e.getMessage(), "Error", SWT.ERROR); logger.error(Messages.EXPORT_XML_ERROR); } }
From source file:org.bibsonomy.rest.renderer.impl.JAXBRenderer.java
/** * Unmarshalls the document from the reader to the generated java * model./*from w ww . j a v a2 s. c om*/ * * @return A BibsonomyXML object that contains the unmarshalled content * @throws InternServerException * if the content can't be unmarshalled */ private BibsonomyXML parse(final Reader reader) throws InternServerException { // first: check the reader this.checkReader(reader); try { // initialize JAXB context. We provide the classloader here because we experienced that under // certain circumstances (e.g. when used within JabRef as a JPF-Plugin), the wrong classloader is // used which has the following exception as consequence: // // javax.xml.bind.JAXBException: "org.bibsonomy.rest.renderer.xml" doesnt contain ObjectFactory.class or jaxb.index // // (see also http://ws.apache.org/jaxme/apidocs/javax/xml/bind/JAXBContext.html) final JAXBContext jc = this.getJAXBContext(); // create an Unmarshaller final Unmarshaller u = jc.createUnmarshaller(); // set schema to validate input documents if (this.validateXMLInput) { u.setSchema(schema); } /* * unmarshal a xml instance document into a tree of Java content * objects composed of classes from the restapi package. */ final JAXBElement<BibsonomyXML> xmlDoc = unmarshal(u, reader); return xmlDoc.getValue(); } catch (final JAXBException e) { if (e.getLinkedException() != null && e.getLinkedException().getClass() == SAXParseException.class) { final SAXParseException ex = (SAXParseException) e.getLinkedException(); throw new BadRequestOrResponseException("Error while parsing XML (Line " + ex.getLineNumber() + ", Column " + ex.getColumnNumber() + ": " + ex.getMessage()); } throw new InternServerException(e.toString()); } }
From source file:org.bibsonomy.rest.renderer.impl.JAXBRenderer.java
/** * Initializes java xml bindings, builds the document and then marshalls * it to the writer.//from w w w . j av a 2 s .c o m * * @throws InternServerException * if the document can't be marshalled */ private void serialize(final Writer writer, final BibsonomyXML xmlDoc) throws InternServerException { try { // initialize context for java xml bindings final JAXBContext jc = this.getJAXBContext(); // buildup document model final JAXBElement<BibsonomyXML> webserviceElement = new ObjectFactory().createBibsonomy(xmlDoc); // create a marshaller final Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); if (this.validateXMLOutput) { // validate the XML produced by the marshaller marshaller.setSchema(schema); } // marshal to the writer this.marshal(marshaller, webserviceElement, writer); // TODO log // log.debug(""); } catch (final JAXBException e) { final Throwable linkedException = e.getLinkedException(); if (present(linkedException) && linkedException.getClass() == SAXParseException.class) { final SAXParseException ex = (SAXParseException) linkedException; throw new BadRequestOrResponseException("Error while parsing XML (Line " + ex.getLineNumber() + ", Column " + ex.getColumnNumber() + ": " + ex.getMessage()); } throw new InternServerException(e.toString()); } }
From source file:org.opencastproject.composer.api.EncodingProfileBuilder.java
/** * Returns an instance of the {@link EncodingProfileBuilder}. * //from w w w. ja v a 2s .c o m * @return a factory */ public static EncodingProfileBuilder getInstance() { if (instance == null) { try { instance = new EncodingProfileBuilder(); } catch (JAXBException e) { throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e); } } return instance; }
From source file:org.opencastproject.episode.api.JaxbSearchResult.java
/** * Reads the search result from the input stream. * /*from w w w . j a v a 2 s . c o m*/ * @param xml * the input stream * @return the deserialized search result */ public static JaxbSearchResult valueOf(InputStream xml) { try { Unmarshaller unmarshaller = context.createUnmarshaller(); Source source = new StreamSource(xml); return unmarshaller.unmarshal(source, JaxbSearchResult.class).getValue(); } catch (JAXBException e) { throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e); } finally { IOUtils.closeQuietly(xml); } }
From source file:org.opencastproject.episode.api.SearchResultImpl.java
/** * Reads the search result from the input stream. * /* w w w . java 2 s . co m*/ * @param xml * the input stream * @return the deserialized search result */ public static SearchResultImpl valueOf(InputStream xml) { try { Unmarshaller unmarshaller = context.createUnmarshaller(); Source source = new StreamSource(xml); return unmarshaller.unmarshal(source, SearchResultImpl.class).getValue(); } catch (JAXBException e) { throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e); } finally { IOUtils.closeQuietly(xml); } }