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());
}
}
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);
}
}
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();
}
Aggregations