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