1 package org.kuali.ole.docstore.common.document;
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 @XmlAccessorType(XmlAccessType.FIELD)
35 @XmlType(name = "bibs", propOrder = {
36 "bibs"
37 })
38 @XmlRootElement(name = "bibDocs")
39 public class Bibs {
40
41 private static final Logger LOG = Logger.getLogger(Bibs.class);
42
43 @XmlElement(name = "bibDoc")
44 protected List<Bib> bibs;
45
46 public static String serialize(Object object) {
47 String result = null;
48 StringWriter sw = new StringWriter();
49 Bibs bibs = (Bibs) object;
50 try {
51 JAXBContext jaxbContext = JAXBContext.newInstance(Bibs.class);
52 Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
53 jaxbMarshaller.marshal(bibs, sw);
54 result = sw.toString();
55 } catch (Exception e) {
56 LOG.error("Exception :", e);
57 }
58 return result;
59 }
60
61 public static Object deserialize(String bibsXml) {
62
63 JAXBElement<Bibs> bibsElement = null;
64 try {
65 JAXBContext jaxbContext = JAXBContext.newInstance(Bibs.class);
66 Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
67 ByteArrayInputStream input = new ByteArrayInputStream(bibsXml.getBytes("UTF-8"));
68 bibsElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), Bibs.class);
69 } catch (Exception e) {
70 LOG.error("Exception :", e);
71 }
72 return bibsElement.getValue();
73 }
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 public List<Bib> getBibs() {
96 if (bibs == null) {
97 bibs = new ArrayList<Bib>();
98 }
99 return this.bibs;
100 }
101
102 }