1
2
3
4
5
6 package org.neo.swarm.util.serialize;
7
8 import org.neo.swarm.core.aop.silc.comp.AspectInvocation;
9 import org.neo.swarm.core.aop.silc.comp.Perspective;
10 import org.neo.swarm.interceptor.logging.JavaLoggingInterceptor;
11 import org.neo.swarm.interceptor.tcp.TcpClientInterceptor;
12
13 import com.thoughtworks.xstream.XStream;
14 import com.thoughtworks.xstream.converters.extended.DynamicProxyConverter;
15 import com.thoughtworks.xstream.core.ReferenceByIdMarshallingStrategy;
16 import com.thoughtworks.xstream.io.xml.XppDriver;
17
18 /***
19 * This object does.....
20 *
21 * @author neil.avery
22 */
23 public class XMLSerializer implements Serializer {
24 transient final XStream xstream = new XStream(new XppDriver());
25
26 public XMLSerializer(){
27 xstream.setMarshallingStrategy(new ReferenceByIdMarshallingStrategy());
28 xstream.registerConverter(new DynamicProxyConverter(xstream.getClassMapper()));
29
30
31 xstream.alias("invoke", AspectInvocation.class);
32 xstream.alias("perspective", Perspective.class);
33 xstream.alias("tcpclientintr", TcpClientInterceptor.class);
34 xstream.alias("javaloggingintr", JavaLoggingInterceptor.class);
35 }
36
37
38
39
40
41
42 public byte[] serialize(Object object) {
43
44 return xstream.toXML(object).getBytes();
45
46 }
47
48
49
50
51
52
53 public Object deserialize(byte[] data) {
54 return xstream.fromXML(new String(data));
55 }
56 }