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 String namespace; 38 String name; 39 String value; 40 41 public SoapPrimitive(String namespace, String name, String value) { 42 this.namespace = namespace; 43 this.name = name; 44 this.value = value; 45 } 46 47 public boolean equals(Object o) { 48 if (!(o instanceof SoapPrimitive)) { 49 return false; 50 } 51 SoapPrimitive p = (SoapPrimitive) o; 52 boolean varsEqual = name.equals(p.name) 53 && (namespace == null ? p.namespace == null : namespace.equals(p.namespace)) 54 && (value == null ? (p.value == null) : value.equals(p.value)); 55 return varsEqual && attributesAreEqual(p); 56 } 57 58 public int hashCode() { 59 return name.hashCode() ^ (namespace == null ? 0 : namespace.hashCode()); 60 } 61 62 public String toString() { 63 return value; 64 } 65 66 public String getNamespace() { 67 return namespace; 68 } 69 70 public String getName() { 71 return name; 72 } 73 } 74