001package org.kuali.ole.docstore.common.document; 002 003import org.apache.log4j.Logger; 004 005import javax.xml.bind.JAXBContext; 006import javax.xml.bind.JAXBElement; 007import javax.xml.bind.Marshaller; 008import javax.xml.bind.Unmarshaller; 009import javax.xml.bind.annotation.*; 010import javax.xml.transform.stream.StreamSource; 011import java.io.ByteArrayInputStream; 012import java.io.StringWriter; 013import java.util.ArrayList; 014import java.util.List; 015 016/** 017 * Created with IntelliJ IDEA. 018 * User: rajeshbabuk 019 * Date: 7/4/14 020 * Time: 3:47 PM 021 * To change this template use File | Settings | File Templates. 022 */ 023 024@XmlAccessorType(XmlAccessType.FIELD) 025@XmlType(name = "holdingsDocs", propOrder = { 026 "holdingsDocs" 027}) 028@XmlRootElement(name="holdingsDocs") 029public class HoldingsDocs { 030 031 private static final Logger LOG = Logger.getLogger(Items.class); 032 @XmlElement(name = "holdingsDoc") 033 protected List<Holdings> holdingsDocs; 034 035 public static String serialize(Object object) { 036 String result = null; 037 StringWriter sw = new StringWriter(); 038 HoldingsDocs holdingsDocs = (HoldingsDocs) object; 039 try { 040 JAXBContext jaxbContext = JAXBContext.newInstance(HoldingsDocs.class); 041 Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); 042 jaxbMarshaller.marshal(holdingsDocs, sw); 043 result = sw.toString(); 044 } catch (Exception e) { 045 LOG.error("Exception :", e); 046 } 047 return result; 048 } 049 050 public static Object deserialize(String holdingsDocsXml) { 051 052 JAXBElement<HoldingsDocs> holdingsDocsElement = null; 053 try { 054 JAXBContext jaxbContext = JAXBContext.newInstance(HoldingsDocs.class); 055 Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); 056 ByteArrayInputStream input = new ByteArrayInputStream(holdingsDocsXml.getBytes("UTF-8")); 057 holdingsDocsElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), HoldingsDocs.class); 058 } catch (Exception e) { 059 LOG.error("Exception :", e); 060 } 061 return holdingsDocsElement.getValue(); 062 } 063 064 /** 065 * Gets the value of the holdingsDocs property. 066 * <p/> 067 * <p/> 068 * This accessor method returns a reference to the live list, 069 * not a snapshot. Therefore any modification you make to the 070 * returned list will be present inside the JAXB object. 071 * This is why there is not a <CODE>set</CODE> method for the holdingsDocs property. 072 * <p/> 073 * <p/> 074 * For example, to add a new holdings, do as follows: 075 * <pre> 076 * getHoldingsDocs().add(newHoldings); 077 * </pre> 078 * <p/> 079 * <p/> 080 * <p/> 081 * Objects of the following type(s) are allowed in the list 082 * {@link Bib } 083 */ 084 public List<Holdings> getHoldingsDocs() { 085 if (holdingsDocs == null) { 086 holdingsDocs = new ArrayList<Holdings>(); 087 } 088 return this.holdingsDocs; 089 } 090}