1 package org.kuali.ole.docstore.common.document;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.docstore.common.document.content.enums.DocCategory;
5 import org.kuali.ole.docstore.common.document.content.enums.DocFormat;
6 import org.kuali.ole.docstore.common.document.content.enums.DocType;
7
8 import javax.xml.bind.JAXBContext;
9 import javax.xml.bind.JAXBElement;
10 import javax.xml.bind.Marshaller;
11 import javax.xml.bind.Unmarshaller;
12 import javax.xml.bind.annotation.XmlAccessType;
13 import javax.xml.bind.annotation.XmlAccessorType;
14 import javax.xml.bind.annotation.XmlRootElement;
15 import javax.xml.bind.annotation.XmlType;
16 import javax.xml.transform.stream.StreamSource;
17 import java.io.ByteArrayInputStream;
18 import java.io.StringWriter;
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 @XmlAccessorType(XmlAccessType.FIELD)
38 @XmlType(name = "pHoldings")
39
40 @XmlRootElement(name = "holdingsDoc")
41 public class PHoldings
42 extends Holdings {
43
44 private static final Logger LOG = Logger.getLogger(PHoldings.class);
45 public static final String PRINT="print";
46
47 public PHoldings() {
48 holdingsType = PRINT;
49 category=DocCategory.WORK.getCode();
50 type=DocType.HOLDINGS.getCode();
51 format=DocFormat.OLEML.getCode();
52 }
53
54 @Override
55 public String serialize(Object object) {
56 String result = null;
57 StringWriter sw = new StringWriter();
58 PHoldings pHoldings = (PHoldings) object;
59 try {
60 JAXBContext jaxbContext = JAXBContext.newInstance(PHoldings.class);
61 Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
62 jaxbMarshaller.marshal(pHoldings, sw);
63 result = sw.toString();
64 } catch (Exception e) {
65 LOG.error("Exception ", e);
66 }
67 return result;
68 }
69
70 @Override
71 public Object deserialize(String content) {
72
73 JAXBElement<PHoldings> pHoldingsElement = null;
74 try {
75 JAXBContext jaxbContext = JAXBContext.newInstance(PHoldings.class);
76 Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
77 ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
78 pHoldingsElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), PHoldings.class);
79 } catch (Exception e) {
80 LOG.error("Exception ", e);
81 }
82 return pHoldingsElement.getValue();
83 }
84
85 @Override
86 public Object deserializeContent(Object object) {
87 return null;
88 }
89 }