View Javadoc
1   package org.kuali.ole.docstore.common.document;
2   
3   import org.apache.log4j.Logger;
4   
5   import java.io.ByteArrayInputStream;
6   import java.io.StringWriter;
7   import java.util.ArrayList;
8   import java.util.List;
9   import javax.xml.bind.JAXBContext;
10  import javax.xml.bind.JAXBElement;
11  import javax.xml.bind.Marshaller;
12  import javax.xml.bind.Unmarshaller;
13  import javax.xml.bind.annotation.*;
14  import javax.xml.transform.stream.StreamSource;
15  
16  
17  /**
18   * <p>Java class for bibs complex type.
19   * <p/>
20   * <p>The following schema fragment specifies the expected content contained within this class.
21   * <p/>
22   * <pre>
23   * &lt;complexType name="bibs">
24   *   &lt;complexContent>
25   *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
26   *       &lt;sequence>
27   *         &lt;element name="bibs" type="{}bib" maxOccurs="unbounded" minOccurs="0"/>
28   *       &lt;/sequence>
29   *     &lt;/restriction>
30   *   &lt;/complexContent>
31   * &lt;/complexType>
32   * </pre>
33   */
34  @XmlAccessorType(XmlAccessType.FIELD)
35  @XmlType(name = "bibs", propOrder = {
36          "bibs"
37  })
38  @XmlRootElement(name = "bibDocs")
39  public class Bibs {
40  
41      private static final Logger LOG = Logger.getLogger(Bibs.class);
42  
43      @XmlElement(name = "bibDoc")
44      protected List<Bib> bibs;
45  
46      public static String serialize(Object object) {
47          String result = null;
48          StringWriter sw = new StringWriter();
49          Bibs bibs = (Bibs) object;
50          try {
51              JAXBContext jaxbContext = JAXBContext.newInstance(Bibs.class);
52              Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
53              jaxbMarshaller.marshal(bibs, sw);
54              result = sw.toString();
55          } catch (Exception e) {
56              LOG.error("Exception :", e);
57          }
58          return result;
59      }
60  
61      public static Object deserialize(String bibsXml) {
62  
63          JAXBElement<Bibs> bibsElement = null;
64          try {
65              JAXBContext jaxbContext = JAXBContext.newInstance(Bibs.class);
66              Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
67              ByteArrayInputStream input = new ByteArrayInputStream(bibsXml.getBytes("UTF-8"));
68              bibsElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), Bibs.class);
69          } catch (Exception e) {
70              LOG.error("Exception :", e);
71          }
72          return bibsElement.getValue();
73      }
74  
75      /**
76       * Gets the value of the bibs property.
77       * <p/>
78       * <p/>
79       * This accessor method returns a reference to the live list,
80       * not a snapshot. Therefore any modification you make to the
81       * returned list will be present inside the JAXB object.
82       * This is why there is not a <CODE>set</CODE> method for the bibs property.
83       * <p/>
84       * <p/>
85       * For example, to add a new item, do as follows:
86       * <pre>
87       *    getBibs().add(newItem);
88       * </pre>
89       * <p/>
90       * <p/>
91       * <p/>
92       * Objects of the following type(s) are allowed in the list
93       * {@link Bib }
94       */
95      public List<Bib> getBibs() {
96          if (bibs == null) {
97              bibs = new ArrayList<Bib>();
98          }
99          return this.bibs;
100     }
101 
102 }