Search in sources :

Example 11 with MarshalException

use of javax.xml.bind.MarshalException in project tomee by apache.

the class JaxbOpenejb method writeConfig.

public static void writeConfig(final String configFile, final Openejb openejb) throws OpenEJBException {
    OutputStream out = null;
    try {
        final File file = new File(configFile);
        out = IO.write(file);
        marshal(Openejb.class, openejb, out);
    } catch (final IOException e) {
        throw new OpenEJBException(messages().format("conf.1040", configFile, e.getLocalizedMessage()), e);
    } catch (final MarshalException e) {
        if (e.getCause() instanceof IOException) {
            throw new OpenEJBException(messages().format("conf.1040", configFile, e.getLocalizedMessage()), e);
        } else {
            throw new OpenEJBException(messages().format("conf.1050", configFile, e.getLocalizedMessage()), e);
        }
    } catch (final ValidationException e) {
        /* NOTE: This doesn't seem to ever happen. When the object graph
             * is invalid, the MarshalException is thrown, not this one as you
             * would think.
             */
        throw new OpenEJBException(messages().format("conf.1060", configFile, e.getLocalizedMessage()), e);
    } catch (final JAXBException e) {
        throw new OpenEJBException(e);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (final Exception e) {
            // no-op
            }
        }
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) MarshalException(javax.xml.bind.MarshalException) ValidationException(javax.xml.bind.ValidationException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) File(java.io.File) MarshalException(javax.xml.bind.MarshalException) MalformedURLException(java.net.MalformedURLException) OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) ValidationException(javax.xml.bind.ValidationException)

Aggregations

MarshalException (javax.xml.bind.MarshalException)11 IOException (java.io.IOException)6 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 StreamResult (javax.xml.transform.stream.StreamResult)5 SAXException (org.xml.sax.SAXException)5 JAXBAssertionError (com.sun.xml.bind.JAXBAssertionError)4 SAX2DOMEx (com.sun.xml.bind.marshaller.SAX2DOMEx)4 SchemaLocationFilter (com.sun.xml.bind.marshaller.SchemaLocationFilter)4 XMLWriter (com.sun.xml.bind.marshaller.XMLWriter)4 FileOutputStream (java.io.FileOutputStream)4 DocumentBuilder (javax.xml.parsers.DocumentBuilder)4 DOMResult (javax.xml.transform.dom.DOMResult)4 SAXResult (javax.xml.transform.sax.SAXResult)4 Document (org.w3c.dom.Document)4 Node (org.w3c.dom.Node)4 LocatorImpl (org.xml.sax.helpers.LocatorImpl)4 JAXBException (javax.xml.bind.JAXBException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1