KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > scalagent > ksoap > SoapObject


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2003 - ScalAgent Distributed Technologies
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * The present code contributor is ScalAgent Distributed Technologies.
21  *
22  * Initial developer(s): Nicolas Tachker (ScalAgent)
23  * Contributor(s):
24  */

25 package com.scalagent.ksoap;
26
27 import java.util.Vector JavaDoc;
28
29 public class SoapObject {
30   String JavaDoc namespace;
31   String JavaDoc name;
32   Vector JavaDoc info = new Vector JavaDoc ();
33   Vector JavaDoc data = new Vector JavaDoc ();
34
35   public SoapObject(String JavaDoc namespace, String JavaDoc name) {
36     this.namespace = namespace;
37     this.name = name;
38   }
39
40   public boolean equals(Object JavaDoc 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 JavaDoc e) {
55       return false;
56     }
57     return true;
58   }
59   
60   public String JavaDoc getName() {
61     return name;
62   }
63   
64   public String JavaDoc getNamespace() {
65     return namespace;
66   }
67
68   public Object JavaDoc getProperty(int index) {
69     return data.elementAt(index);
70   }
71
72   public Object JavaDoc getProperty(String JavaDoc 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 JavaDoc ("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 JavaDoc value) {
98     data.setSize(index+1);
99     data.setElementAt(value,index);
100   }
101     
102   public SoapObject addProperty(String JavaDoc name, Object JavaDoc value) {
103     PropertyInfo prop = new PropertyInfo(name,new Object JavaDoc().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 JavaDoc 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 JavaDoc toString() {
119     return "SoapObject (" + namespace +
120       "," + name +
121       "," + info +
122       "," + data +")";
123   }
124 }
125
Popular Tags