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  /**
17   * <p>Java class for bibs complex type.
18   * <p/>
19   * <p>The following schema fragment specifies the expected content contained within this class.
20   * <p/>
21   * <pre>
22   * &lt;complexType name="bibs">
23   *   &lt;complexContent>
24   *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
25   *       &lt;sequence>
26   *         &lt;element name="bibs" type="{}bib" maxOccurs="unbounded" minOccurs="0"/>
27   *       &lt;/sequence>
28   *     &lt;/restriction>
29   *   &lt;/complexContent>
30   * &lt;/complexType>
31   * </pre>
32   */
33  @XmlAccessorType(XmlAccessType.FIELD)
34  @XmlType(name = "bibs", propOrder = {
35          "bibs"
36  })
37  @XmlRootElement(name = "bibDocs")
38  public class Bibs {
39  
40      private static final Logger LOG = Logger.getLogger(Bibs.class);
41  
42      @XmlElement(name = "bibDoc")
43      protected List<Bib> bibs;
44  
45      public static String serialize(Object object) {
46          String result = null;
47          Bibs bibs = (Bibs) object;
48          try {
49              StringWriter sw = new StringWriter();
50              Marshaller jaxbMarshaller = JAXBContextFactory.getInstance().getMarshaller(Bibs.class);
51              synchronized (jaxbMarshaller) {
52                  jaxbMarshaller.marshal(bibs, sw);
53                 } 
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          Bibs bibs = new Bibs();
63          try {
64              Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(Bibs.class);
65              ByteArrayInputStream input = new ByteArrayInputStream(bibsXml.getBytes("UTF-8"));
66              synchronized (unmarshaller) {
67                  bibs = unmarshaller.unmarshal(new StreamSource(input), Bibs.class).getValue();
68              }
69          } catch (Exception e) {
70              LOG.error("Exception :", e);
71          }
72          return bibs;
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 }