1 6 package org.prevayler.implementation.snapshot; 7 import java.io.*; 8 9 import javax.xml.transform.stream.*; 10 11 import com.skaringa.javaxml.*; 12 13 33 public class XmlSnapshotManager extends SnapshotManager { 34 35 36 public XmlSnapshotManager(Object newPrevalentSystem, String snapshotDirectoryName) throws ClassNotFoundException , IOException { 37 super(newPrevalentSystem, snapshotDirectoryName); 38 } 39 40 41 44 public Object readSnapshot(InputStream in) throws IOException { 45 StreamSource source = new StreamSource(in); 46 try { 47 return transformer().deserialize(source); 48 } catch (DeserializerException de) { 49 throw new IOException("Unable to deserialize with Skaringa: " + de.getMessage()); 50 } finally { 51 source.getInputStream().close(); 52 } 53 } 54 55 56 59 protected String suffix() { 60 return "xml"; 61 } 62 63 64 67 public void writeSnapshot(Object prevalentSystem, OutputStream out) throws IOException { 68 StreamResult result = new StreamResult(out); 69 try { 70 transformer().serialize(prevalentSystem, result); 71 } catch (SerializerException se) { 72 throw new IOException("Unable to serialize with Skaringa: " + se.getMessage()); 73 } finally { 74 result.getOutputStream().close(); 75 } 76 } 77 78 79 private ObjectTransformer transformer() throws IOException { 80 try { 81 return ObjectTransformerFactory.getInstance().getImplementation(); 82 } 87 catch (NoImplementationException nie) { 88 throw new IOException("Unable to start Skaringa: " + nie.getMessage()); 89 } 90 } 91 } 92 | Popular Tags |