View Javadoc
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.bind.annotation.XmlRootElement;
15  import javax.xml.transform.stream.StreamSource;
16  import java.io.ByteArrayInputStream;
17  import java.io.StringWriter;
18  
19  /**
20   * Created with IntelliJ IDEA.
21   * User: sambasivam
22   * Date: 12/13/13
23   * Time: 3:32 PM
24   * To change this template use File | Settings | File Templates.
25   */
26  @XmlRootElement(name = "holdings")
27  public class PHoldingsOleml extends PHoldings {
28  
29      private static final Logger LOG = Logger.getLogger(PHoldingsOleml.class);
30  
31      public PHoldingsOleml() {
32          holdingsType = "print";
33          category=DocCategory.WORK.getCode();
34          type=DocType.HOLDINGS.getCode();
35          format=DocFormat.OLEML.getCode();
36      }
37  
38      @Override
39      public String serialize(Object object) {
40          String result = null;
41          StringWriter sw = new StringWriter();
42          PHoldingsOleml pHoldings = (PHoldingsOleml) object;
43          try {
44              JAXBContext jaxbContext = JAXBContext.newInstance(PHoldingsOleml.class);
45              Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
46              jaxbMarshaller.marshal(pHoldings, sw);
47              result = sw.toString();
48          } catch (Exception e) {
49              LOG.error("Exception ", e);
50          }
51          return result;
52      }
53  
54      @Override
55      public Object deserialize(String content) {
56  
57          JAXBElement<PHoldingsOleml> pHoldingsElement = null;
58          try {
59              JAXBContext jaxbContext = JAXBContext.newInstance(PHoldingsOleml.class);
60              Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
61              ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
62              pHoldingsElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), PHoldingsOleml.class);
63          } catch (Exception e) {
64              LOG.error("Exception ", e);
65          }
66          return pHoldingsElement.getValue();
67      }
68  
69      @Override
70      public Object deserializeContent(String content) {
71          HoldingOlemlRecordProcessor recordProcessor = new HoldingOlemlRecordProcessor();
72          OleHoldings oleHoldings = recordProcessor.fromXML(content);
73          return oleHoldings;
74      }
75  
76      @Override
77      public String serializeContent(Object object) {
78          OleHoldings oleHoldings = (OleHoldings) object;
79          HoldingOlemlRecordProcessor recordProcessor = new HoldingOlemlRecordProcessor();
80          String content = recordProcessor.toXML(oleHoldings);
81          return content;
82      }
83  
84  }