1 package org.kuali.ole.docstore.common.exception;
2
3
4 import org.apache.log4j.Logger;
5
6 import javax.xml.bind.JAXBContext;
7 import javax.xml.bind.JAXBElement;
8 import javax.xml.bind.Marshaller;
9 import javax.xml.bind.Unmarshaller;
10 import javax.xml.bind.annotation.*;
11 import javax.xml.transform.stream.StreamSource;
12 import java.io.ByteArrayInputStream;
13 import java.io.StringWriter;
14 import java.util.ArrayList;
15 import java.util.List;
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 @XmlAccessorType(XmlAccessType.FIELD)
36 @XmlType(name = "bibImportResponse", propOrder = {
37 "bibImportResults"
38 })
39
40 @XmlRootElement
41 public class BibImportResponse {
42
43 private static final Logger LOG = Logger.getLogger(BibImportResponse.class);
44
45 @XmlElement(nillable = true)
46 protected List<BibImportResult> bibImportResults;
47
48
49 public static String serialize(Object object) {
50 String result = null;
51 StringWriter sw = new StringWriter();
52 BibImportResponse bibImportResponse = (BibImportResponse) object;
53 try {
54 JAXBContext jaxbContext = JAXBContext.newInstance(BibImportResponse.class);
55 Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
56 jaxbMarshaller.marshal(bibImportResponse, sw);
57 result = sw.toString();
58 } catch (Exception e) {
59 LOG.error("Exception :", e);
60 }
61 return result;
62 }
63
64 public static Object deserialize(String content) {
65
66 JAXBElement<BibImportResponse> bibImportResponseElement = null;
67 try {
68 JAXBContext jaxbContext = JAXBContext.newInstance(BibImportResponse.class);
69 Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
70 ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
71 bibImportResponseElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), BibImportResponse.class);
72 } catch (Exception e) {
73 LOG.error("Exception :", e);
74 }
75 return bibImportResponseElement.getValue();
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98 public List<BibImportResult> getBibImportResults() {
99 if (bibImportResults == null) {
100 bibImportResults = new ArrayList<BibImportResult>();
101 }
102 return this.bibImportResults;
103 }
104
105 public void setBibImportResults(List<BibImportResult> bibImportResults) {
106 this.bibImportResults = bibImportResults;
107 }
108
109 }