Hi David,
You are on the right track. To make things as easy as possible I would suggest creating a wrapper object to contain your list of results, and then marshal/unmarshal that wrapper object.
A wrapper object could look like this:
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class MatrixData {
private List<CtoPolicyMatrix> data;
public List<CtoPolicyMatrix> getData() {
return data;
}
public void setData(List<CtoPolicyMatrix> data) {
this.data = data;
}
}
Your persistMatrixData method would look like this:
public void persistMatrixData(List results) {
// Save CtoPolicyMatrix to XML
try {
MatrixData data = new MatrixData();
data.setData(results);
File file = new File("D:/Temp/MatrixData.xml");
jc = JAXBContext.newInstance(MatrixData.class);
Marshaller marshaller = jc.createMarshaller();
marshaller.marshal(data, file);
} catch (JAXBException e) {
e.printStackTrace();
}
}
And reading them back in:
public void retrieveMatrixData(List results) {
// Load CtoPolicyMatrix from XML
Unmarshaller unmarshaller;
try {
File file = new File("D:/Temp/MatrixData.xml");
unmarshaller = jc.createUnmarshaller();
MatrixData data = (MatrixData) u.unmarshal(file);
List<CtoPolicyMatrix> savedResults = data.getData();
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Hope this helps,
Rick