/** * Load anual hours xml file from disk and parse * * @return AnualHours java bean * @throws CRUDException */ public static AnualHours loadAnualHoursFromXML() throws CRUDException { StringBuffer strBuffer = new StringBuffer(); FileReader fr = null; try { // Read from file File archivo = ConfigurationUtils.getInputHoursFile(); fr = new FileReader(archivo); BufferedReader br = new BufferedReader(fr); String str; while ((str = br.readLine()) != null) strBuffer.append(str); // Parse the XML final JAXBContext jaxbContext = JAXBContext.newInstance(AnualHours.class); final AnualHours aHours = (AnualHours) jaxbContext.createUnmarshaller().unmarshal(new StringReader(strBuffer.toString())); return aHours; } catch (Exception e) { throw new CRUDException(e); } finally { if (fr != null) try { fr.close(); } catch (IOException e) { throw new CRUDException(e); } } }
/** * Persist the anual hours * * @param aHours anual hours java bean * @throws CRUDException */ public static void saveAnualHours(AnualHours aHours) throws CRUDException { FileWriter fichero = null; try { // write it out as XML final JAXBContext jaxbContext = JAXBContext.newInstance(AnualHours.class); StringWriter writer = new StringWriter(); jaxbContext.createMarshaller().marshal(aHours, writer); // Write to a file fichero = new FileWriter(ConfigurationUtils.getInputHoursFile()); PrintWriter pw = new PrintWriter(fichero); pw.println(writer); } catch (Exception e) { throw new CRUDException(e); } finally { if (fichero != null) try { fichero.close(); } catch (IOException e) { throw new CRUDException(e); } } }