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