KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > rpc > IF3SOAPProxy


1
2 package test.rpc;
3
4 import org.apache.axis.client.Call;
5 import org.apache.axis.client.Service;
6 import org.apache.axis.encoding.ser.BeanDeserializerFactory;
7 import org.apache.axis.encoding.ser.BeanSerializerFactory;
8 import org.apache.axis.Constants;
9
10 import javax.xml.namespace.QName JavaDoc;
11 import javax.xml.rpc.ParameterMode JavaDoc;
12 import java.util.Calendar JavaDoc;
13
14 public final class IF3SOAPProxy implements IF3SOAP
15 {
16     private String JavaDoc m_service;
17     private String JavaDoc m_url;
18     private QName JavaDoc m_beanQName;
19     private QName JavaDoc m_arrayQName;
20
21     public IF3SOAPProxy(String JavaDoc service, String JavaDoc url)
22     {
23         m_service = service;
24         m_url = url;
25         m_beanQName = new QName JavaDoc("urn:" + m_service, "Bean");
26         m_arrayQName = Constants.SOAP_ARRAY;
27     }
28
29     public IF1 getBeanById(String JavaDoc id)
30         throws Exception JavaDoc
31     {
32         IF1 bean = null;
33
34         if (id == null)
35             throw new Exception JavaDoc("invalid id");
36
37             Call call = getCall();
38             call.setTargetEndpointAddress(m_url);
39             call.setOperationName(new QName JavaDoc(m_service, "getBeanById"));
40             call.addParameter("id", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);
41             call.setReturnType(m_beanQName);
42             bean = (IF1) call.invoke(new Object JavaDoc[] { id });
43
44         return bean;
45     }
46
47     public IF1[] getAllBeans()
48         throws Exception JavaDoc
49     {
50         return getAllBeans(null);
51     }
52
53     public IF1[] getAllBeans(String JavaDoc[] filter)
54         throws Exception JavaDoc
55     {
56         IF1[] beans = null;
57
58             Call call = getCall();
59             call.setTargetEndpointAddress(m_url);
60             call.setOperationName(new QName JavaDoc(m_service, "getAllBeans"));
61             call.setReturnType(m_arrayQName);
62             if (filter == null)
63                 beans = (IF1[]) call.invoke(new Object JavaDoc[0]);
64             else
65             {
66                 call.addParameter("filter", m_arrayQName, ParameterMode.IN);
67                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { filter });
68             }
69
70         return beans;
71     }
72
73     public String JavaDoc[] getAllCategories()
74         throws Exception JavaDoc
75     {
76         String JavaDoc[] categories = null;
77
78             Call call = getCall();
79             call.setTargetEndpointAddress(m_url);
80             call.setOperationName(new QName JavaDoc(m_service, "getAllCategories"));
81             call.setReturnType(m_arrayQName);
82             categories = (String JavaDoc[]) call.invoke(new Object JavaDoc[0]);
83
84         return categories;
85     }
86
87     public IF1[] getBeansByCategory(String JavaDoc category)
88         throws Exception JavaDoc
89     {
90         return getBeansByCategory(category, (String JavaDoc[]) null);
91     }
92
93     public IF1[] getBeansByCategory(String JavaDoc category, String JavaDoc[] filter)
94         throws Exception JavaDoc
95     {
96         IF1[] beans = null;
97
98         if (category == null)
99             throw new Exception JavaDoc("invalid category");
100
101             Call call = getCall();
102             call.setTargetEndpointAddress(m_url);
103             call.setOperationName(new QName JavaDoc(m_service, "getBeansByCategory"));
104             call.setReturnType(m_arrayQName);
105             call.addParameter("category", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);
106             if (filter == null)
107                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { category });
108             else
109             {
110                 call.addParameter("filter", m_arrayQName, ParameterMode.IN);
111                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { category, filter });
112             }
113
114         return beans;
115     }
116
117     public IF1[] getBeansByDate(Calendar JavaDoc[] dates)
118         throws Exception JavaDoc
119     {
120         return getBeansByDate(dates, null);
121     }
122
123     public IF1[] getBeansByDate(Calendar JavaDoc[] dates, String JavaDoc[] filter)
124         throws Exception JavaDoc
125     {
126         IF1[] beans = null;
127
128         if (dates == null)
129             throw new Exception JavaDoc("invalid dates");
130
131             Call call = getCall();
132             call.setTargetEndpointAddress(m_url);
133             call.setOperationName(new QName JavaDoc(m_service, "getBeansByDate"));
134             call.setReturnType(m_arrayQName);
135             call.addParameter("dates", m_arrayQName, ParameterMode.IN);
136             if (filter == null)
137                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { dates });
138             else
139             {
140                 call.addParameter("filter", m_arrayQName, ParameterMode.IN);
141                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { dates, filter });
142             }
143
144         return beans;
145     }
146
147     public IF1[] getBeansByExpression(int expType, String JavaDoc expression)
148         throws Exception JavaDoc
149     {
150         return getBeansByExpression(expType, expression, null);
151     }
152
153     public IF1[] getBeansByExpression(int expType, String JavaDoc expression, String JavaDoc[] filter)
154         throws Exception JavaDoc
155     {
156         IF1[] beans = null;
157
158         if (expression == null)
159             throw new Exception JavaDoc("invalid expression");
160
161             Call call = getCall();
162             call.setTargetEndpointAddress(m_url);
163             call.setOperationName(new QName JavaDoc(m_service, "getBeansByExpression"));
164             call.setReturnType(m_arrayQName);
165             call.addParameter("expType", org.apache.axis.Constants.XSD_INT, ParameterMode.IN);
166             call.addParameter("expression", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);
167             if (filter == null)
168                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { new Integer JavaDoc(expType), expression });
169             else
170             {
171                 call.addParameter("filter", m_arrayQName, ParameterMode.IN);
172                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { new Integer JavaDoc(expType), expression, filter });
173             }
174
175         return beans;
176     }
177
178     public String JavaDoc getXMLForBean(IF1 bean)
179         throws Exception JavaDoc
180     {
181         String JavaDoc xml = null;
182
183         if (bean == null)
184             throw new Exception JavaDoc("invalid bean");
185
186             Call call = getCall();
187             call.setTargetEndpointAddress(m_url);
188             call.setOperationName(new QName JavaDoc(m_service, "getXMLForBean"));
189             call.addParameter("bean", m_beanQName, ParameterMode.IN);
190             call.setReturnType(org.apache.axis.Constants.XSD_STRING);
191             xml = (String JavaDoc) call.invoke(new Object JavaDoc[] { bean });
192
193         return xml;
194     }
195
196     public IF1[] getBeansByCategory(String JavaDoc ifId, String JavaDoc category)
197         throws Exception JavaDoc
198     {
199         return getBeansByCategory(ifId, category, null);
200     }
201
202     public IF1[] getBeansByCategory(String JavaDoc ifId, String JavaDoc category, String JavaDoc[] filter)
203         throws Exception JavaDoc
204     {
205         IF1[] beans = null;
206
207         if (ifId == null)
208             throw new Exception JavaDoc("invalid ifId");
209         if (category == null)
210             throw new Exception JavaDoc("invalid category");
211
212             Call call = getCall();
213             call.setTargetEndpointAddress(m_url);
214             call.setOperationName(new QName JavaDoc(m_service, "getBeansByCategory"));
215             call.setReturnType(m_arrayQName);
216             call.addParameter("ifId", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);
217             call.addParameter("category", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);
218             if (filter == null)
219                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { ifId, category });
220             else
221             {
222                 call.addParameter("filter", m_arrayQName, ParameterMode.IN);
223                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { ifId, category, filter });
224             }
225
226         return beans;
227     }
228
229     public IF1[] getBeansByDate(String JavaDoc ifId, Calendar JavaDoc[] dates)
230         throws Exception JavaDoc
231     {
232         return getBeansByDate(ifId, dates, null);
233     }
234
235     public IF1[] getBeansByDate(String JavaDoc ifId, Calendar JavaDoc[] dates, String JavaDoc[] filter)
236         throws Exception JavaDoc
237     {
238         IF1[] beans = null;
239
240         if (ifId == null)
241             throw new Exception JavaDoc("invalid ifId");
242         if (dates == null)
243             throw new Exception JavaDoc("invalid dates");
244
245             Call call = getCall();
246             call.setTargetEndpointAddress(m_url);
247             call.setOperationName(new QName JavaDoc(m_service, "getBeansByDate"));
248             call.setReturnType(m_arrayQName);
249             call.addParameter("ifId", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);
250             call.addParameter("dates", m_arrayQName, ParameterMode.IN);
251             if (filter == null)
252                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { ifId, dates });
253             else
254             {
255                 call.addParameter("filter", m_arrayQName, ParameterMode.IN);
256                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { ifId, dates, filter });
257             }
258
259         return beans;
260     }
261
262     public IF1[] getBeansByExpression(String JavaDoc ifId, int expType, String JavaDoc expression)
263         throws Exception JavaDoc
264     {
265         return getBeansByExpression(ifId, expType, expression, null);
266     }
267
268     public IF1[] getBeansByExpression(String JavaDoc ifId, int expType, String JavaDoc expression, String JavaDoc[] filter)
269         throws Exception JavaDoc
270     {
271         IF1[] beans = null;
272
273         if (ifId == null)
274             throw new Exception JavaDoc("invalid ifId");
275         if (expression == null)
276             throw new Exception JavaDoc("invalid expression");
277
278             Call call = getCall();
279             call.setTargetEndpointAddress(m_url);
280             call.setOperationName(new QName JavaDoc(m_service, "getBeansByExpression"));
281             call.setReturnType(m_arrayQName);
282             call.addParameter("ifId", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);
283             call.addParameter("expType", org.apache.axis.Constants.XSD_INT, ParameterMode.IN);
284             call.addParameter("expression", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);
285             if (filter == null)
286                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { ifId, new Integer JavaDoc(expType), expression });
287             else
288             {
289                 call.addParameter("filter", m_arrayQName, ParameterMode.IN);
290                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { ifId, new Integer JavaDoc(expType), expression, filter });
291             }
292
293         return beans;
294     }
295
296     private Call getCall()
297         throws Exception JavaDoc
298     {
299         Call call = null;
300             Service service = new Service();
301             call = (Call) service.createCall();
302
303             call.registerTypeMapping(Bean.class, m_beanQName,
304                 new BeanSerializerFactory(Bean.class, m_beanQName),
305                 new BeanDeserializerFactory(Bean.class, m_beanQName));
306         return call;
307     }
308 }
309
310
Popular Tags