From: rodinia814 Date: Wed, 25 Apr 2012 20:59:35 +0000 (+0000) Subject: Cleanup X-Git-Tag: upstream/12.09^2~322 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=20a322d0bf5d52ac19b76652b1b895b2dc91ae8b;p=debian%2Fopenrocket Cleanup git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@613 180e2498-e6e9-4542-8430-84ac67f01cd8 --- diff --git a/core/src/net/sf/openrocket/preset/xml/OpenRocketComponentSaver.java b/core/src/net/sf/openrocket/preset/xml/OpenRocketComponentSaver.java index 33b1a416..5563bac8 100644 --- a/core/src/net/sf/openrocket/preset/xml/OpenRocketComponentSaver.java +++ b/core/src/net/sf/openrocket/preset/xml/OpenRocketComponentSaver.java @@ -54,33 +54,32 @@ public class OpenRocketComponentSaver { return null; } + /** + * This method unmarshals from a Reader that is presumed to be open on an XML file in .orc format. + * + * @param is an open reader; StringBufferInputStream could not be used because it's deprecated and does not handle + * UTF characters correctly + * + * @return a list of ComponentPresets + * + * @throws InvalidComponentPresetException + * + */ public List unmarshalFromOpenRocketComponent(Reader is) throws InvalidComponentPresetException { return fromOpenRocketComponent(is).asComponentPresets(); } - private OpenRocketComponentDTO fromOpenRocketComponent(Reader is) { - try { - JAXBContext bind = JAXBContext.newInstance(OpenRocketComponentDTO.class); - Unmarshaller unmarshaller = bind.createUnmarshaller(); - return (OpenRocketComponentDTO)unmarshaller.unmarshal(is); - } - catch (JAXBException e) { - e.printStackTrace(); - log.error("Could not unmarshal the .orc file. " + e.getMessage()); - } - return null; - } - /** * Write an XML representation of a list of presets. * - * @param dest the stream to write the data to + * @param dest the stream to write the data to * @param theMaterialList the list of materials to be included * @param thePresetList the list of presets to be included * * @throws IOException thrown if the stream could not be written */ - public void save(OutputStream dest, List theMaterialList, List thePresetList) throws IOException { + public void save(OutputStream dest, List theMaterialList, List thePresetList) throws + IOException { log.info("Saving .orc file"); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(dest, "UTF-8")); @@ -89,6 +88,26 @@ public class OpenRocketComponentSaver { writer.close(); } + /** + * Read from an open Reader instance XML in .orc format and reconstruct an OpenRocketComponentDTO instance. + * + * @param is an open Reader; assumed to be opened on a file of XML in .orc format + * + * @return the OpenRocketComponentDTO that is a POJO representation of the XML; null if the data could not be read + * or was in an invalid format + */ + private OpenRocketComponentDTO fromOpenRocketComponent(Reader is) { + try { + JAXBContext bind = JAXBContext.newInstance(OpenRocketComponentDTO.class); + Unmarshaller unmarshaller = bind.createUnmarshaller(); + return (OpenRocketComponentDTO) unmarshaller.unmarshal(is); + } + catch (JAXBException e) { + log.error("Could not unmarshal the .orc file. ", e); + } + return null; + } + /** * Root conversion method. It iterates over all subcomponents. * @@ -111,17 +130,13 @@ public class OpenRocketComponentSaver { return rsd; } - public List fromOpenRocketComponentDTO(OpenRocketComponentDTO dto) { - return null; - } - /** * Factory method that maps a preset to the corresponding DTO handler. * - * @param thePreset the preset for which a handler will be found + * @param thePreset the preset for which a handler will be found * * @return a subclass of BaseComponentDTO that can be used for marshalling/unmarshalling a preset; null if not found - * for the preset type + * for the preset type */ private static BaseComponentDTO toComponentDTO(ComponentPreset thePreset) { switch (thePreset.getType()) {