001package org.kuali.ole.docstore.common.find; 002 003import org.apache.log4j.Logger; 004 005import java.io.ByteArrayInputStream; 006import java.io.StringWriter; 007import java.util.ArrayList; 008import java.util.List; 009import javax.xml.bind.JAXBContext; 010import javax.xml.bind.JAXBElement; 011import javax.xml.bind.Marshaller; 012import javax.xml.bind.Unmarshaller; 013import javax.xml.bind.annotation.*; 014import javax.xml.transform.stream.StreamSource; 015 016 017/** 018 * <p>Java class for findParams complex type. 019 * 020 * <p>The following schema fragment specifies the expected content contained within this class. 021 * 022 * <pre> 023 * <complexType name="findParams"> 024 * <complexContent> 025 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 026 * <sequence> 027 * <element name="map"> 028 * <complexType> 029 * <complexContent> 030 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 031 * <sequence> 032 * <element name="entry" maxOccurs="unbounded" minOccurs="0"> 033 * <complexType> 034 * <complexContent> 035 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 036 * <sequence> 037 * <element name="key" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 038 * <element name="value" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 039 * </sequence> 040 * </restriction> 041 * </complexContent> 042 * </complexType> 043 * </element> 044 * </sequence> 045 * </restriction> 046 * </complexContent> 047 * </complexType> 048 * </element> 049 * </sequence> 050 * </restriction> 051 * </complexContent> 052 * </complexType> 053 * </pre> 054 * 055 * 056 */ 057@XmlAccessorType(XmlAccessType.FIELD) 058@XmlType(name = "findParams", propOrder = { 059 "map" 060}) 061@XmlRootElement 062public class FindParams { 063 064 private static final Logger LOG = Logger.getLogger(FindParams.class); 065 @XmlElement(required = true) 066 protected FindParams.Map map; 067 068 /** 069 * Gets the value of the map property. 070 * 071 * @return 072 * possible object is 073 * {@link FindParams.Map } 074 * 075 */ 076 public FindParams.Map getMap() { 077 return map; 078 } 079 080 /** 081 * Sets the value of the map property. 082 * 083 * @param value 084 * allowed object is 085 * {@link FindParams.Map } 086 * 087 */ 088 public void setMap(FindParams.Map value) { 089 this.map = value; 090 } 091 092 093 /** 094 * <p>Java class for anonymous complex type. 095 * 096 * <p>The following schema fragment specifies the expected content contained within this class. 097 * 098 * <pre> 099 * <complexType> 100 * <complexContent> 101 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 102 * <sequence> 103 * <element name="entry" maxOccurs="unbounded" minOccurs="0"> 104 * <complexType> 105 * <complexContent> 106 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 107 * <sequence> 108 * <element name="key" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 109 * <element name="value" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 110 * </sequence> 111 * </restriction> 112 * </complexContent> 113 * </complexType> 114 * </element> 115 * </sequence> 116 * </restriction> 117 * </complexContent> 118 * </complexType> 119 * </pre> 120 * 121 * 122 */ 123 @XmlAccessorType(XmlAccessType.FIELD) 124 @XmlType(name = "", propOrder = { 125 "entry" 126 }) 127 public static class Map { 128 129 protected List<FindParams.Map.Entry> entry; 130 131 /** 132 * Gets the value of the entry property. 133 * 134 * <p> 135 * This accessor method returns a reference to the live list, 136 * not a snapshot. Therefore any modification you make to the 137 * returned list will be present inside the JAXB object. 138 * This is why there is not a <CODE>set</CODE> method for the entry property. 139 * 140 * <p> 141 * For example, to add a new item, do as follows: 142 * <pre> 143 * getEntry().add(newItem); 144 * </pre> 145 * 146 * 147 * <p> 148 * Objects of the following type(s) are allowed in the list 149 * {@link FindParams.Map.Entry } 150 * 151 * 152 */ 153 public List<FindParams.Map.Entry> getEntry() { 154 if (entry == null) { 155 entry = new ArrayList<FindParams.Map.Entry>(); 156 } 157 return this.entry; 158 } 159 160 161 /** 162 * <p>Java class for anonymous complex type. 163 * 164 * <p>The following schema fragment specifies the expected content contained within this class. 165 * 166 * <pre> 167 * <complexType> 168 * <complexContent> 169 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 170 * <sequence> 171 * <element name="key" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 172 * <element name="value" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 173 * </sequence> 174 * </restriction> 175 * </complexContent> 176 * </complexType> 177 * </pre> 178 * 179 * 180 */ 181 @XmlAccessorType(XmlAccessType.FIELD) 182 @XmlType(name = "", propOrder = { 183 "key", 184 "value" 185 }) 186 public static class Entry { 187 188 protected String key; 189 protected String value; 190 191 /** 192 * Gets the value of the key property. 193 * 194 * @return 195 * possible object is 196 * {@link String } 197 * 198 */ 199 public String getKey() { 200 return key; 201 } 202 203 /** 204 * Sets the value of the key property. 205 * 206 * @param value 207 * allowed object is 208 * {@link String } 209 * 210 */ 211 public void setKey(String value) { 212 this.key = value; 213 } 214 215 /** 216 * Gets the value of the value property. 217 * 218 * @return 219 * possible object is 220 * {@link String } 221 * 222 */ 223 public String getValue() { 224 return value; 225 } 226 227 /** 228 * Sets the value of the value property. 229 * 230 * @param value 231 * allowed object is 232 * {@link String } 233 * 234 */ 235 public void setValue(String value) { 236 this.value = value; 237 } 238 239 } 240 241 } 242 public String serialize(Object object) { 243 String result = null; 244 StringWriter sw = new StringWriter(); 245 FindParams findParams = (FindParams) object; 246 try { 247 JAXBContext jaxbContext = JAXBContext.newInstance(FindParams.class); 248 Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); 249 jaxbMarshaller.marshal(findParams, sw); 250 result = sw.toString(); 251 System.out.println("Result is " + result); 252 } catch (Exception e) { 253 LOG.error("Exception ", e); 254 } 255 return result; 256 } 257 258 259 public Object deserialize(String content) { 260 261 JAXBElement<FindParams> findParamsElement = null; 262 try { 263 JAXBContext jaxbContext = JAXBContext.newInstance(FindParams.class); 264 Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); 265 ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8")); 266 findParamsElement = jaxbUnmarshaller.unmarshal(new StreamSource(input),FindParams.class); 267 } catch (Exception e) { 268 LOG.error("Exception ", e); 269 } 270 return findParamsElement .getValue(); 271 } 272}