1 package org.kuali.ole.docstore.common.document;
2
3 import org.apache.log4j.Logger;
4
5 import javax.xml.bind.JAXBContext;
6 import javax.xml.bind.JAXBElement;
7 import javax.xml.bind.Marshaller;
8 import javax.xml.bind.Unmarshaller;
9 import javax.xml.bind.annotation.*;
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 @XmlAccessorType(XmlAccessType.FIELD)
25 @XmlType(name = "holdingsDocs", propOrder = {
26 "holdingsDocs"
27 })
28 @XmlRootElement(name="holdingsDocs")
29 public class HoldingsDocs {
30
31 private static final Logger LOG = Logger.getLogger(Items.class);
32 @XmlElement(name = "holdingsDoc")
33 protected List<Holdings> holdingsDocs;
34
35 public static String serialize(Object object) {
36 String result = null;
37 StringWriter sw = new StringWriter();
38 HoldingsDocs holdingsDocs = (HoldingsDocs) object;
39 try {
40 JAXBContext jaxbContext = JAXBContext.newInstance(HoldingsDocs.class);
41 Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
42 jaxbMarshaller.marshal(holdingsDocs, sw);
43 result = sw.toString();
44 } catch (Exception e) {
45 LOG.error("Exception :", e);
46 }
47 return result;
48 }
49
50 public static Object deserialize(String holdingsDocsXml) {
51
52 JAXBElement<HoldingsDocs> holdingsDocsElement = null;
53 try {
54 JAXBContext jaxbContext = JAXBContext.newInstance(HoldingsDocs.class);
55 Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
56 ByteArrayInputStream input = new ByteArrayInputStream(holdingsDocsXml.getBytes("UTF-8"));
57 holdingsDocsElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), HoldingsDocs.class);
58 } catch (Exception e) {
59 LOG.error("Exception :", e);
60 }
61 return holdingsDocsElement.getValue();
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84 public List<Holdings> getHoldingsDocs() {
85 if (holdingsDocs == null) {
86 holdingsDocs = new ArrayList<Holdings>();
87 }
88 return this.holdingsDocs;
89 }
90 }