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.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 items 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="items">
23   *   &lt;complexContent>
24   *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
25   *       &lt;sequence>
26   *         &lt;element name="items" type="{}item" maxOccurs="unbounded" minOccurs="0"/>
27   *       &lt;/sequence>
28   *     &lt;/restriction>
29   *   &lt;/complexContent>
30   * &lt;/complexType>
31   * </pre>
32   */
33  @XmlAccessorType(XmlAccessType.FIELD)
34  @XmlType(name = "items", propOrder = {
35          "items"
36  })
37  @XmlRootElement(name="itemsDocs")
38  public class Items {
39  
40      private static final Logger LOG = Logger.getLogger(Items.class);
41      @XmlElement(name = "itemsDoc")
42      protected List<Item> items;
43  
44  
45      public static String serialize(Object object) {
46          String result = null;
47          Items items = (Items) object;
48          try {
49              StringWriter sw = new StringWriter();
50              Marshaller jaxbMarshaller = JAXBContextFactory.getInstance().getMarshaller(Items.class);
51              synchronized (jaxbMarshaller) {
52                  jaxbMarshaller.marshal(items, sw);
53              }
54              result = sw.toString();
55          } catch (Exception e) {
56              LOG.error("Exception ", e);
57          }
58          return result;
59      }
60  
61  
62      public static Object deserialize(String content) {
63          Items items = new Items();
64          try {
65              Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(Items.class);
66              ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
67              synchronized (unmarshaller) {
68                  items = unmarshaller.unmarshal(new StreamSource(input), Items.class).getValue();
69              }
70          } catch (Exception e) {
71              LOG.error("Exception ", e);
72          }
73          return items;
74      }
75  
76  
77      /**
78       * Gets the value of the items property.
79       * <p/>
80       * <p/>
81       * This accessor method returns a reference to the live list,
82       * not a snapshot. Therefore any modification you make to the
83       * returned list will be present inside the JAXB object.
84       * This is why there is not a <CODE>set</CODE> method for the items property.
85       * <p/>
86       * <p/>
87       * For example, to add a new item, do as follows:
88       * <pre>
89       *    getItems().add(newItem);
90       * </pre>
91       * <p/>
92       * <p/>
93       * <p/>
94       * Objects of the following type(s) are allowed in the list
95       * {@link org.kuali.ole.docstore.common.document.Item }
96       */
97      public List<Item> getItems() {
98          if (items == null) {
99              items = new ArrayList<Item>();
100         }
101         return this.items;
102     }
103 
104 }