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 = "holdings")
41 public class PHoldings
42 extends Holdings {
43
44 private static final Logger LOG = Logger.getLogger(PHoldings.class);
45
46 public PHoldings() {
47 holdingsType = "print";
48 category=DocCategory.WORK.getCode();
49 type=DocType.HOLDINGS.getCode();
50 format=DocFormat.OLEML.getCode();
51 }
52
53 @Override
54 public String serialize(Object object) {
55 String result = null;
56 StringWriter sw = new StringWriter();
57 PHoldings pHoldings = (PHoldings) object;
58 try {
59 JAXBContext jaxbContext = JAXBContext.newInstance(PHoldings.class);
60 Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
61 jaxbMarshaller.marshal(pHoldings, sw);
62 result = sw.toString();
63 } catch (Exception e) {
64 LOG.error("Exception ", e);
65 }
66 return result;
67 }
68
69 @Override
70 public Object deserialize(String content) {
71
72 JAXBElement<PHoldings> pHoldingsElement = null;
73 try {
74 JAXBContext jaxbContext = JAXBContext.newInstance(PHoldings.class);
75 Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
76 ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
77 pHoldingsElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), PHoldings.class);
78 } catch (Exception e) {
79 LOG.error("Exception ", e);
80 }
81 return pHoldingsElement.getValue();
82 }
83
84 @Override
85 public Object deserializeContent(Object object) {
86 return null;
87 }
88 }