1 package org.kuali.ole.docstore.common.search;
2
3
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.docstore.common.document.factory.JAXBContextFactory;
6
7 import javax.xml.bind.Marshaller;
8 import javax.xml.bind.Unmarshaller;
9 import javax.xml.bind.annotation.XmlAccessType;
10 import javax.xml.bind.annotation.XmlAccessorType;
11 import javax.xml.bind.annotation.XmlRootElement;
12 import javax.xml.bind.annotation.XmlType;
13 import javax.xml.transform.stream.StreamSource;
14 import java.io.ByteArrayInputStream;
15 import java.io.StringWriter;
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 @XmlAccessorType(XmlAccessType.FIELD)
38 @XmlType(name = "browseParams", propOrder = {
39 "totalCount"
40 })
41 @XmlRootElement
42 public class BrowseParams
43 extends SearchParams
44 {
45 private static final Logger LOG = Logger.getLogger(BrowseParams.class);
46 protected long totalCount;
47
48
49
50
51
52 public long getTotalCount() {
53 return totalCount;
54 }
55
56
57
58
59
60 public void setTotalCount(long value) {
61 this.totalCount = value;
62 }
63
64 @Override
65 public String serialize(Object object) {
66 String result = null;
67 BrowseParams browseParams = (BrowseParams) object;
68 try {
69 StringWriter sw = new StringWriter();
70 JAXBContextFactory jaxbContextFactory = JAXBContextFactory.getInstance();
71 Marshaller jaxbMarshaller = jaxbContextFactory.getMarshaller(BrowseParams.class);
72 synchronized (jaxbMarshaller) {
73 jaxbMarshaller.marshal(browseParams, sw);
74 }
75
76 result = sw.toString();
77 } catch (Exception e) {
78 LOG.error("Exception :", e);
79 }
80 return result;
81 }
82
83 @Override
84 public Object deserialize(String content) {
85 BrowseParams browseParams = new BrowseParams();
86 try {
87 Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(BrowseParams.class);
88 ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
89 synchronized (unmarshaller) {
90 browseParams = unmarshaller.unmarshal(new StreamSource(input), BrowseParams.class).getValue();
91 }
92
93 } catch (Exception e) {
94 LOG.error("Exception :", e);
95 }
96 return browseParams;
97 }
98
99 }