Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7474 vikram.rag 1
 
2
package com.amazonservices.mws.products.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
    @Override
253
    public boolean equals(Object obj) {
254
        if (obj == this) {
255
            return true;
256
        } else if (!(obj instanceof Error)) {
257
            return false;
258
        }
259
        Error err = (Error) obj;
260
        return getCode().equals(err.getCode()) && getMessage().equals(err.getMessage()) && getType().equals(err.getType());
261
    }
262
 
263
    @Override
264
    public int hashCode() {
265
        StringBuilder sb = new StringBuilder();
266
        sb.append("Type: ");
267
        if (isSetType()) {
268
            sb.append(getType());
269
        }
270
        sb.append("Code: ");
271
        if (isSetCode()) {
272
            sb.append(getCode());
273
        }
274
        sb.append("Message: ");
275
        if (isSetMessage()) {
276
            sb.append(getMessage());
277
        }
278
        return sb.toString().hashCode();
279
    }
280
 
281
    @Override
282
    public String toString() {
283
        return toXMLFragment();
284
    }
285
 
286
 
287
    /**
288
     * <p>Java class for anonymous complex type.
289
     * 
290
     * <p>The following schema fragment specifies the expected content contained within this class.
291
     * 
292
     * <pre>
293
     * &lt;complexType>
294
     *   &lt;complexContent>
295
     *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
296
     *       &lt;sequence>
297
     *         &lt;any/>
298
     *       &lt;/sequence>
299
     *     &lt;/restriction>
300
     *   &lt;/complexContent>
301
     * &lt;/complexType>
302
     * </pre>
303
     * 
304
     * 
305
     */
306
    @XmlAccessorType(XmlAccessType.FIELD)
307
    @XmlType(name = "", propOrder = {
308
        "any"
309
    })
310
    public static class Detail {
311
 
312
        @XmlAnyElement(lax = true)
313
        protected List<Object> any;
314
 
315
        /**
316
         * Default constructor
317
         * 
318
         */
319
        public Detail() {
320
            super();
321
        }
322
 
323
        /**
324
         * Value constructor
325
         * 
326
         */
327
        public Detail(final List<Object> any) {
328
            this.any = any;
329
        }
330
 
331
        /**
332
         * Gets the value of the any property.
333
         * 
334
         * <p>
335
         * This accessor method returns a reference to the live list,
336
         * not a snapshot. Therefore any modification you make to the
337
         * returned list will be present inside the JAXB object.
338
         * This is why there is not a <CODE>set</CODE> method for the any property.
339
         * 
340
         * <p>
341
         * For example, to add a new item, do as follows:
342
         * <pre>
343
         *    getAny().add(newItem);
344
         * </pre>
345
         * 
346
         * 
347
         * <p>
348
         * Objects of the following type(s) are allowed in the list
349
         * {@link Object }
350
         * {@link Element }
351
         * 
352
         * 
353
         */
354
        public List<Object> getAny() {
355
            if (any == null) {
356
                any = new ArrayList<Object>();
357
            }
358
            return this.any;
359
        }
360
 
361
        public boolean isSetAny() {
362
            return ((this.any!= null)&&(!this.any.isEmpty()));
363
        }
364
 
365
        public void unsetAny() {
366
            this.any = null;
367
        }
368
 
369
        /**
370
         * Sets the value of the Any property.
371
         * 
372
         * @param values
373
         * @return
374
         *     this instance
375
         */
376
        public Error.Detail withAny(Object... values) {
377
            for (Object value: values) {
378
                getAny().add(value);
379
            }
380
            return this;
381
        }
382
 
383
        /**
384
         * Sets the value of the any property.
385
         * 
386
         * @param any
387
         *     allowed object is
388
         *     {@link Object }
389
         *     {@link Element }
390
         *     
391
         */
392
        public void setAny(List<Object> any) {
393
            this.any = any;
394
        }
395
 
396
    }
397
 
398
 
399
 
400
    /**
401
     * 
402
     * XML fragment representation of this object
403
     * 
404
     * @return XML fragment for this object. Name for outer
405
     * tag expected to be set by calling method. This fragment
406
     * returns inner properties representation only
407
     */
408
    public String toXMLFragment() {
409
        StringBuffer xml = new StringBuffer();
410
        if (isSetType()) {
411
            xml.append("<Type>");
412
            xml.append(getType() + "");
413
            xml.append("</Type>");
414
        }
415
        if (isSetCode()) {
416
            xml.append("<Code>");
417
            xml.append(escapeXML(getCode()));
418
            xml.append("</Code>");
419
        }
420
        if (isSetMessage()) {
421
            xml.append("<Message>");
422
            xml.append(escapeXML(getMessage()));
423
            xml.append("</Message>");
424
        }
425
        if (isSetDetail()) {
426
            Error.Detail  detail = getDetail();
427
            xml.append("<Detail>");
428
            xml.append(detail.toString());
429
 
430
            xml.append("</Detail>");
431
        } 
432
        return xml.toString();
433
    }
434
 
435
    /**
436
     * 
437
     * Escape XML special characters
438
     */
439
    private String escapeXML(String string) {
440
        if (string == null)
441
            return "null";
442
        StringBuffer sb = new StringBuffer();
443
        int length = string.length();
444
        for (int i = 0; i < length; ++i) {
445
            char c = string.charAt(i);
446
            switch (c) {
447
            case '&':
448
                sb.append("&amp;");
449
                break;
450
            case '<':
451
                sb.append("&lt;");
452
                break;
453
            case '>':
454
                sb.append("&gt;");
455
                break;
456
            case '\'':
457
                sb.append("&#039;");
458
                break;
459
            case '"':
460
                sb.append("&quot;");
461
                break;
462
            default:
463
                sb.append(c);
464
            }
465
        }
466
        return sb.toString();
467
    }
468
 
469
 
470
 
471
    /**
472
     *
473
     * JSON fragment representation of this object
474
     *
475
     * @return JSON fragment for this object. Name for outer
476
     * object expected to be set by calling method. This fragment
477
     * returns inner properties representation only
478
     *
479
     */
480
    protected String toJSONFragment() {
481
        StringBuffer json = new StringBuffer();
482
        boolean first = true;
483
        if (isSetType()) {
484
            if (!first) json.append(", ");
485
            json.append(quoteJSON("Type"));
486
            json.append(" : ");
487
            json.append(quoteJSON(getType() + ""));
488
            first = false;
489
        }
490
        if (isSetCode()) {
491
            if (!first) json.append(", ");
492
            json.append(quoteJSON("Code"));
493
            json.append(" : ");
494
            json.append(quoteJSON(getCode()));
495
            first = false;
496
        }
497
        if (isSetMessage()) {
498
            if (!first) json.append(", ");
499
            json.append(quoteJSON("Message"));
500
            json.append(" : ");
501
            json.append(quoteJSON(getMessage()));
502
            first = false;
503
        }
504
        if (isSetDetail()) {
505
            if (!first) json.append(", ");
506
            json.append("\"Detail\" : {");
507
            Error.Detail  detail = getDetail();
508
 
509
 
510
            json.append(detail.toString());
511
 
512
            json.append("}");
513
            first = false;
514
        }
515
        return json.toString();
516
    }
517
 
518
    /**
519
     *
520
     * Quote JSON string
521
     */
522
    private String quoteJSON(String string) {
523
        if (string == null)
524
            return "null";
525
        StringBuffer sb = new StringBuffer();
526
        sb.append("\"");
527
        int length = string.length();
528
        for (int i = 0; i < length; ++i) {
529
            char c = string.charAt(i);
530
            switch (c) {
531
            case '"':
532
                sb.append("\\\"");
533
                break;
534
            case '\\':
535
                sb.append("\\\\");
536
                break;
537
            case '/':
538
                sb.append("\\/");
539
                break;
540
            case '\b':
541
                sb.append("\\b");
542
                break;
543
            case '\f':
544
                sb.append("\\f");
545
                break;
546
            case '\n':
547
                sb.append("\\n");
548
                break;
549
            case '\r':
550
                sb.append("\\r");
551
                break;
552
            case '\t':
553
                sb.append("\\t");
554
                break;
555
            default:
556
                if (c <  ' ') {
557
                    sb.append("\\u" + String.format("%03x", Integer.valueOf(c)));
558
                } else {
559
                sb.append(c);
560
            }
561
        }
562
        }
563
        sb.append("\"");
564
        return sb.toString();
565
    }
566
 
567
 
568
}