1 25 package com.scalagent.ksoap; 26 27 import java.util.Vector ; 28 29 public class SoapObject { 30 String namespace; 31 String name; 32 Vector info = new Vector (); 33 Vector data = new Vector (); 34 35 public SoapObject(String namespace, String name) { 36 this.namespace = namespace; 37 this.name = name; 38 } 39 40 public boolean equals(Object o) { 41 if (!(o instanceof SoapObject)) 42 return false; 43 44 SoapObject so = (SoapObject) o; 45 int cnt = data.size(); 46 if (cnt != so.data.size()) 47 return false; 48 49 try { 50 for (int i = 0; i < cnt; i++) 51 if (!data.elementAt(i).equals( 52 so.getProperty(((PropertyInfo) info.elementAt(i)).name))) 53 return false; 54 } catch (Exception e) { 55 return false; 56 } 57 return true; 58 } 59 60 public String getName() { 61 return name; 62 } 63 64 public String getNamespace() { 65 return namespace; 66 } 67 68 public Object getProperty(int index) { 69 return data.elementAt(index); 70 } 71 72 public Object getProperty(String name) { 73 for (int i = 0; i < data.size(); i++) { 74 if (name.equals(((PropertyInfo) info.elementAt(i)).name)) 75 return data.elementAt(i); 76 } 77 throw new RuntimeException ("illegal property: "+name); 78 } 79 80 public int getPropertyCount() { 81 return data.size(); 82 } 83 84 public PropertyInfo getPropertyInfo(int index) { 85 return (PropertyInfo) info.elementAt(index); 86 } 87 88 public SoapObject newInstance() { 89 SoapObject o = new SoapObject(namespace,name); 90 for (int i = 0; i < data.size(); i++) { 91 PropertyInfo p = (PropertyInfo) info.elementAt(i); 92 o.addProperty(p.name,data.elementAt(i)); 93 } 94 return o; 95 } 96 97 public void setProperty(int index, Object value) { 98 data.setSize(index+1); 99 data.setElementAt(value,index); 100 } 101 102 public SoapObject addProperty(String name, Object value) { 103 PropertyInfo prop = new PropertyInfo(name,new Object ().getClass()); 104 if (value != null) 105 prop = new PropertyInfo(name,value.getClass()); 106 return addProperty(prop,value); 107 } 108 109 public SoapObject addProperty(PropertyInfo p, Object value) { 110 if (KSoapTracing.dbg) 111 KSoapTracing.log(KSoapTracing.DEBUG, 112 "SoapObject.addProperty(" + p + "," + value + ")"); 113 info.addElement(p); 114 data.addElement(value); 115 return this; 116 } 117 118 public String toString() { 119 return "SoapObject (" + namespace + 120 "," + name + 121 "," + info + 122 "," + data +")"; 123 } 124 } 125 | Popular Tags |