View Javadoc
1   package org.kuali.ole.docstore.common.document;
2   
3   import org.apache.log4j.Logger;
4   import org.kuali.ole.docstore.common.util.ParseXml;
5   import org.w3c.dom.Document;
6   import org.w3c.dom.Node;
7   import org.w3c.dom.NodeList;
8   import org.xml.sax.InputSource;
9   import org.xml.sax.SAXException;
10  
11  import javax.xml.bind.JAXBContext;
12  import javax.xml.bind.Marshaller;
13  import javax.xml.bind.annotation.*;
14  import javax.xml.parsers.DocumentBuilder;
15  import javax.xml.parsers.DocumentBuilderFactory;
16  import javax.xml.parsers.ParserConfigurationException;
17  import java.io.IOException;
18  import java.io.StringReader;
19  import java.io.StringWriter;
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  
24  /**
25   * <p>Java class for bibTrees complex type.
26   * <p/>
27   * <p>The following schema fragment specifies the expected content contained within this class.
28   * <p/>
29   * <pre>
30   * &lt;complexType name="bibsTrees">
31   *   &lt;complexContent>
32   *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
33   *       &lt;sequence>
34   *         &lt;element name="bibTrees" type="{}bibTree" maxOccurs="unbounded" minOccurs="0"/>
35   *       &lt;/sequence>
36   *     &lt;/restriction>
37   *   &lt;/complexContent>
38   * &lt;/complexType>
39   * </pre>
40   */
41  @XmlAccessorType(XmlAccessType.FIELD)
42  @XmlType(name = "bibTrees", propOrder = {
43          "bibTrees"
44  })
45  @XmlRootElement(name = "bibDocsTree")
46  public class BibTrees {
47  
48      private static final Logger LOG = Logger.getLogger(BibTrees.class);
49      @XmlElement(name = "bibDocTree")
50      protected List<BibTree> bibTrees;
51  
52      public static String serialize(Object object) {
53          String result = null;
54          StringWriter sw = new StringWriter();
55          BibTrees bibsTrees = (BibTrees) object;
56          try {
57              JAXBContext jaxbContext = JAXBContext.newInstance(BibTrees.class);
58              Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
59              jaxbMarshaller.marshal(bibsTrees, sw);
60              result = sw.toString();
61          } catch (Exception e) {
62              LOG.error("Exception :", e);
63          }
64         return result;
65      }
66  
67      public static Object deserialize(String bibTreesXml) {
68  
69          BibTrees bibTrees = new BibTrees();
70          try {
71              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
72              DocumentBuilder builder = factory.newDocumentBuilder();
73              Document doc = builder.parse(new InputSource(new StringReader(bibTreesXml)));
74              NodeList root = doc.getChildNodes();
75              Node bibTreesNode = ParseXml.getNode("bibDocsTree", root);
76              BibTree bibTree = new BibTree();
77              NodeList nodeList = doc.getElementsByTagName("bibDocTree");
78              for (int i = 0; i < nodeList.getLength(); i++) {
79                  Node bibTreeNode = ParseXml.getNodeXml(bibTreesNode.getChildNodes(), i);
80                  bibTrees.getBibTrees().add((BibTree) bibTree.deserialize(ParseXml.nodeToString(bibTreeNode)));
81              }
82          } catch (SAXException e) {
83              LOG.error("Exception :", e);
84          } catch (IOException e) {
85              LOG.error("Exception :", e);
86          } catch (ParserConfigurationException e) {
87              LOG.error("Exception :", e);
88          }
89  
90  
91          return bibTrees;
92      }
93  
94      /**
95       * Gets the value of the bibTrees property.
96       * <p/>
97       * <p/>
98       * This accessor method returns a reference to the live list,
99       * not a snapshot. Therefore any modification you make to the
100      * returned list will be present inside the JAXB object.
101      * This is why there is not a <CODE>set</CODE> method for the bibTrees property.
102      * <p/>
103      * <p/>
104      * For example, to add a new item, do as follows:
105      * <pre>
106      *    getBibTrees().add(newItem);
107      * </pre>
108      * <p/>
109      * <p/>
110      * <p/>
111      * Objects of the following type(s) are allowed in the list
112      * {@link BibTree }
113      */
114     public List<BibTree> getBibTrees() {
115         if (bibTrees == null) {
116             bibTrees = new ArrayList<BibTree>();
117         }
118         return this.bibTrees;
119     }
120 
121 
122 }