This commit is contained in:
Doug Pedrick 2012-04-25 20:59:35 +00:00
parent 619e17b40f
commit 517207857b

View File

@ -54,23 +54,21 @@ 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<ComponentPreset> 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.
*
@ -80,7 +78,8 @@ public class OpenRocketComponentSaver {
*
* @throws IOException thrown if the stream could not be written
*/
public void save(OutputStream dest, List<Material> theMaterialList, List<ComponentPreset> thePresetList) throws IOException {
public void save(OutputStream dest, List<Material> theMaterialList, List<ComponentPreset> 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,10 +130,6 @@ public class OpenRocketComponentSaver {
return rsd;
}
public List<ComponentPreset> fromOpenRocketComponentDTO(OpenRocketComponentDTO dto) {
return null;
}
/**
* Factory method that maps a preset to the corresponding DTO handler.
*