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.factory.JAXBContextFactory;
8   import org.kuali.ole.docstore.common.exception.DocstoreDeserializeException;
9   import org.kuali.ole.docstore.common.exception.DocstoreResources;
10  
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 bib 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="bib">
29   *   &lt;complexContent>
30   *     &lt;extension base="{}docstoreDocument">
31   *       &lt;sequence>
32   *         &lt;element name="issn" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
33   *         &lt;element name="isbn" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
34   *         &lt;element name="subject" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
35   *         &lt;element name="edition" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
36   *         &lt;element name="publicationDate" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
37   *         &lt;element name="publisher" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
38   *         &lt;element name="author" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
39   *         &lt;element name="title" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
40   *       &lt;/sequence>
41   *     &lt;/extension>
42   *   &lt;/complexContent>
43   * &lt;/complexType>
44   * </pre>
45   */
46  @XmlAccessorType(XmlAccessType.FIELD)
47  @XmlType(name = "bibDoc", propOrder = {
48          "issn",
49          "isbn",
50          "subject",
51          "edition",
52          "publicationDate",
53          "publisher",
54          "author",
55          "title"
56  })
57  @XmlRootElement(name = "bibDoc")
58  public class Bib
59          extends DocstoreDocument {
60  
61      private static final Logger LOG = Logger.getLogger(Bib.class);
62      public static final String TITLE = "TITLE";
63      public static final String AUTHOR = "AUTHOR";
64      public static final String ISBN = "ISBN";
65      public static final String ISSN = "ISSN";
66      public static final String SUBJECT = "SUBJECT";
67      public static final String PUBLISHER = "PUBLISHER";
68      public static final String PUBLICATIONDATE = "PUBLICATIONDATE";
69      public static final String EDITION = "EDITION";
70      public static final String DESCRIPTION = "DESCRIPTION";
71      public static final String FORMAT = "FORMAT";
72      public static final String LANGUAGE = "LANGUAGE";
73      public static final String BIBIDENTIFIER = "BIBIDENTIFIER";
74      protected String issn;
75      protected String isbn;
76      protected String subject;
77      protected String edition;
78      protected String publicationDate;
79      protected String publisher;
80      protected String author;
81      protected String title;
82  
83      public Bib() {
84          category = DocCategory.WORK.getCode();
85          type = DocType.BIB.getCode();
86          format = DocFormat.MARC.getCode();
87      }
88  
89      /**
90       * Gets the value of the issn property.
91       *
92       * @return possible object is
93       * {@link String }
94       */
95      public String getIssn() {
96          return issn;
97      }
98  
99      /**
100      * Sets the value of the issn property.
101      *
102      * @param value allowed object is
103      *              {@link String }
104      */
105     public void setIssn(String value) {
106         this.issn = value;
107     }
108 
109     /**
110      * Gets the value of the isbn property.
111      *
112      * @return possible object is
113      * {@link String }
114      */
115     public String getIsbn() {
116         return isbn;
117     }
118 
119     /**
120      * Sets the value of the isbn property.
121      *
122      * @param value allowed object is
123      *              {@link String }
124      */
125     public void setIsbn(String value) {
126         this.isbn = value;
127     }
128 
129     /**
130      * Gets the value of the subject property.
131      *
132      * @return possible object is
133      * {@link String }
134      */
135     public String getSubject() {
136         return subject;
137     }
138 
139     /**
140      * Sets the value of the subject property.
141      *
142      * @param value allowed object is
143      *              {@link String }
144      */
145     public void setSubject(String value) {
146         this.subject = value;
147     }
148 
149     /**
150      * Gets the value of the edition property.
151      *
152      * @return possible object is
153      * {@link String }
154      */
155     public String getEdition() {
156         return edition;
157     }
158 
159     /**
160      * Sets the value of the edition property.
161      *
162      * @param value allowed object is
163      *              {@link String }
164      */
165     public void setEdition(String value) {
166         this.edition = value;
167     }
168 
169     /**
170      * Gets the value of the publicationDate property.
171      *
172      * @return possible object is
173      * {@link String }
174      */
175     public String getPublicationDate() {
176         return publicationDate;
177     }
178 
179     /**
180      * Sets the value of the publicationDate property.
181      *
182      * @param value allowed object is
183      *              {@link String }
184      */
185     public void setPublicationDate(String value) {
186         this.publicationDate = value;
187     }
188 
189     /**
190      * Gets the value of the publisher property.
191      *
192      * @return possible object is
193      * {@link String }
194      */
195     public String getPublisher() {
196         return publisher;
197     }
198 
199     /**
200      * Sets the value of the publisher property.
201      *
202      * @param value allowed object is
203      *              {@link String }
204      */
205     public void setPublisher(String value) {
206         this.publisher = value;
207     }
208 
209     /**
210      * Gets the value of the author property.
211      *
212      * @return possible object is
213      * {@link String }
214      */
215     public String getAuthor() {
216         return author;
217     }
218 
219     /**
220      * Sets the value of the author property.
221      *
222      * @param value allowed object is
223      *              {@link String }
224      */
225     public void setAuthor(String value) {
226         this.author = value;
227     }
228 
229     /**
230      * Gets the value of the title property.
231      *
232      * @return possible object is
233      * {@link String }
234      */
235     public String getTitle() {
236         return title;
237     }
238 
239     /**
240      * Sets the value of the title property.
241      *
242      * @param value allowed object is
243      *              {@link String }
244      */
245     public void setTitle(String value) {
246         this.title = value;
247     }
248 
249     @Override
250     public String serialize(Object object) {
251         String result = null;
252         Bib bib = (Bib) object;
253         try {
254             StringWriter sw = new StringWriter();
255             JAXBContextFactory jaxbContextFactory = JAXBContextFactory.getInstance();
256             Marshaller jaxbMarshaller = jaxbContextFactory.getMarshaller(Bib.class);
257             synchronized (jaxbMarshaller) {
258                 jaxbMarshaller.marshal(bib, sw);
259             }
260 
261             result = sw.toString();
262         } catch (Exception e) {
263             LOG.error("Exception :", e);
264         }
265         return result;
266     }
267 
268     @Override
269     public Object deserialize(String content) {
270         Bib bib = new Bib();
271         try {
272             Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(Bib.class);
273             ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
274             synchronized (unmarshaller) {
275                 bib = unmarshaller.unmarshal(new StreamSource(input), Bib.class).getValue();
276             }
277 
278         } catch (Exception e) {
279             LOG.error("Exception :", e);
280            throw new DocstoreDeserializeException(DocstoreResources.BIB_CREATION_FAILED,DocstoreResources.BIB_CREATION_FAILED);
281         }
282         return bib;
283     }
284 
285     @Override
286     public Object deserializeContent(Object object) {
287         Bib bib = (Bib) object;
288         BibMarcMapping bibMarcMapping = new BibMarcMapping();
289         return bibMarcMapping.getDocument(bib);
290     }
291 
292     @Override
293     public Object deserializeContent(String content) {
294         return null;  //To change body of implemented methods use File | Settings | File Templates.
295     }
296 
297     @Override
298     public String serializeContent(Object object) {
299         return null;  //To change body of implemented methods use File | Settings | File Templates.
300     }
301 }