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   
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   * <p>Java class for pHoldings complex type.
23   * <p/>
24   * <p>The following schema fragment specifies the expected content contained within this class.
25   * <p/>
26   * <pre>
27   * &lt;complexType name="pHoldings">
28   *   &lt;complexContent>
29   *     &lt;extension base="{}holdings">
30   *       &lt;sequence>
31   *       &lt;/sequence>
32   *     &lt;/extension>
33   *   &lt;/complexContent>
34   * &lt;/complexType>
35   * </pre>
36   */
37  @XmlAccessorType(XmlAccessType.FIELD)
38  @XmlType(name = "pHoldings")
39  
40  @XmlRootElement(name = "holdingsDoc")
41  public class PHoldings
42          extends Holdings {
43  
44      private static final Logger LOG = Logger.getLogger(PHoldings.class);
45      public static final String PRINT="print";
46  
47      public PHoldings() {
48          holdingsType = PRINT;
49          category=DocCategory.WORK.getCode();
50          type=DocType.HOLDINGS.getCode();
51          format=DocFormat.OLEML.getCode();
52      }
53  
54      @Override
55      public String serialize(Object object) {
56          String result = null;
57          StringWriter sw = new StringWriter();
58          PHoldings pHoldings = (PHoldings) object;
59          try {
60              JAXBContext jaxbContext = JAXBContext.newInstance(PHoldings.class);
61              Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
62              jaxbMarshaller.marshal(pHoldings, sw);
63              result = sw.toString();
64          } catch (Exception e) {
65              LOG.error("Exception ", e);
66          }
67          return result;
68      }
69  
70      @Override
71      public Object deserialize(String content) {
72  
73          JAXBElement<PHoldings> pHoldingsElement = null;
74          try {
75              JAXBContext jaxbContext = JAXBContext.newInstance(PHoldings.class);
76              Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
77              ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
78              pHoldingsElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), PHoldings.class);
79          } catch (Exception e) {
80              LOG.error("Exception ", e);
81          }
82          return pHoldingsElement.getValue();
83      }
84  
85      @Override
86      public Object deserializeContent(Object object) {
87          return null;  //To change body of implemented methods use File | Settings | File Templates.
88      }
89  }