001package org.kuali.ole.docstore.common.document; 002 003import org.apache.log4j.Logger; 004import org.kuali.ole.docstore.common.document.factory.JAXBContextFactory; 005 006import javax.xml.bind.Marshaller; 007import javax.xml.bind.Unmarshaller; 008import javax.xml.bind.annotation.*; 009import javax.xml.transform.stream.StreamSource; 010import java.io.ByteArrayInputStream; 011import java.io.StringWriter; 012import java.util.ArrayList; 013import java.util.List; 014 015 016/** 017 * <p>Java class for bibs complex type. 018 * <p/> 019 * <p>The following schema fragment specifies the expected content contained within this class. 020 * <p/> 021 * <pre> 022 * <complexType name="bibs"> 023 * <complexContent> 024 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 025 * <sequence> 026 * <element name="bibs" type="{}bib" maxOccurs="unbounded" minOccurs="0"/> 027 * </sequence> 028 * </restriction> 029 * </complexContent> 030 * </complexType> 031 * </pre> 032 */ 033@XmlAccessorType(XmlAccessType.FIELD) 034@XmlType(name = "bibs", propOrder = { 035 "bibs" 036}) 037@XmlRootElement(name = "bibDocs") 038public class Bibs { 039 040 private static final Logger LOG = Logger.getLogger(Bibs.class); 041 042 @XmlElement(name = "bibDoc") 043 protected List<Bib> bibs; 044 045 public static String serialize(Object object) { 046 String result = null; 047 Bibs bibs = (Bibs) object; 048 try { 049 StringWriter sw = new StringWriter(); 050 Marshaller jaxbMarshaller = JAXBContextFactory.getInstance().getMarshaller(Bibs.class); 051 synchronized (jaxbMarshaller) { 052 jaxbMarshaller.marshal(bibs, sw); 053 } 054 result = sw.toString(); 055 } catch (Exception e) { 056 LOG.error("Exception :", e); 057 } 058 return result; 059 } 060 061 public static Object deserialize(String bibsXml) { 062 Bibs bibs = new Bibs(); 063 try { 064 Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(Bibs.class); 065 ByteArrayInputStream input = new ByteArrayInputStream(bibsXml.getBytes("UTF-8")); 066 synchronized (unmarshaller) { 067 bibs = unmarshaller.unmarshal(new StreamSource(input), Bibs.class).getValue(); 068 } 069 } catch (Exception e) { 070 LOG.error("Exception :", e); 071 } 072 return bibs; 073 } 074 075 /** 076 * Gets the value of the bibs property. 077 * <p/> 078 * <p/> 079 * This accessor method returns a reference to the live list, 080 * not a snapshot. Therefore any modification you make to the 081 * returned list will be present inside the JAXB object. 082 * This is why there is not a <CODE>set</CODE> method for the bibs property. 083 * <p/> 084 * <p/> 085 * For example, to add a new item, do as follows: 086 * <pre> 087 * getBibs().add(newItem); 088 * </pre> 089 * <p/> 090 * <p/> 091 * <p/> 092 * Objects of the following type(s) are allowed in the list 093 * {@link Bib } 094 */ 095 public List<Bib> getBibs() { 096 if (bibs == null) { 097 bibs = new ArrayList<Bib>(); 098 } 099 return this.bibs; 100 } 101 102}