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 bibTree 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="bibTree">
24   *   &lt;complexContent>
25   *     &lt;extension base="{}docstoreDocument">
26   *       &lt;sequence>
27   *         &lt;element name="holdingsTrees" type="{}holdingsTree" maxOccurs="unbounded" minOccurs="0"/>
28   *         &lt;element name="bib" type="{}bib" minOccurs="0"/>
29   *       &lt;/sequence>
30   *     &lt;/extension>
31   *   &lt;/complexContent>
32   * &lt;/complexType>
33   * </pre>
34   */
35  @XmlAccessorType(XmlAccessType.FIELD)
36  @XmlType(name = "bibTree", propOrder = {
37          "holdingsTrees",
38          "bib"
39  })
40  
41  @XmlRootElement(name = "bibDocTree")
42  public class BibTree {
43  
44      private static final Logger LOG = Logger.getLogger(BibTree.class);
45      // XmLElementWrapper generates a wrapper element around XML representation
46      @XmlElementWrapper(name = "holdingsDocsTree")
47      // XmlElement sets the name of the entities
48      @XmlElement(name = "holdingsDocTree")
49      protected List<HoldingsTree> holdingsTrees;
50  
51      @XmlElement(name = "bibDoc")
52      protected Bib bib;
53  
54      /**
55       * Gets the value of the holdingsTrees property.
56       * <p/>
57       * <p/>
58       * This accessor method returns a reference to the live list,
59       * not a snapshot. Therefore any modification you make to the
60       * returned list will be present inside the JAXB object.
61       * This is why there is not a <CODE>set</CODE> method for the holdingsTrees property.
62       * <p/>
63       * <p/>
64       * For example, to add a new item, do as follows:
65       * <pre>
66       *    getHoldingsTrees().add(newItem);
67       * </pre>
68       * <p/>
69       * <p/>
70       * <p/>
71       * Objects of the following type(s) are allowed in the list
72       * {@link org.kuali.ole.docstore.common.document.HoldingsTree }
73       */
74      public List<HoldingsTree> getHoldingsTrees() {
75          if (holdingsTrees == null) {
76              holdingsTrees = new ArrayList<HoldingsTree>();
77          }
78          return this.holdingsTrees;
79      }
80  
81      /**
82       * Gets the value of the bib property.
83       *
84       * @return possible object is
85       *         {@link org.kuali.ole.docstore.common.document.Bib }
86       */
87      public Bib getBib() {
88          return bib;
89      }
90  
91      /**
92       * Sets the value of the bib property.
93       *
94       * @param value allowed object is
95       *              {@link org.kuali.ole.docstore.common.document.Bib }
96       */
97      public void setBib(Bib value) {
98          this.bib = value;
99      }
100 
101     public String serialize(Object object) {
102         String result = null;
103         BibTree bibTree = (BibTree) object;
104         try {
105             StringWriter sw = new StringWriter();
106             Marshaller jaxbMarshaller = JAXBContextFactory.getInstance().getMarshaller(BibTree.class);
107             jaxbMarshaller.marshal(bibTree, sw);
108             result = sw.toString();
109         } catch (Exception e) {
110             LOG.error("Exception :", e);
111         }
112         return result;
113     }
114 
115     public Object deserialize(String bibTreeXml) {
116         BibTree bibTree = new BibTree();
117         try {
118             ByteArrayInputStream bibTreeInputStream = new ByteArrayInputStream(bibTreeXml.getBytes());
119             StreamSource streamSource = new StreamSource(bibTreeInputStream);
120             XMLStreamReader xmlStreamReader = JAXBContextFactory.getInstance().getXmlInputFactory().createXMLStreamReader(streamSource);
121 
122             Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(BibTree.class);
123             bibTree = unmarshaller.unmarshal(xmlStreamReader, BibTree.class).getValue();
124         } catch (Exception e) {
125             LOG.error("Exception :", e);
126         }
127         return bibTree;
128     }
129 
130 }