View Javadoc
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   * &lt;complexType name="findParams">
24   *   &lt;complexContent>
25   *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
26   *       &lt;sequence>
27   *         &lt;element name="map">
28   *           &lt;complexType>
29   *             &lt;complexContent>
30   *               &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
31   *                 &lt;sequence>
32   *                   &lt;element name="entry" maxOccurs="unbounded" minOccurs="0">
33   *                     &lt;complexType>
34   *                       &lt;complexContent>
35   *                         &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
36   *                           &lt;sequence>
37   *                             &lt;element name="key" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
38   *                             &lt;element name="value" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
39   *                           &lt;/sequence>
40   *                         &lt;/restriction>
41   *                       &lt;/complexContent>
42   *                     &lt;/complexType>
43   *                   &lt;/element>
44   *                 &lt;/sequence>
45   *               &lt;/restriction>
46   *             &lt;/complexContent>
47   *           &lt;/complexType>
48   *         &lt;/element>
49   *       &lt;/sequence>
50   *     &lt;/restriction>
51   *   &lt;/complexContent>
52   * &lt;/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       * &lt;complexType>
100      *   &lt;complexContent>
101      *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
102      *       &lt;sequence>
103      *         &lt;element name="entry" maxOccurs="unbounded" minOccurs="0">
104      *           &lt;complexType>
105      *             &lt;complexContent>
106      *               &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
107      *                 &lt;sequence>
108      *                   &lt;element name="key" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
109      *                   &lt;element name="value" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
110      *                 &lt;/sequence>
111      *               &lt;/restriction>
112      *             &lt;/complexContent>
113      *           &lt;/complexType>
114      *         &lt;/element>
115      *       &lt;/sequence>
116      *     &lt;/restriction>
117      *   &lt;/complexContent>
118      * &lt;/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          * &lt;complexType>
168          *   &lt;complexContent>
169          *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
170          *       &lt;sequence>
171          *         &lt;element name="key" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
172          *         &lt;element name="value" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
173          *       &lt;/sequence>
174          *     &lt;/restriction>
175          *   &lt;/complexContent>
176          * &lt;/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 }