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.stream.XMLStreamReader;
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  /**
18   * <p>Java class for bibTrees 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="bibsTrees">
24   *   &lt;complexContent>
25   *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
26   *       &lt;sequence>
27   *         &lt;element name="bibTrees" type="{}bibTree" 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 = "bibTrees", propOrder = {
36          "bibTrees"
37  })
38  @XmlRootElement(name = "bibDocsTree")
39  public class BibTrees {
40  
41      private static final Logger LOG = Logger.getLogger(BibTrees.class);
42      @XmlElement(name = "bibDocTree")
43      protected List<BibTree> bibTrees;
44  
45      public static String serialize(Object object) {
46          String result = null;
47          BibTrees bibTrees = (BibTrees) object;
48          try {
49              StringWriter sw = new StringWriter();
50              Marshaller jaxbMarshaller = JAXBContextFactory.getInstance().getMarshaller(BibTrees.class);
51              synchronized (jaxbMarshaller) {
52              jaxbMarshaller.marshal(bibTrees, 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 bibTreesXml) {
62  
63          BibTrees bibTrees = new BibTrees();
64          try {
65              ByteArrayInputStream bibTreeInputStream = new ByteArrayInputStream(bibTreesXml.getBytes());
66              StreamSource streamSource = new StreamSource(bibTreeInputStream);
67              XMLStreamReader xmlStreamReader = JAXBContextFactory.getInstance().getXmlInputFactory().createXMLStreamReader(streamSource);
68              Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(BibTrees.class);
69              synchronized (unmarshaller) {
70              bibTrees = unmarshaller.unmarshal(xmlStreamReader, BibTrees.class).getValue();
71              }
72          } catch (Exception e) {
73              LOG.error("Exception :", e);
74          }
75          return bibTrees;
76      }
77  
78      /**
79       * Gets the value of the bibTrees property.
80       * <p/>
81       * <p/>
82       * This accessor method returns a reference to the live list,
83       * not a snapshot. Therefore any modification you make to the
84       * returned list will be present inside the JAXB object.
85       * This is why there is not a <CODE>set</CODE> method for the bibTrees property.
86       * <p/>
87       * <p/>
88       * For example, to add a new item, do as follows:
89       * <pre>
90       *    getBibTrees().add(newItem);
91       * </pre>
92       * <p/>
93       * <p/>
94       * <p/>
95       * Objects of the following type(s) are allowed in the list
96       * {@link BibTree }
97       */
98      public List<BibTree> getBibTrees() {
99          if (bibTrees == null) {
100             bibTrees = new ArrayList<BibTree>();
101         }
102         return this.bibTrees;
103     }
104 
105 
106 }