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              jaxbMarshaller.marshal(bibTrees, sw);
52              result = sw.toString();
53          } catch (Exception e) {
54              LOG.error("Exception :", e);
55          }
56         return result;
57      }
58  
59      public static Object deserialize(String bibTreesXml) {
60  
61          BibTrees bibTrees = new BibTrees();
62          try {
63              ByteArrayInputStream bibTreeInputStream = new ByteArrayInputStream(bibTreesXml.getBytes());
64              StreamSource streamSource = new StreamSource(bibTreeInputStream);
65              XMLStreamReader xmlStreamReader = JAXBContextFactory.getInstance().getXmlInputFactory().createXMLStreamReader(streamSource);
66  
67              Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(BibTrees.class);
68              bibTrees = unmarshaller.unmarshal(xmlStreamReader, BibTrees.class).getValue();
69          } catch (Exception e) {
70              LOG.error("Exception :", e);
71          }
72          return bibTrees;
73      }
74  
75      /**
76       * Gets the value of the bibTrees 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 bibTrees property.
83       * <p/>
84       * <p/>
85       * For example, to add a new item, do as follows:
86       * <pre>
87       *    getBibTrees().add(newItem);
88       * </pre>
89       * <p/>
90       * <p/>
91       * <p/>
92       * Objects of the following type(s) are allowed in the list
93       * {@link BibTree }
94       */
95      public List<BibTree> getBibTrees() {
96          if (bibTrees == null) {
97              bibTrees = new ArrayList<BibTree>();
98          }
99          return this.bibTrees;
100     }
101 
102 
103 }