1 package org.kuali.ole.docstore.common.document;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.docstore.common.document.factory.JAXBContextFactory;
5
6 import javax.xml.bind.Marshaller;
7 import javax.xml.bind.Unmarshaller;
8 import javax.xml.bind.annotation.*;
9 import javax.xml.transform.stream.StreamSource;
10 import java.io.ByteArrayInputStream;
11 import java.io.StringWriter;
12 import java.util.ArrayList;
13 import java.util.List;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 @XmlAccessorType(XmlAccessType.FIELD)
34 @XmlType(name = "bibs", propOrder = {
35 "bibs"
36 })
37 @XmlRootElement(name = "bibDocs")
38 public class Bibs {
39
40 private static final Logger LOG = Logger.getLogger(Bibs.class);
41
42 @XmlElement(name = "bibDoc")
43 protected List<Bib> bibs;
44
45 public static String serialize(Object object) {
46 String result = null;
47 Bibs bibs = (Bibs) object;
48 try {
49 StringWriter sw = new StringWriter();
50 Marshaller jaxbMarshaller = JAXBContextFactory.getInstance().getMarshaller(Bibs.class);
51 synchronized (jaxbMarshaller) {
52 jaxbMarshaller.marshal(bibs, sw);
53 }
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 Bibs bibs = new Bibs();
63 try {
64 Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(Bibs.class);
65 ByteArrayInputStream input = new ByteArrayInputStream(bibsXml.getBytes("UTF-8"));
66 synchronized (unmarshaller) {
67 bibs = unmarshaller.unmarshal(new StreamSource(input), Bibs.class).getValue();
68 }
69 } catch (Exception e) {
70 LOG.error("Exception :", e);
71 }
72 return bibs;
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 }