1   package org.kuali.ole.docstore.common.search;
2   
3   import org.apache.log4j.Logger;
4   
5   import java.io.ByteArrayInputStream;
6   import java.io.StringWriter;
7   import java.util.ArrayList;
8   import java.util.List;
9   import javax.xml.bind.JAXBContext;
10  import javax.xml.bind.JAXBElement;
11  import javax.xml.bind.Marshaller;
12  import javax.xml.bind.Unmarshaller;
13  import javax.xml.bind.annotation.*;
14  import javax.xml.transform.stream.StreamSource;
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  @XmlAccessorType(XmlAccessType.FIELD)
41  @XmlType(name = "searchResponse", propOrder = {
42          "endIndex",
43          "pageSize",
44          "searchResults",
45          "startIndex",
46          "totalRecordCount",
47          "facetResult",
48          "time"
49  })
50  @XmlRootElement
51  public class SearchResponse {
52  
53      private static final Logger LOG = Logger.getLogger(SearchResponse.class);
54      protected int endIndex;
55      protected int pageSize;
56  
57      @XmlElementWrapper(name = "searchResults")
58      @XmlElement(name = "searchResult")
59      protected List<SearchResult> searchResults;
60      protected int startIndex;
61      protected int totalRecordCount;
62      protected FacetResult facetResult;
63  
64      protected int time;
65  
66      public FacetResult getFacetResult() {
67          return facetResult;
68      }
69  
70      public void setFacetResult(FacetResult facetResult) {
71          this.facetResult = facetResult;
72      }
73  
74      
75  
76  
77  
78      public int getEndIndex() {
79          return endIndex;
80      }
81  
82      
83  
84  
85  
86      public void setEndIndex(int value) {
87          this.endIndex = value;
88      }
89  
90      
91  
92  
93  
94      public int getPageSize() {
95          return pageSize;
96      }
97  
98      
99  
100 
101 
102     public void setPageSize(int value) {
103         this.pageSize = value;
104     }
105 
106     
107 
108 
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128     public List<SearchResult> getSearchResults() {
129         if (searchResults == null) {
130             searchResults = new ArrayList<SearchResult>();
131         }
132         return this.searchResults;
133     }
134 
135     
136 
137 
138 
139     public int getStartIndex() {
140         return startIndex;
141     }
142 
143     
144 
145 
146 
147     public void setStartIndex(int value) {
148         this.startIndex = value;
149     }
150 
151     
152 
153 
154 
155     public int getTotalRecordCount() {
156         return totalRecordCount;
157     }
158 
159     
160 
161 
162 
163     public void setTotalRecordCount(int value) {
164         this.totalRecordCount = value;
165     }
166 
167     public int getTime() {
168         return time;
169     }
170 
171     public void setTime(int time) {
172         this.time = time;
173     }
174 
175     public String serialize(Object object) {
176         String result = null;
177         StringWriter sw = new StringWriter();
178         SearchResponse searchResponse = (SearchResponse) object;
179         try {
180             JAXBContext jaxbContext = JAXBContext.newInstance(SearchResponse.class);
181             Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
182             jaxbMarshaller.marshal(searchResponse, sw);
183             result = sw.toString();
184         } catch (Exception e) {
185             LOG.error("Exception ", e);
186         }
187         return result;
188     }
189 
190 
191     public Object deserialize(String content) {
192 
193         JAXBElement<SearchResponse> SearchResponseElement = null;
194         try {
195             JAXBContext jaxbContext = JAXBContext.newInstance(SearchResponse.class);
196             Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
197             ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
198             SearchResponseElement = jaxbUnmarshaller.unmarshal(new StreamSource(input),SearchResponse.class);
199         } catch (Exception e) {
200             LOG.error("Exception ", e);
201         }
202         return SearchResponseElement.getValue();
203     }
204 }