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.content.enums.DocCategory;
5   import org.kuali.ole.docstore.common.document.content.enums.DocFormat;
6   import org.kuali.ole.docstore.common.document.content.enums.DocType;
7   import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
8   import org.kuali.ole.docstore.common.document.factory.JAXBContextFactory;
9   
10  import javax.xml.bind.Marshaller;
11  import javax.xml.bind.Unmarshaller;
12  import javax.xml.bind.annotation.XmlAccessType;
13  import javax.xml.bind.annotation.XmlAccessorType;
14  import javax.xml.bind.annotation.XmlRootElement;
15  import javax.xml.bind.annotation.XmlType;
16  import javax.xml.transform.stream.StreamSource;
17  import java.io.ByteArrayInputStream;
18  import java.io.StringWriter;
19  
20  
21  /**
22   * <p>Java class for itemOleml complex type.
23   * <p/>
24   * <p>The following schema fragment specifies the expected content contained within this class.
25   * <p/>
26   * <pre>
27   * &lt;complexType name="itemOleml">
28   *   &lt;complexContent>
29   *     &lt;extension base="{}item">
30   *       &lt;sequence>
31   *       &lt;/sequence>
32   *     &lt;/extension>
33   *   &lt;/complexContent>
34   * &lt;/complexType>
35   * </pre>
36   */
37  @XmlAccessorType(XmlAccessType.FIELD)
38  @XmlType(name = "itemOleml")
39  
40  @XmlRootElement(name = "itemDoc")
41  public class ItemOleml
42          extends Item {
43      private static final Logger LOG = Logger.getLogger(ItemOleml.class);
44      public ItemOleml() {
45          category=DocCategory.WORK.getCode();
46          type=DocType.ITEM.getCode();
47          format=DocFormat.OLEML.getCode();
48      }
49      @Override
50      public String serialize(Object object) {
51          String result = null;
52          ItemOleml item = (ItemOleml) object;
53          try {
54              StringWriter sw = new StringWriter();
55              Marshaller jaxbMarshaller = JAXBContextFactory.getInstance().getMarshaller(ItemOleml.class);
56              synchronized (jaxbMarshaller) {
57                  jaxbMarshaller.marshal(item, sw);
58              }
59              result = sw.toString();
60          } catch (Exception e) {
61              LOG.error("Exception ", e);
62          }
63          return result;
64      }
65  
66      @Override
67      public Object deserialize(String content) {
68          ItemOleml item = new ItemOleml();
69          try {
70              Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(ItemOleml.class);
71              ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
72              synchronized (unmarshaller) {
73                  item = unmarshaller.unmarshal(new StreamSource(input), ItemOleml.class).getValue();
74              }
75          } catch (Exception e) {
76              LOG.error("Exception ", e);
77          }
78          return item;
79      }
80  
81      @Override
82      public Object deserializeContent(Object object) {
83          return null;  //To change body of implemented methods use File | Settings | File Templates.
84      }
85  
86      @Override
87      public Object deserializeContent(String content) {
88          ItemOlemlRecordProcessor recordProcessor = new ItemOlemlRecordProcessor();
89          org.kuali.ole.docstore.common.document.content.instance.Item item = recordProcessor.fromXML(content);
90          return item;
91      }
92  
93      @Override
94      public String serializeContent(Object object) {
95          org.kuali.ole.docstore.common.document.content.instance.Item item = (org.kuali.ole.docstore.common.document.content.instance.Item) object;
96          ItemOlemlRecordProcessor recordProcessor = new ItemOlemlRecordProcessor();
97          String content = recordProcessor.toXML(item);
98          return content;
99      }
100 }