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.factory.JAXBContextFactory;
5   
6   import javax.xml.bind.Marshaller;
7   import javax.xml.bind.Unmarshaller;
8   import javax.xml.bind.annotation.*;
9   import javax.xml.transform.stream.StreamSource;
10  import java.io.ByteArrayInputStream;
11  import java.io.StringWriter;
12  import java.util.ArrayList;
13  import java.util.List;
14  
15  /**
16   * Created with IntelliJ IDEA.
17   * User: rajeshbabuk
18   * Date: 7/4/14
19   * Time: 3:47 PM
20   * To change this template use File | Settings | File Templates.
21   */
22  
23  @XmlAccessorType(XmlAccessType.FIELD)
24  @XmlType(name = "holdingsDocs", propOrder = {
25          "holdingsDocs"
26  })
27  @XmlRootElement(name="holdingsDocs")
28  public class HoldingsDocs {
29  
30      private static final Logger LOG = Logger.getLogger(Items.class);
31      @XmlElement(name = "holdingsDoc")
32      protected List<Holdings> holdingsDocs;
33  
34  
35      public static String serialize(Object object) {
36          String result = null;
37          HoldingsDocs holdingsDocs = (HoldingsDocs) object;
38          try {
39              StringWriter sw = new StringWriter();
40              Marshaller jaxbMarshaller = JAXBContextFactory.getInstance().getMarshaller(HoldingsDocs.class);
41              synchronized (jaxbMarshaller) {
42                  jaxbMarshaller.marshal(holdingsDocs, sw);
43              }
44              result = sw.toString();
45          } catch (Exception e) {
46              LOG.error("Exception ", e);
47          }
48          return result;
49      }
50  
51  
52      public static Object deserialize(String content) {
53          HoldingsDocs holdings = new HoldingsDocs();
54          try {
55              Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(HoldingsDocs.class);
56              ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
57              synchronized (unmarshaller) {
58                  holdings = unmarshaller.unmarshal(new StreamSource(input), HoldingsDocs.class).getValue();
59              }
60          } catch (Exception e) {
61              LOG.error("Exception ", e);
62          }
63          return holdings;
64      }
65  
66      /**
67       * Gets the value of the holdingsDocs property.
68       * <p/>
69       * <p/>
70       * This accessor method returns a reference to the live list,
71       * not a snapshot. Therefore any modification you make to the
72       * returned list will be present inside the JAXB object.
73       * This is why there is not a <CODE>set</CODE> method for the holdingsDocs property.
74       * <p/>
75       * <p/>
76       * For example, to add a new holdings, do as follows:
77       * <pre>
78       *    getHoldingsDocs().add(newHoldings);
79       * </pre>
80       * <p/>
81       * <p/>
82       * <p/>
83       * Objects of the following type(s) are allowed in the list
84       * {@link Bib }
85       */
86      public List<Holdings> getHoldingsDocs() {
87          if (holdingsDocs == null) {
88              holdingsDocs = new ArrayList<Holdings>();
89          }
90          return this.holdingsDocs;
91      }
92  }