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.*;
7   import javax.xml.bind.annotation.*;
8   import javax.xml.stream.XMLStreamReader;
9   import javax.xml.transform.stream.StreamSource;
10  import java.io.ByteArrayInputStream;
11  import java.io.StringWriter;
12  import java.util.ArrayList;
13  import java.util.List;
14  
15  
16  /**
17   * <p>Java class for holdingsTree complex type.
18   * <p/>
19   * <p>The following schema fragment specifies the expected content contained within this class.
20   * <p/>
21   * <pre>
22   * &lt;complexType name="holdingsTree">
23   *   &lt;complexContent>
24   *     &lt;extension base="{}docstoreDocument">
25   *       &lt;sequence>
26   *         &lt;element name="items" type="{}item" maxOccurs="unbounded" minOccurs="0"/>
27   *         &lt;element name="holdings" type="{}holdings" minOccurs="0"/>
28   *       &lt;/sequence>
29   *     &lt;/extension>
30   *   &lt;/complexContent>
31   * &lt;/complexType>
32   * </pre>
33   */
34  @XmlAccessorType(XmlAccessType.FIELD)
35  @XmlType(name = "holdingsTree", propOrder = {
36          "items",
37          "holdings"
38  })
39  
40  @XmlRootElement(name = "holdingsDocTree")
41  public class HoldingsTree
42          implements Comparable<HoldingsTree> {
43  
44      private static final Logger LOG = Logger.getLogger(HoldingsTree.class);
45      @XmlElementWrapper(name = "itemsDocs")
46      @XmlElement(name = "itemsDoc")
47      protected List<Item> items;
48      @XmlElement(name = "holdingsDoc")
49      protected Holdings holdings;
50  
51      /**
52       * Gets the value of the items property.
53       * <p/>
54       * <p/>
55       * This accessor method returns a reference to the live list,
56       * not a snapshot. Therefore any modification you make to the
57       * returned list will be present inside the JAXB object.
58       * This is why there is not a <CODE>set</CODE> method for the items property.
59       * <p/>
60       * <p/>
61       * For example, to add a new item, do as follows:
62       * <pre>
63       *    getItems().add(newItem);
64       * </pre>
65       * <p/>
66       * <p/>
67       * <p/>
68       * Objects of the following type(s) are allowed in the list
69       * {@link org.kuali.ole.docstore.common.document.Item }
70       */
71      public List<Item> getItems() {
72          if (items == null) {
73              items = new ArrayList<Item>();
74          }
75          return this.items;
76      }
77  
78      /**
79       * Gets the value of the holdings property.
80       *
81       * @return possible object is
82       *         {@link org.kuali.ole.docstore.common.document.Holdings }
83       */
84      public Holdings getHoldings() {
85          return holdings;
86      }
87  
88      /**
89       * Sets the value of the holdings property.
90       *
91       * @param value allowed object is
92       *              {@link org.kuali.ole.docstore.common.document.Holdings }
93       */
94      public void setHoldings(Holdings value) {
95          this.holdings = value;
96      }
97  
98      public String serialize(Object object) {
99          String result = null;
100         HoldingsTree holdingsTree = (HoldingsTree) object;
101         try {
102             StringWriter sw = new StringWriter();
103             Marshaller jaxbMarshaller = JAXBContext.newInstance(HoldingsTree.class).createMarshaller();
104             jaxbMarshaller.marshal(holdingsTree, sw);
105             result = sw.toString();
106         } catch (Exception e) {
107             LOG.error("Exception ", e);
108         }
109         return result;
110     }
111 
112     public Object deserialize(String holdingsTreeXml) {
113         HoldingsTree holdingsTree = new HoldingsTree();
114         try {
115             ByteArrayInputStream bibTreeInputStream = new ByteArrayInputStream(holdingsTreeXml.getBytes());
116             StreamSource streamSource = new StreamSource(bibTreeInputStream);
117             XMLStreamReader xmlStreamReader = JAXBContextFactory.getInstance().getXmlInputFactory().createXMLStreamReader(streamSource);
118 
119             Unmarshaller unmarshaller = JAXBContext.newInstance(HoldingsTree.class).createUnmarshaller();
120             holdingsTree = unmarshaller.unmarshal(xmlStreamReader, HoldingsTree.class).getValue();
121         } catch (Exception e) {
122             LOG.error("Exception ", e);
123         }
124         return holdingsTree;
125     }
126 
127     public Object deserializeContent(Object object) {
128         return null;  //To change body of implemented methods use File | Settings | File Templates.
129     }
130 
131     @Override
132     public int compareTo(HoldingsTree o) {
133         return this.getHoldings().compareTo(o.getHoldings());
134     }
135 }