1 package org.kuali.ole.converters;
2
3 import com.thoughtworks.xstream.converters.Converter;
4 import com.thoughtworks.xstream.converters.MarshallingContext;
5 import com.thoughtworks.xstream.converters.UnmarshallingContext;
6 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
7 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
8 import org.kuali.ole.bo.explain.OleSRUExplainServerInfo;
9
10
11
12
13
14
15
16
17
18 public class OleSRUExplainServerInfoConverter implements Converter {
19
20
21 @Override
22 public void marshal(Object o, HierarchicalStreamWriter hierarchicalStreamWriter,
23 MarshallingContext marshallingContext) {
24 OleSRUExplainServerInfo oleSRUExplainServerInfo = (OleSRUExplainServerInfo) o;
25 hierarchicalStreamWriter.addAttribute("protocol", oleSRUExplainServerInfo.getProtocol());
26 hierarchicalStreamWriter.addAttribute("version", oleSRUExplainServerInfo.getVersion() == null ? "" : oleSRUExplainServerInfo.getVersion());
27 hierarchicalStreamWriter.addAttribute("transport", oleSRUExplainServerInfo.getTransport() == null ? "" : oleSRUExplainServerInfo.getTransport());
28 hierarchicalStreamWriter.addAttribute("method", oleSRUExplainServerInfo.getMethod() == null ? "" : oleSRUExplainServerInfo.getMethod());
29 hierarchicalStreamWriter.setValue(oleSRUExplainServerInfo.getValue());
30 hierarchicalStreamWriter.startNode("zr:host");
31 hierarchicalStreamWriter.setValue(oleSRUExplainServerInfo.getHost());
32 hierarchicalStreamWriter.endNode();
33 hierarchicalStreamWriter.startNode("zr:port");
34 hierarchicalStreamWriter.setValue(oleSRUExplainServerInfo.getPort());
35 hierarchicalStreamWriter.endNode();
36 hierarchicalStreamWriter.startNode("zr:database");
37 hierarchicalStreamWriter.setValue(oleSRUExplainServerInfo.getDatabase());
38 hierarchicalStreamWriter.endNode();
39
40 }
41
42 @Override
43 public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader,
44 UnmarshallingContext unmarshallingContext) {
45
46 OleSRUExplainServerInfo oleSRUExplainServerInfo = new OleSRUExplainServerInfo();
47 oleSRUExplainServerInfo.setProtocol(hierarchicalStreamReader.getAttribute("protocol"));
48 oleSRUExplainServerInfo.setVersion(hierarchicalStreamReader.getAttribute("version"));
49 oleSRUExplainServerInfo.setTransport(hierarchicalStreamReader.getAttribute("transport"));
50 oleSRUExplainServerInfo.setMethod(hierarchicalStreamReader.getAttribute("method"));
51 oleSRUExplainServerInfo.setValue(hierarchicalStreamReader.getValue());
52 while(hierarchicalStreamReader.hasMoreChildren()) {
53 hierarchicalStreamReader.moveDown();
54 if ("zr:host".equals(hierarchicalStreamReader.getNodeName()))
55 oleSRUExplainServerInfo.setHost(hierarchicalStreamReader.getValue());
56 else if ("zr:port".equals(hierarchicalStreamReader.getNodeName()))
57 oleSRUExplainServerInfo.setPort(hierarchicalStreamReader.getValue());
58 else if ("zr:database".equals(hierarchicalStreamReader.getNodeName()))
59 oleSRUExplainServerInfo.setDatabase(hierarchicalStreamReader.getValue());
60 hierarchicalStreamReader.moveUp();
61 }
62 return oleSRUExplainServerInfo;
63 }
64
65 @Override
66 public boolean canConvert(Class aClass) {
67 return aClass.equals(OleSRUExplainServerInfo.class);
68 }
69 }