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 * &lt;complexType name="findParams">
024 *   &lt;complexContent>
025 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
026 *       &lt;sequence>
027 *         &lt;element name="map">
028 *           &lt;complexType>
029 *             &lt;complexContent>
030 *               &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
031 *                 &lt;sequence>
032 *                   &lt;element name="entry" maxOccurs="unbounded" minOccurs="0">
033 *                     &lt;complexType>
034 *                       &lt;complexContent>
035 *                         &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
036 *                           &lt;sequence>
037 *                             &lt;element name="key" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
038 *                             &lt;element name="value" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
039 *                           &lt;/sequence>
040 *                         &lt;/restriction>
041 *                       &lt;/complexContent>
042 *                     &lt;/complexType>
043 *                   &lt;/element>
044 *                 &lt;/sequence>
045 *               &lt;/restriction>
046 *             &lt;/complexContent>
047 *           &lt;/complexType>
048 *         &lt;/element>
049 *       &lt;/sequence>
050 *     &lt;/restriction>
051 *   &lt;/complexContent>
052 * &lt;/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     * &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}