• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The  above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  * IN THE SOFTWARE. */
20 
21 package org.ksoap2.serialization;
22 
23 /**
24  * A class that is used to encapsulate primitive types (represented by a string
25  * in XML serialization).
26  *
27  * Basically, the SoapPrimitive class encapsulates "unknown" primitive types
28  * (similar to SoapObject encapsulating unknown complex types). For example, new
29  * SoapPrimitive (classMap.xsd, "float", "12.3") allows you to send a float from
30  * a MIDP device to a server although MIDP does not support floats. In the other
31  * direction, kSOAP will deserialize any primitive type (=no subelements) that
32  * are not recognized by the ClassMap to SoapPrimitive, preserving the
33  * namespace, name and string value (this is how the stockquote example works).
34  */
35 
36 public class SoapPrimitive extends AttributeContainer {
37     protected String namespace;
38     protected String name;
39     protected Object value;
40 
41     public static final Object NullSkip = new Object();
42     public static final Object NullNilElement = new Object();
43 
SoapPrimitive(String namespace, String name, Object value)44     public SoapPrimitive(String namespace, String name, Object value) {
45         this.namespace = namespace;
46         this.name = name;
47         this.value = value;
48     }
49 
equals(Object o)50     public boolean equals(Object o) {
51         if (!(o instanceof SoapPrimitive)) {
52             return false;
53         }
54         SoapPrimitive p = (SoapPrimitive) o;
55         boolean varsEqual = name.equals(p.name)
56                 && (namespace == null ? p.namespace == null : namespace.equals(p.namespace))
57                 && (value == null ? (p.value == null) : value.equals(p.value));
58         return varsEqual && attributesAreEqual(p);
59     }
60 
hashCode()61     public int hashCode() {
62         return name.hashCode() ^ (namespace == null ? 0 : namespace.hashCode());
63     }
64 
toString()65     public String toString() {
66         return value != null ? value.toString() : null;
67     }
68 
getNamespace()69     public String getNamespace() {
70         return namespace;
71     }
72 
getName()73     public String getName() {
74         return name;
75     }
76 
getValue()77     public Object getValue() {
78         return value;
79     }
80 
81 }
82