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.factory.JAXBContextFactory;
8   
9   import javax.xml.bind.Marshaller;
10  import javax.xml.bind.Unmarshaller;
11  import javax.xml.bind.annotation.XmlAccessType;
12  import javax.xml.bind.annotation.XmlAccessorType;
13  import javax.xml.bind.annotation.XmlRootElement;
14  import javax.xml.bind.annotation.XmlType;
15  import javax.xml.transform.stream.StreamSource;
16  import java.io.ByteArrayInputStream;
17  import java.io.StringWriter;
18  
19  
20  /**
21   * <p>Java class for pHoldings complex type.
22   * <p/>
23   * <p>The following schema fragment specifies the expected content contained within this class.
24   * <p/>
25   * <pre>
26   * &lt;complexType name="pHoldings">
27   *   &lt;complexContent>
28   *     &lt;extension base="{}holdings">
29   *       &lt;sequence>
30   *       &lt;/sequence>
31   *     &lt;/extension>
32   *   &lt;/complexContent>
33   * &lt;/complexType>
34   * </pre>
35   */
36  @XmlAccessorType(XmlAccessType.FIELD)
37  @XmlType(name = "pHoldings")
38  
39  @XmlRootElement(name = "holdingsDoc")
40  public class PHoldings
41          extends Holdings {
42  
43      private static final Logger LOG = Logger.getLogger(PHoldings.class);
44      public static final String PRINT="print";
45  
46      public PHoldings() {
47          holdingsType = PRINT;
48          category=DocCategory.WORK.getCode();
49          type=DocType.HOLDINGS.getCode();
50          format=DocFormat.OLEML.getCode();
51      }
52  
53      @Override
54      public String serialize(Object object) {
55          String result = null;
56          PHoldings holdings = (PHoldings) object;
57          try {
58          StringWriter sw = new StringWriter();
59              Marshaller jaxbMarshaller = JAXBContextFactory.getInstance().getMarshaller(PHoldings.class);
60              synchronized (jaxbMarshaller) {
61                  jaxbMarshaller.marshal(holdings, sw);
62              }
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          PHoldings holdings = new PHoldings();
73          try {
74              Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(PHoldings.class);
75              ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
76              synchronized (unmarshaller) {
77                  holdings = unmarshaller.unmarshal(new StreamSource(input), PHoldings.class).getValue();
78              }
79          } catch (Exception e) {
80              LOG.error("Exception ", e);
81          }
82          return holdings;
83      }
84  
85  
86      @Override
87      public Object deserializeContent(Object object) {
88          return null;  //To change body of implemented methods use File | Settings | File Templates.
89      }
90  }