View Javadoc
1   package org.kuali.ole.docstore.common.document.content.instance;
2   
3   import com.thoughtworks.xstream.annotations.XStreamAlias;
4   import com.thoughtworks.xstream.annotations.XStreamImplicit;
5   
6   import javax.xml.bind.JAXBContext;
7   import javax.xml.bind.Marshaller;
8   import javax.xml.bind.annotation.*;
9   import java.io.StringWriter;
10  import java.util.ArrayList;
11  import java.util.List;
12  
13  
14  /**
15   * Created by IntelliJ IDEA.
16   * User: Pranitha
17   * Date: 8/17/12
18   * Time: 10:47 AM
19   * To change this template use File | Settings | File Templates.
20   * <p/>
21   * <p>Java class for items complex type.
22   * <p/>
23   * <p>The following schema fragment specifies the expected content contained within this class.
24   * <p/>
25   * <pre>
26   * &lt;complexType name="items">
27   *   &lt;complexContent>
28   *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
29   *       &lt;sequence>
30   *         &lt;element name="item" type="{http://ole.kuali.org/standards/ole-instance}item" maxOccurs="unbounded"/>
31   *       &lt;/sequence>
32   *     &lt;/restriction>
33   *   &lt;/complexContent>
34   * &lt;/complexType>
35   * </pre>
36   */
37  @XmlAccessorType(XmlAccessType.FIELD)
38  @XmlType(name = "items", propOrder = {
39          "item"
40  })
41  @XStreamAlias("items")
42  @XmlRootElement(name = "items")
43  public class Items {
44  
45      @XmlElement(name = "item", required = true)
46      @XStreamImplicit(itemFieldName = "item")
47      protected List<Item> item;
48  
49      /**
50       * Gets the value of the item property.
51       * <p/>
52       * <p/>
53       * This accessor method returns a reference to the live list,
54       * not a snapshot. Therefore any modification you make to the
55       * returned list will be present inside the JAXB object.
56       * This is why there is not a <CODE>set</CODE> method for the item property.
57       * <p/>
58       * <p/>
59       * For example, to add a new item, do as follows:
60       * <pre>
61       *    getItem().add(newItem);
62       * </pre>
63       * <p/>
64       * <p/>
65       * <p/>
66       * Objects of the following type(s) are allowed in the list
67       * {@link Item }
68       */
69      public List<Item> getItem() {
70          if (item == null) {
71              item = new ArrayList<Item>();
72          }
73          return this.item;
74      }
75  
76      public void setItem(List<Item> item) {
77          this.item = item;
78      }
79  
80      public static String serialize(Object object) {
81          String result = null;
82          StringWriter sw = new StringWriter();
83          Items items = (Items) object;
84          try {
85              JAXBContext jaxbContext = JAXBContext.newInstance(Items.class);
86              Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
87              jaxbMarshaller.marshal(items, sw);
88              result = sw.toString().replace("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>","");
89          } catch (Exception e) {
90              //LOG.error("Exception ", e);
91          }
92          return result;
93      }
94  }