1
2
3
4
5
6 package yawn.io.serialization.xml;
7
8 import java.io.InputStreamReader;
9 import java.io.OutputStreamWriter;
10
11 import org.exolab.castor.xml.MarshalException;
12 import org.exolab.castor.xml.Marshaller;
13 import org.exolab.castor.xml.Unmarshaller;
14 import org.exolab.castor.xml.ValidationException;
15
16 import yawn.io.serialization.ISerializer;
17 import yawn.io.serialization.SerializationException;
18
19 /***
20 * XML serializer based on Castor (@link http://castor.exolab.org)
21 *
22 * <p>$Id: CastorXmlSerializer.java,v 1.4 2005/04/20 18:55:19 supermarti Exp $</p>
23 *
24 * @author <a href="mailto:alexei.guevara@uhn.on.ca">Alexei Guevara </a>
25 * @version $Revision: 1.4 $
26 */
27 public class CastorXmlSerializer implements ISerializer {
28
29 /***
30 *
31 * @see yawn.io.serialization.ISerializer#serialize(Object,
32 * OutputStreamWriter)
33 */
34 public void serialize(Object network, OutputStreamWriter writer) throws SerializationException {
35 try {
36 Marshaller.marshal(network, writer);
37 } catch (MarshalException e) {
38 throw new SerializationException(e);
39 } catch (ValidationException e) {
40 throw new SerializationException(e);
41 }
42 }
43
44 /***
45 *
46 * @see yawn.io.serialization.ISerializer#deSerialize(Class, InputStreamReader)
47 */
48 public Object deSerialize(Class root, InputStreamReader reader) throws SerializationException {
49 try {
50 return Unmarshaller.unmarshal(root, reader);
51 } catch (MarshalException e) {
52 throw new SerializationException(e);
53 } catch (ValidationException e) {
54 throw new SerializationException(e);
55 }
56 }
57
58 }