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 import org.kuali.ole.docstore.common.document.content.instance.OleHoldings;
8 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
9
10 import javax.xml.bind.JAXBContext;
11 import javax.xml.bind.JAXBElement;
12 import javax.xml.bind.Marshaller;
13 import javax.xml.bind.Unmarshaller;
14 import javax.xml.transform.stream.StreamSource;
15 import java.io.ByteArrayInputStream;
16 import java.io.StringWriter;
17
18
19
20
21
22
23
24
25 public class EHoldingsOleml extends EHoldings {
26
27 private static final Logger LOG = Logger.getLogger(EHoldingsOleml.class);
28 protected String accessStatus;
29 protected String platForm;
30 protected String imprint;
31 protected String statisticalCode;
32 protected String location;
33 protected String url;
34 protected String eResourceName;
35 protected String subscriptionStatus;
36
37 public EHoldingsOleml() {
38 holdingsType = "electronic";
39 category=DocCategory.WORK.getCode();
40 type=DocType.EHOLDINGS.getCode();
41 format=DocFormat.OLEML.getCode();
42 }
43
44 public String getAccessStatus() {
45 return accessStatus;
46 }
47
48 public void setAccessStatus(String accessStatus) {
49 this.accessStatus = accessStatus;
50 }
51
52 public String getPlatForm() {
53 return platForm;
54 }
55
56 public void setPlatForm(String platForm) {
57 this.platForm = platForm;
58 }
59
60 public String getImprint() {
61 return imprint;
62 }
63
64 public void setImprint(String imprint) {
65 this.imprint = imprint;
66 }
67
68 public String getStatisticalCode() {
69 return statisticalCode;
70 }
71
72 public void setStatisticalCode(String statisticalCode) {
73 this.statisticalCode = statisticalCode;
74 }
75
76 public String getLocation() {
77 return location;
78 }
79
80 public void setLocation(String location) {
81 this.location = location;
82 }
83
84 public String getUrl() {
85 return url;
86 }
87
88 public void setUrl(String url) {
89 this.url = url;
90 }
91
92 public String geteResourceName() {
93 return eResourceName;
94 }
95
96 public void seteResourceName(String eResourceName) {
97 this.eResourceName = eResourceName;
98 }
99
100 public String getSubscriptionStatus() {
101 return subscriptionStatus;
102 }
103
104 public void setSubscriptionStatus(String subscriptionStatus) {
105 this.subscriptionStatus = subscriptionStatus;
106 }
107
108 @Override
109 public String serialize(Object object) {
110 String result = null;
111 StringWriter sw = new StringWriter();
112 EHoldingsOleml holdings = (EHoldingsOleml) object;
113 try {
114 JAXBContext jaxbContext = JAXBContext.newInstance(EHoldingsOleml.class);
115 Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
116 jaxbMarshaller.marshal(holdings, sw);
117 result = sw.toString();
118 } catch (Exception e) {
119 LOG.error("Exception ", e);
120 }
121 return result;
122 }
123
124 @Override
125 public Object deserialize(String content) {
126 JAXBElement<EHoldingsOleml> holdingsElement = null;
127 try {
128 JAXBContext jaxbContext = JAXBContext.newInstance(EHoldingsOleml.class);
129 Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
130 ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
131 holdingsElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), EHoldingsOleml.class);
132 } catch (Exception e) {
133 LOG.error("Exception ", e);
134 }
135 return holdingsElement.getValue();
136 }
137
138 @Override
139 public Object deserializeContent(String content) {
140 HoldingOlemlRecordProcessor recordProcessor = new HoldingOlemlRecordProcessor();
141 OleHoldings oleHoldings = recordProcessor.fromXML(content);
142 return oleHoldings;
143 }
144
145 @Override
146 public String serializeContent(Object object) {
147 OleHoldings oleHoldings = (OleHoldings) object;
148 HoldingOlemlRecordProcessor recordProcessor = new HoldingOlemlRecordProcessor();
149 String content = recordProcessor.toXML(oleHoldings);
150 return content;
151 }
152
153 }