Search in sources :

Example 1 with PropertyException

use of javax.xml.bind.PropertyException in project openhab1-addons by openhab.

the class ConfigParser method marshal.

/**
     * This method saves List of Request objects into xml file
     *
     * @param requests
     *            object to be saved
     * @param xmlFileLocation
     *            file object to save the object into
     */
@SuppressWarnings("resource")
public void marshal(List<Request> requests, File xmlFileLocation) throws StiebelHeatPumpException {
    JAXBContext context;
    BufferedWriter writer = null;
    try {
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(xmlFileLocation), "UTF-8"));
    } catch (IOException e) {
        throw new StiebelHeatPumpException(e.toString());
    }
    try {
        context = JAXBContext.newInstance(Requests.class);
    } catch (JAXBException e) {
        throw new StiebelHeatPumpException(e.toString());
    }
    Marshaller m;
    try {
        m = context.createMarshaller();
    } catch (JAXBException e) {
        throw new StiebelHeatPumpException(e.toString());
    }
    try {
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    } catch (PropertyException e) {
        throw new StiebelHeatPumpException(e.toString());
    }
    try {
        m.marshal(new Requests(requests), writer);
    } catch (JAXBException e) {
        throw new StiebelHeatPumpException(e.toString());
    }
    try {
        writer.close();
    } catch (IOException e) {
        throw new StiebelHeatPumpException(e.toString());
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) PropertyException(javax.xml.bind.PropertyException) FileOutputStream(java.io.FileOutputStream) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) Requests(org.openhab.binding.stiebelheatpump.protocol.Requests) BufferedWriter(java.io.BufferedWriter)

Example 2 with PropertyException

use of javax.xml.bind.PropertyException in project openhab1-addons by openhab.

the class LgTvChannelSet method savetofile.

/**
     * Save Channel List to File f
     * 
     * @param f
     */
public void savetofile(String f) {
    Writer writer = null;
    JAXBContext jc;
    try {
        jc = JAXBContext.newInstance(envelope.class);
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "utf-8"));
        marshaller.marshal(envel, writer);
    } catch (PropertyException e) {
        logger.error("error in savetofile", e);
    } catch (JAXBException e) {
        logger.error("error in savetofile", e);
    } catch (IOException ex) {
        logger.error("error in savetofile", ex);
    } finally {
        try {
            writer.close();
        } catch (Exception ex) {
        }
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) PropertyException(javax.xml.bind.PropertyException) FileOutputStream(java.io.FileOutputStream) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) PropertyException(javax.xml.bind.PropertyException) JAXBException(javax.xml.bind.JAXBException) BufferedWriter(java.io.BufferedWriter)

Example 3 with PropertyException

use of javax.xml.bind.PropertyException in project openhab1-addons by openhab.

the class LgTvAppSet method savetofile.

/**
     * 
     * Save Application List to File f
     * 
     * @param f
     */
public void savetofile(String f) {
    Writer writer = null;
    JAXBContext jc;
    try {
        jc = JAXBContext.newInstance(envelope.class);
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "utf-8"));
        marshaller.marshal(envel, writer);
    } catch (PropertyException e) {
        logger.error("error in xml processing - save file", e);
    } catch (JAXBException e) {
        logger.error("error in xml processing - save file", e);
    } catch (IOException ex) {
        logger.error("error in xml processing - save file", ex);
    } finally {
        try {
            writer.close();
        } catch (Exception ex) {
        }
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) PropertyException(javax.xml.bind.PropertyException) FileOutputStream(java.io.FileOutputStream) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) PropertyException(javax.xml.bind.PropertyException) JAXBException(javax.xml.bind.JAXBException) BufferedWriter(java.io.BufferedWriter)

Example 4 with PropertyException

use of javax.xml.bind.PropertyException in project OpenAM by OpenRock.

the class Utils method convertJAXBToElement.

/**
     * Converts a JAXB object to a <code>org.w3c.dom.Element</code>.
     *
     * @param jaxbObj a JAXB object
     * @return a <code>org.w3c.dom.Element</code>
     * @throws JAXBException if an error occurs while converting JAXB object.
     * @supported.api
     */
public static Element convertJAXBToElement(Object jaxbObj, boolean checkIdref) throws JAXBException {
    Marshaller m = jc.createMarshaller();
    try {
        m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl());
    } catch (PropertyException ex) {
        debug.error("Utils.convertJAXBToElement", ex);
    }
    if (!checkIdref) {
        m.setEventHandler(new DefaultValidationEventHandler() {

            public boolean handleEvent(ValidationEvent event) {
                if (event instanceof NotIdentifiableEvent) {
                    return true;
                }
                return super.handleEvent(event);
            }
        });
    }
    Document doc = null;
    try {
        doc = XMLUtils.newDocument();
    } catch (Exception ex) {
        debug.error("Utils.convertJAXBToElement:", ex);
    }
    m.marshal(jaxbObj, doc);
    return doc.getDocumentElement();
}
Also used : Marshaller(javax.xml.bind.Marshaller) PropertyException(javax.xml.bind.PropertyException) ValidationEvent(javax.xml.bind.ValidationEvent) DefaultValidationEventHandler(javax.xml.bind.helpers.DefaultValidationEventHandler) Document(org.w3c.dom.Document) NotIdentifiableEvent(javax.xml.bind.NotIdentifiableEvent) PropertyException(javax.xml.bind.PropertyException) JAXBException(javax.xml.bind.JAXBException)

Example 5 with PropertyException

use of javax.xml.bind.PropertyException in project OpenAM by OpenRock.

the class Utils method convertJAXBToElement.

/**
     * Converts a JAXB object to a <code>org.w3c.dom.Element</code>.
     *
     * @param jaxbObj a JAXB object
     * @return a <code>org.w3c.dom.Element</code>
     * @throws JAXBException if an error occurs while converting JAXB object.
     * @supported.api
     */
public static Element convertJAXBToElement(Object jaxbObj) throws JAXBException {
    Marshaller m = jc.createMarshaller();
    try {
        m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl());
    } catch (PropertyException ex) {
        debug.error("Utils.convertJAXBToElement", ex);
    }
    Document doc = null;
    try {
        doc = XMLUtils.newDocument();
    } catch (Exception ex) {
        debug.error("Utils.convertJAXBToElement:", ex);
    }
    m.marshal(jaxbObj, doc);
    return doc.getDocumentElement();
}
Also used : Marshaller(javax.xml.bind.Marshaller) PropertyException(javax.xml.bind.PropertyException) Document(org.w3c.dom.Document) PropertyException(javax.xml.bind.PropertyException) JAXBException(javax.xml.bind.JAXBException)

Aggregations

JAXBException (javax.xml.bind.JAXBException)5 Marshaller (javax.xml.bind.Marshaller)5 PropertyException (javax.xml.bind.PropertyException)5 BufferedWriter (java.io.BufferedWriter)3 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 OutputStreamWriter (java.io.OutputStreamWriter)3 JAXBContext (javax.xml.bind.JAXBContext)3 Writer (java.io.Writer)2 Document (org.w3c.dom.Document)2 NotIdentifiableEvent (javax.xml.bind.NotIdentifiableEvent)1 ValidationEvent (javax.xml.bind.ValidationEvent)1 DefaultValidationEventHandler (javax.xml.bind.helpers.DefaultValidationEventHandler)1 Requests (org.openhab.binding.stiebelheatpump.protocol.Requests)1