001package org.kuali.ole.docstore.common.document;
002
003import org.apache.log4j.Logger;
004import org.kuali.ole.docstore.common.document.content.enums.DocCategory;
005import org.kuali.ole.docstore.common.document.content.enums.DocFormat;
006import org.kuali.ole.docstore.common.document.content.enums.DocType;
007import org.kuali.ole.docstore.common.document.content.instance.OleHoldings;
008import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
009
010import javax.xml.bind.JAXBContext;
011import javax.xml.bind.JAXBElement;
012import javax.xml.bind.Marshaller;
013import javax.xml.bind.Unmarshaller;
014import javax.xml.transform.stream.StreamSource;
015import java.io.ByteArrayInputStream;
016import java.io.StringWriter;
017
018/**
019 * Created with IntelliJ IDEA.
020 * User: sambasivam
021 * Date: 12/13/13
022 * Time: 3:32 PM
023 * To change this template use File | Settings | File Templates.
024 */
025public class EHoldingsOleml extends EHoldings {
026
027    private static final Logger LOG = Logger.getLogger(EHoldingsOleml.class);
028    protected String accessStatus;
029    protected String platForm;
030    protected String imprint;
031    protected String statisticalCode;
032    protected String location;
033    protected String url;
034    protected String eResourceName;
035    protected String subscriptionStatus;
036
037    public EHoldingsOleml() {
038        holdingsType = "electronic";
039        category=DocCategory.WORK.getCode();
040        type=DocType.EHOLDINGS.getCode();
041        format=DocFormat.OLEML.getCode();
042    }
043
044    public String getAccessStatus() {
045        return accessStatus;
046    }
047
048    public void setAccessStatus(String accessStatus) {
049        this.accessStatus = accessStatus;
050    }
051
052    public String getPlatForm() {
053        return platForm;
054    }
055
056    public void setPlatForm(String platForm) {
057        this.platForm = platForm;
058    }
059
060    public String getImprint() {
061        return imprint;
062    }
063
064    public void setImprint(String imprint) {
065        this.imprint = imprint;
066    }
067
068    public String getStatisticalCode() {
069        return statisticalCode;
070    }
071
072    public void setStatisticalCode(String statisticalCode) {
073        this.statisticalCode = statisticalCode;
074    }
075
076    public String getLocation() {
077        return location;
078    }
079
080    public void setLocation(String location) {
081        this.location = location;
082    }
083
084    public String getUrl() {
085        return url;
086    }
087
088    public void setUrl(String url) {
089        this.url = url;
090    }
091
092    public String geteResourceName() {
093        return eResourceName;
094    }
095
096    public void seteResourceName(String eResourceName) {
097        this.eResourceName = eResourceName;
098    }
099
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}