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.stream.XMLStreamReader;
10 import javax.xml.transform.stream.StreamSource;
11 import java.io.ByteArrayInputStream;
12 import java.io.StringWriter;
13 import java.util.ArrayList;
14 import java.util.List;
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 = "bibTrees", propOrder = {
36 "bibTrees"
37 })
38 @XmlRootElement(name = "bibDocsTree")
39 public class BibTrees {
40
41 private static final Logger LOG = Logger.getLogger(BibTrees.class);
42 @XmlElement(name = "bibDocTree")
43 protected List<BibTree> bibTrees;
44
45 public static String serialize(Object object) {
46 String result = null;
47 BibTrees bibTrees = (BibTrees) object;
48 try {
49 StringWriter sw = new StringWriter();
50 Marshaller jaxbMarshaller = JAXBContextFactory.getInstance().getMarshaller(BibTrees.class);
51 jaxbMarshaller.marshal(bibTrees, sw);
52 result = sw.toString();
53 } catch (Exception e) {
54 LOG.error("Exception :", e);
55 }
56 return result;
57 }
58
59 public static Object deserialize(String bibTreesXml) {
60
61 BibTrees bibTrees = new BibTrees();
62 try {
63 ByteArrayInputStream bibTreeInputStream = new ByteArrayInputStream(bibTreesXml.getBytes());
64 StreamSource streamSource = new StreamSource(bibTreeInputStream);
65 XMLStreamReader xmlStreamReader = JAXBContextFactory.getInstance().getXmlInputFactory().createXMLStreamReader(streamSource);
66
67 Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(BibTrees.class);
68 bibTrees = unmarshaller.unmarshal(xmlStreamReader, BibTrees.class).getValue();
69 } catch (Exception e) {
70 LOG.error("Exception :", e);
71 }
72 return bibTrees;
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<BibTree> getBibTrees() {
96 if (bibTrees == null) {
97 bibTrees = new ArrayList<BibTree>();
98 }
99 return this.bibTrees;
100 }
101
102
103 }