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 @XmlAccessorType(XmlAccessType.FIELD)
24 @XmlType(name = "holdingsDocs", propOrder = {
25 "holdingsDocs"
26 })
27 @XmlRootElement(name="holdingsDocs")
28 public class HoldingsDocs {
29
30 private static final Logger LOG = Logger.getLogger(Items.class);
31 @XmlElement(name = "holdingsDoc")
32 protected List<Holdings> holdingsDocs;
33
34
35 public static String serialize(Object object) {
36 String result = null;
37 HoldingsDocs holdingsDocs = (HoldingsDocs) object;
38 try {
39 StringWriter sw = new StringWriter();
40 Marshaller jaxbMarshaller = JAXBContextFactory.getInstance().getMarshaller(HoldingsDocs.class);
41 synchronized (jaxbMarshaller) {
42 jaxbMarshaller.marshal(holdingsDocs, sw);
43 }
44 result = sw.toString();
45 } catch (Exception e) {
46 LOG.error("Exception ", e);
47 }
48 return result;
49 }
50
51
52 public static Object deserialize(String content) {
53 HoldingsDocs holdings = new HoldingsDocs();
54 try {
55 Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(HoldingsDocs.class);
56 ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
57 synchronized (unmarshaller) {
58 holdings = unmarshaller.unmarshal(new StreamSource(input), HoldingsDocs.class).getValue();
59 }
60 } catch (Exception e) {
61 LOG.error("Exception ", e);
62 }
63 return holdings;
64 }
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 public List<Holdings> getHoldingsDocs() {
87 if (holdingsDocs == null) {
88 holdingsDocs = new ArrayList<Holdings>();
89 }
90 return this.holdingsDocs;
91 }
92 }