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