Search in sources :

Example 1 with Requests

use of org.openhab.binding.stiebelheatpump.protocol.Requests 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 Requests

use of org.openhab.binding.stiebelheatpump.protocol.Requests in project openhab1-addons by openhab.

the class ConfigParser method parseConfig.

/**
     * This method loads a List of Request objects from xml file
     *
     * @param fileName
     *            file object to load the object from
     * @return List of Requests
     */
public List<Request> parseConfig(String fileName) {
    logger.debug("Parsing  heat pump configuration file {}.", fileName);
    try {
        JAXBContext context = JAXBContext.newInstance(Requests.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
        Requests configuration = (Requests) unmarshaller.unmarshal(stream);
        List<Request> requests = configuration.getRequests();
        return requests;
    } catch (JAXBException e) {
        logger.debug("Parsing  failed {}. " + e.toString(), fileName);
        throw new RuntimeException(e);
    }
}
Also used : InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) Request(org.openhab.binding.stiebelheatpump.protocol.Request) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Requests(org.openhab.binding.stiebelheatpump.protocol.Requests)

Example 3 with Requests

use of org.openhab.binding.stiebelheatpump.protocol.Requests in project openhab1-addons by openhab.

the class ConfigParser method unmarshal.

/**
     * This method loads a List of Request objects from xml file
     *
     * @param importFile
     *            file object to load the object from
     * @return List of Requests
     */
public List<Request> unmarshal(File importFile) throws StiebelHeatPumpException {
    Requests requests = new Requests();
    JAXBContext context;
    try {
        context = JAXBContext.newInstance(Requests.class);
        Unmarshaller um = context.createUnmarshaller();
        requests = (Requests) um.unmarshal(importFile);
    } catch (JAXBException e) {
        throw new StiebelHeatPumpException(e.toString(), e);
    }
    return requests.getRequests();
}
Also used : JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Requests(org.openhab.binding.stiebelheatpump.protocol.Requests)

Aggregations

JAXBContext (javax.xml.bind.JAXBContext)3 JAXBException (javax.xml.bind.JAXBException)3 Requests (org.openhab.binding.stiebelheatpump.protocol.Requests)3 Unmarshaller (javax.xml.bind.Unmarshaller)2 BufferedWriter (java.io.BufferedWriter)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Marshaller (javax.xml.bind.Marshaller)1 PropertyException (javax.xml.bind.PropertyException)1 Request (org.openhab.binding.stiebelheatpump.protocol.Request)1