Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7473 vikram.rag 1
 
2
package com.amazonservices.mws.orders.model;
3
 
4
import java.util.ArrayList;
5
import java.util.List;
6
import javax.xml.bind.annotation.XmlAccessType;
7
import javax.xml.bind.annotation.XmlAccessorType;
8
import javax.xml.bind.annotation.XmlAnyElement;
9
import javax.xml.bind.annotation.XmlElement;
10
import javax.xml.bind.annotation.XmlRootElement;
11
import javax.xml.bind.annotation.XmlType;
12
import org.w3c.dom.Element;
13
 
14
 
15
/**
16
 * <p>Java class for anonymous complex type.
17
 * 
18
 * <p>The following schema fragment specifies the expected content contained within this class.
19
 * 
20
 * <pre>
21
 * &lt;complexType>
22
 *   &lt;complexContent>
23
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
24
 *       &lt;sequence>
25
 *         &lt;element name="Type">
26
 *           &lt;simpleType>
27
 *             &lt;restriction base="{http://www.w3.org/2001/XMLSchema}string">
28
 *               &lt;enumeration value="Receiver"/>
29
 *               &lt;enumeration value="Sender"/>
30
 *             &lt;/restriction>
31
 *           &lt;/simpleType>
32
 *         &lt;/element>
33
 *         &lt;element name="Code" type="{http://www.w3.org/2001/XMLSchema}string"/>
34
 *         &lt;element name="Message" type="{http://www.w3.org/2001/XMLSchema}string"/>
35
 *         &lt;element name="Detail">
36
 *           &lt;complexType>
37
 *             &lt;complexContent>
38
 *               &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
39
 *                 &lt;sequence>
40
 *                   &lt;any/>
41
 *                 &lt;/sequence>
42
 *               &lt;/restriction>
43
 *             &lt;/complexContent>
44
 *           &lt;/complexType>
45
 *         &lt;/element>
46
 *       &lt;/sequence>
47
 *     &lt;/restriction>
48
 *   &lt;/complexContent>
49
 * &lt;/complexType>
50
 * </pre>
51
 * 
52
 * 
53
 */
54
@XmlAccessorType(XmlAccessType.FIELD)
55
@XmlType(name = "", propOrder = {
56
    "type",
57
    "code",
58
    "message",
59
    "detail"
60
})
61
@XmlRootElement(name = "Error")
62
public class Error {
63
 
64
    @XmlElement(name = "Type", required = true)
65
    protected String type;
66
    @XmlElement(name = "Code", required = true)
67
    protected String code;
68
    @XmlElement(name = "Message", required = true)
69
    protected String message;
70
    @XmlElement(name = "Detail", required = true)
71
    protected Error.Detail detail;
72
 
73
    /**
74
     * Default constructor
75
     * 
76
     */
77
    public Error() {
78
        super();
79
    }
80
 
81
    /**
82
     * Value constructor
83
     * 
84
     */
85
    public Error(final String type, final String code, final String message, final Error.Detail detail) {
86
        this.type = type;
87
        this.code = code;
88
        this.message = message;
89
        this.detail = detail;
90
    }
91
 
92
    /**
93
     * Gets the value of the type property.
94
     * 
95
     * @return
96
     *     possible object is
97
     *     {@link String }
98
     *     
99
     */
100
    public String getType() {
101
        return type;
102
    }
103
 
104
    /**
105
     * Sets the value of the type property.
106
     * 
107
     * @param value
108
     *     allowed object is
109
     *     {@link String }
110
     *     
111
     */
112
    public void setType(String value) {
113
        this.type = value;
114
    }
115
 
116
    public boolean isSetType() {
117
        return (this.type!= null);
118
    }
119
 
120
    /**
121
     * Gets the value of the code property.
122
     * 
123
     * @return
124
     *     possible object is
125
     *     {@link String }
126
     *     
127
     */
128
    public String getCode() {
129
        return code;
130
    }
131
 
132
    /**
133
     * Sets the value of the code property.
134
     * 
135
     * @param value
136
     *     allowed object is
137
     *     {@link String }
138
     *     
139
     */
140
    public void setCode(String value) {
141
        this.code = value;
142
    }
143
 
144
    public boolean isSetCode() {
145
        return (this.code!= null);
146
    }
147
 
148
    /**
149
     * Gets the value of the message property.
150
     * 
151
     * @return
152
     *     possible object is
153
     *     {@link String }
154
     *     
155
     */
156
    public String getMessage() {
157
        return message;
158
    }
159
 
160
    /**
161
     * Sets the value of the message property.
162
     * 
163
     * @param value
164
     *     allowed object is
165
     *     {@link String }
166
     *     
167
     */
168
    public void setMessage(String value) {
169
        this.message = value;
170
    }
171
 
172
    public boolean isSetMessage() {
173
        return (this.message!= null);
174
    }
175
 
176
    /**
177
     * Gets the value of the detail property.
178
     * 
179
     * @return
180
     *     possible object is
181
     *     {@link Error.Detail }
182
     *     
183
     */
184
    public Error.Detail getDetail() {
185
        return detail;
186
    }
187
 
188
    /**
189
     * Sets the value of the detail property.
190
     * 
191
     * @param value
192
     *     allowed object is
193
     *     {@link Error.Detail }
194
     *     
195
     */
196
    public void setDetail(Error.Detail value) {
197
        this.detail = value;
198
    }
199
 
200
    public boolean isSetDetail() {
201
        return (this.detail!= null);
202
    }
203
 
204
    /**
205
     * Sets the value of the Type property.
206
     * 
207
     * @param value
208
     * @return
209
     *     this instance
210
     */
211
    public Error withType(String value) {
212
        setType(value);
213
        return this;
214
    }
215
 
216
    /**
217
     * Sets the value of the Code property.
218
     * 
219
     * @param value
220
     * @return
221
     *     this instance
222
     */
223
    public Error withCode(String value) {
224
        setCode(value);
225
        return this;
226
    }
227
 
228
    /**
229
     * Sets the value of the Message property.
230
     * 
231
     * @param value
232
     * @return
233
     *     this instance
234
     */
235
    public Error withMessage(String value) {
236
        setMessage(value);
237
        return this;
238
    }
239
 
240
    /**
241
     * Sets the value of the Detail property.
242
     * 
243
     * @param value
244
     * @return
245
     *     this instance
246
     */
247
    public Error withDetail(Error.Detail value) {
248
        setDetail(value);
249
        return this;
250
    }
251
 
252
 
253
    /**
254
     * <p>Java class for anonymous complex type.
255
     * 
256
     * <p>The following schema fragment specifies the expected content contained within this class.
257
     * 
258
     * <pre>
259
     * &lt;complexType>
260
     *   &lt;complexContent>
261
     *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
262
     *       &lt;sequence>
263
     *         &lt;any/>
264
     *       &lt;/sequence>
265
     *     &lt;/restriction>
266
     *   &lt;/complexContent>
267
     * &lt;/complexType>
268
     * </pre>
269
     * 
270
     * 
271
     */
272
    @XmlAccessorType(XmlAccessType.FIELD)
273
    @XmlType(name = "", propOrder = {
274
        "any"
275
    })
276
    public static class Detail {
277
 
278
        @XmlAnyElement(lax = true)
279
        protected List<Object> any;
280
 
281
        /**
282
         * Default constructor
283
         * 
284
         */
285
        public Detail() {
286
            super();
287
        }
288
 
289
        /**
290
         * Value constructor
291
         * 
292
         */
293
        public Detail(final List<Object> any) {
294
            this.any = any;
295
        }
296
 
297
        /**
298
         * Gets the value of the any property.
299
         * 
300
         * <p>
301
         * This accessor method returns a reference to the live list,
302
         * not a snapshot. Therefore any modification you make to the
303
         * returned list will be present inside the JAXB object.
304
         * This is why there is not a <CODE>set</CODE> method for the any property.
305
         * 
306
         * <p>
307
         * For example, to add a new item, do as follows:
308
         * <pre>
309
         *    getAny().add(newItem);
310
         * </pre>
311
         * 
312
         * 
313
         * <p>
314
         * Objects of the following type(s) are allowed in the list
315
         * {@link Element }
316
         * {@link Object }
317
         * 
318
         * 
319
         */
320
        public List<Object> getAny() {
321
            if (any == null) {
322
                any = new ArrayList<Object>();
323
            }
324
            return this.any;
325
        }
326
 
327
        public boolean isSetAny() {
328
            return ((this.any!= null)&&(!this.any.isEmpty()));
329
        }
330
 
331
        public void unsetAny() {
332
            this.any = null;
333
        }
334
 
335
        /**
336
         * Sets the value of the Any property.
337
         * 
338
         * @param values
339
         * @return
340
         *     this instance
341
         */
342
        public Error.Detail withAny(Object... values) {
343
            for (Object value: values) {
344
                getAny().add(value);
345
            }
346
            return this;
347
        }
348
 
349
        /**
350
         * Sets the value of the any property.
351
         * 
352
         * @param any
353
         *     allowed object is
354
         *     {@link Element }
355
         *     {@link Object }
356
         *     
357
         */
358
        public void setAny(List<Object> any) {
359
            this.any = any;
360
        }
361
 
362
    }
363
 
364
 
365
 
366
    /**
367
     * 
368
     * XML fragment representation of this object
369
     * 
370
     * @return XML fragment for this object. Name for outer
371
     * tag expected to be set by calling method. This fragment
372
     * returns inner properties representation only
373
     */
374
    public String toXMLFragment() {
375
        StringBuffer xml = new StringBuffer();
376
        if (isSetType()) {
377
            xml.append("<Type>");
378
            xml.append(getType() + "");
379
            xml.append("</Type>");
380
        }
381
        if (isSetCode()) {
382
            xml.append("<Code>");
383
            xml.append(escapeXML(getCode()));
384
            xml.append("</Code>");
385
        }
386
        if (isSetMessage()) {
387
            xml.append("<Message>");
388
            xml.append(escapeXML(getMessage()));
389
            xml.append("</Message>");
390
        }
391
        if (isSetDetail()) {
392
            Error.Detail  detail = getDetail();
393
            xml.append("<Detail>");
394
            xml.append(detail.toString());
395
 
396
            xml.append("</Detail>");
397
        } 
398
        return xml.toString();
399
    }
400
 
401
    /**
402
     * 
403
     * Escape XML special characters
404
     */
405
    private String escapeXML(String string) {
406
        if (string == null)
407
            return "null";
408
        StringBuffer sb = new StringBuffer();
409
        int length = string.length();
410
        for (int i = 0; i < length; ++i) {
411
            char c = string.charAt(i);
412
            switch (c) {
413
            case '&':
414
                sb.append("&amp;");
415
                break;
416
            case '<':
417
                sb.append("&lt;");
418
                break;
419
            case '>':
420
                sb.append("&gt;");
421
                break;
422
            case '\'':
423
                sb.append("&#039;");
424
                break;
425
            case '"':
426
                sb.append("&quot;");
427
                break;
428
            default:
429
                sb.append(c);
430
            }
431
        }
432
        return sb.toString();
433
    }
434
 
435
 
436
 
437
    /**
438
     *
439
     * JSON fragment representation of this object
440
     *
441
     * @return JSON fragment for this object. Name for outer
442
     * object expected to be set by calling method. This fragment
443
     * returns inner properties representation only
444
     *
445
     */
446
    protected String toJSONFragment() {
447
        StringBuffer json = new StringBuffer();
448
        boolean first = true;
449
        if (isSetType()) {
450
            if (!first) json.append(", ");
451
            json.append(quoteJSON("Type"));
452
            json.append(" : ");
453
            json.append(quoteJSON(getType() + ""));
454
            first = false;
455
        }
456
        if (isSetCode()) {
457
            if (!first) json.append(", ");
458
            json.append(quoteJSON("Code"));
459
            json.append(" : ");
460
            json.append(quoteJSON(getCode()));
461
            first = false;
462
        }
463
        if (isSetMessage()) {
464
            if (!first) json.append(", ");
465
            json.append(quoteJSON("Message"));
466
            json.append(" : ");
467
            json.append(quoteJSON(getMessage()));
468
            first = false;
469
        }
470
        if (isSetDetail()) {
471
            if (!first) json.append(", ");
472
            json.append("\"Detail\" : {");
473
            Error.Detail  detail = getDetail();
474
 
475
 
476
            json.append(detail.toString());
477
 
478
            json.append("}");
479
            first = false;
480
        }
481
        return json.toString();
482
    }
483
 
484
    /**
485
     *
486
     * Quote JSON string
487
     */
488
    private String quoteJSON(String string) {
489
        if (string == null)
490
            return "null";
491
        StringBuffer sb = new StringBuffer();
492
        sb.append("\"");
493
        int length = string.length();
494
        for (int i = 0; i < length; ++i) {
495
            char c = string.charAt(i);
496
            switch (c) {
497
            case '"':
498
                sb.append("\\\"");
499
                break;
500
            case '\\':
501
                sb.append("\\\\");
502
                break;
503
            case '/':
504
                sb.append("\\/");
505
                break;
506
            case '\b':
507
                sb.append("\\b");
508
                break;
509
            case '\f':
510
                sb.append("\\f");
511
                break;
512
            case '\n':
513
                sb.append("\\n");
514
                break;
515
            case '\r':
516
                sb.append("\\r");
517
                break;
518
            case '\t':
519
                sb.append("\\t");
520
                break;
521
            default:
522
                if (c <  ' ') {
523
                    sb.append("\\u" + String.format("%03x", Integer.valueOf(c)));
524
                } else {
525
                sb.append(c);
526
            }
527
        }
528
        }
529
        sb.append("\"");
530
        return sb.toString();
531
    }
532
 
533
 
534
}