1 package org.kuali.ole.docstore.common.find; 2 3 import org.apache.log4j.Logger; 4 5 import java.io.ByteArrayInputStream; 6 import java.io.StringWriter; 7 import java.util.ArrayList; 8 import java.util.List; 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.*; 14 import javax.xml.transform.stream.StreamSource; 15 16 17 /** 18 * <p>Java class for findParams complex type. 19 * 20 * <p>The following schema fragment specifies the expected content contained within this class. 21 * 22 * <pre> 23 * <complexType name="findParams"> 24 * <complexContent> 25 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 26 * <sequence> 27 * <element name="map"> 28 * <complexType> 29 * <complexContent> 30 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 31 * <sequence> 32 * <element name="entry" maxOccurs="unbounded" minOccurs="0"> 33 * <complexType> 34 * <complexContent> 35 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 36 * <sequence> 37 * <element name="key" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 38 * <element name="value" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 39 * </sequence> 40 * </restriction> 41 * </complexContent> 42 * </complexType> 43 * </element> 44 * </sequence> 45 * </restriction> 46 * </complexContent> 47 * </complexType> 48 * </element> 49 * </sequence> 50 * </restriction> 51 * </complexContent> 52 * </complexType> 53 * </pre> 54 * 55 * 56 */ 57 @XmlAccessorType(XmlAccessType.FIELD) 58 @XmlType(name = "findParams", propOrder = { 59 "map" 60 }) 61 @XmlRootElement 62 public class FindParams { 63 64 private static final Logger LOG = Logger.getLogger(FindParams.class); 65 @XmlElement(required = true) 66 protected FindParams.Map map; 67 68 /** 69 * Gets the value of the map property. 70 * 71 * @return 72 * possible object is 73 * {@link FindParams.Map } 74 * 75 */ 76 public FindParams.Map getMap() { 77 return map; 78 } 79 80 /** 81 * Sets the value of the map property. 82 * 83 * @param value 84 * allowed object is 85 * {@link FindParams.Map } 86 * 87 */ 88 public void setMap(FindParams.Map value) { 89 this.map = value; 90 } 91 92 93 /** 94 * <p>Java class for anonymous complex type. 95 * 96 * <p>The following schema fragment specifies the expected content contained within this class. 97 * 98 * <pre> 99 * <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 }