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             synchronized (jaxbMarshaller) {
108                 jaxbMarshaller.marshal(bibTree, sw);
109             }
110             result = sw.toString();
111         } catch (Exception e) {
112             LOG.error("Exception :", e);
113         }
114         return result;
115     }
116 
117     public Object deserialize(String bibTreeXml) {
118         BibTree bibTree = new BibTree();
119         try {
120             ByteArrayInputStream bibTreeInputStream = new ByteArrayInputStream(bibTreeXml.getBytes());
121             StreamSource streamSource = new StreamSource(bibTreeInputStream);
122             XMLStreamReader xmlStreamReader = JAXBContextFactory.getInstance().getXmlInputFactory().createXMLStreamReader(streamSource);
123             Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(BibTree.class);
124             synchronized (unmarshaller) {
125                 bibTree = unmarshaller.unmarshal(xmlStreamReader, BibTree.class).getValue();
126             }
127         } catch (Exception e) {
128             LOG.error("Exception :", e);
129         }
130         return bibTree;
131     }
132 
133 }