KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > rpc > IF2SOAPProxy


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
9 import javax.xml.namespace.QName JavaDoc;
10 import javax.xml.rpc.ParameterMode JavaDoc;
11 import java.util.Calendar JavaDoc;
12
13 public final class IF2SOAPProxy implements IF2SOAP
14 {
15     private String JavaDoc m_service;
16     private String JavaDoc m_url;
17     private QName JavaDoc m_beanQName;
18     private QName JavaDoc m_beanArrayQName;
19     private QName JavaDoc m_stringArrayQName;
20     private QName JavaDoc m_calendarArrayQName;
21
22     public IF2SOAPProxy(String JavaDoc service, String JavaDoc url)
23     {
24         m_service = service;
25         m_url = url;
26         m_beanQName = new QName JavaDoc("urn:" + m_service, "Bean");
27         m_beanArrayQName = new QName JavaDoc("urn:" + m_service, "Bean[]");
28         m_stringArrayQName = new QName JavaDoc("urn:" + m_service, "String[]");
29         m_calendarArrayQName = new QName JavaDoc("urn:" + m_service, "Calendar[]");
30     }
31
32     public IF1 getBeanById(String JavaDoc id)
33         throws Exception JavaDoc
34     {
35         IF1 bean = null;
36
37         if (id == null)
38             throw new Exception JavaDoc("invalid id");
39
40             Call call = getCall();
41             call.setTargetEndpointAddress(m_url);
42             call.setOperationName(new QName JavaDoc(m_service, "getBeanById"));
43             call.addParameter("id", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);
44             call.setReturnType(m_beanQName);
45             bean = (IF1) call.invoke(new Object JavaDoc[] { id });
46
47         return bean;
48     }
49
50     public IF1[] getAllBeans()
51         throws Exception JavaDoc
52     {
53         return getAllBeans(null);
54     }
55
56     public IF1[] getAllBeans(String JavaDoc[] filter)
57         throws Exception JavaDoc
58     {
59         IF1[] beans = null;
60
61             Call call = getCall();
62             call.setTargetEndpointAddress(m_url);
63             call.setOperationName(new QName JavaDoc(m_service, "getAllBeans"));
64             call.setReturnType(m_beanArrayQName);
65             if (filter == null)
66                 beans = (IF1[]) call.invoke(new Object JavaDoc[0]);
67             else
68             {
69                 call.addParameter("filter", m_stringArrayQName, ParameterMode.IN);
70                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { filter });
71             }
72
73         return beans;
74     }
75
76     public String JavaDoc[] getAllCategories()
77         throws Exception JavaDoc
78     {
79         String JavaDoc[] categories = null;
80
81             Call call = getCall();
82             call.setTargetEndpointAddress(m_url);
83             call.setOperationName(new QName JavaDoc(m_service, "getAllCategories"));
84             call.setReturnType(m_stringArrayQName);
85             categories = (String JavaDoc[]) call.invoke(new Object JavaDoc[0]);
86
87         return categories;
88     }
89
90     public IF1[] getBeansByCategory(String JavaDoc category)
91         throws Exception JavaDoc
92     {
93         return getBeansByCategory(category, null);
94     }
95
96     public IF1[] getBeansByCategory(String JavaDoc category, String JavaDoc[] filter)
97         throws Exception JavaDoc
98     {
99         IF1[] beans = null;
100
101         if (category == null)
102             throw new Exception JavaDoc("invalid category");
103
104             Call call = getCall();
105             call.setTargetEndpointAddress(m_url);
106             call.setOperationName(new QName JavaDoc(m_service, "getBeansByCategory"));
107             call.setReturnType(m_beanArrayQName);
108             call.addParameter("category", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);
109             if (filter == null)
110                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { category });
111             else
112             {
113                 call.addParameter("filter", m_stringArrayQName, ParameterMode.IN);
114                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { category, filter });
115             }
116
117         return beans;
118     }
119
120     public IF1[] getBeansByDate(Calendar JavaDoc[] dates)
121         throws Exception JavaDoc
122     {
123         return getBeansByDate(dates, null);
124     }
125
126     public IF1[] getBeansByDate(Calendar JavaDoc[] dates, String JavaDoc[] filter)
127         throws Exception JavaDoc
128     {
129         IF1[] beans = null;
130
131         if (dates == null)
132             throw new Exception JavaDoc("invalid dates");
133
134             Call call = getCall();
135             call.setTargetEndpointAddress(m_url);
136             call.setOperationName(new QName JavaDoc(m_service, "getBeansByDate"));
137             call.setReturnType(m_beanArrayQName);
138             call.addParameter("dates", m_calendarArrayQName, ParameterMode.IN);
139             if (filter == null)
140                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { dates });
141             else
142             {
143                 call.addParameter("filter", m_stringArrayQName, ParameterMode.IN);
144                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { dates, filter });
145             }
146
147         return beans;
148     }
149
150     public IF1[] getBeansByExpression(int expType, String JavaDoc expression)
151         throws Exception JavaDoc
152     {
153         return getBeansByExpression(expType, expression, null);
154     }
155
156     public IF1[] getBeansByExpression(int expType, String JavaDoc expression, String JavaDoc[] filter)
157         throws Exception JavaDoc
158     {
159         IF1[] beans = null;
160
161         if (expression == null)
162             throw new Exception JavaDoc("invalid expression");
163
164             Call call = getCall();
165             call.setTargetEndpointAddress(m_url);
166             call.setOperationName(new QName JavaDoc(m_service, "getBeansByExpression"));
167             call.setReturnType(m_beanArrayQName);
168             call.addParameter("expType", org.apache.axis.Constants.XSD_INT, ParameterMode.IN);
169             call.addParameter("expression", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);
170             if (filter == null)
171                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { new Integer JavaDoc(expType), expression });
172             else
173             {
174                 call.addParameter("filter", m_stringArrayQName, ParameterMode.IN);
175                 beans = (IF1[]) call.invoke(new Object JavaDoc[] { new Integer JavaDoc(expType), expression, filter });
176             }
177
178         return beans;
179     }
180
181     public String JavaDoc getXMLForBean(IF1 bean)
182         throws Exception JavaDoc
183     {
184         String JavaDoc xml = null;
185
186         if (bean == null)
187             throw new Exception JavaDoc("invalid bean");
188
189             Call call = getCall();
190             call.setTargetEndpointAddress(m_url);
191             call.setOperationName(new QName JavaDoc(m_service, "getXMLForBean"));
192             call.addParameter("bean", m_beanQName, ParameterMode.IN);
193             call.setReturnType(org.apache.axis.Constants.XSD_STRING);
194             xml = (String JavaDoc) call.invoke(new Object JavaDoc[] { bean });
195
196         return xml;
197     }
198
199     private Call getCall()
200         throws Exception JavaDoc
201     {
202         Call call = null;
203             Service service = new Service();
204             call = (Call) service.createCall();
205
206             call.registerTypeMapping(Bean.class, m_beanQName,
207                 new BeanSerializerFactory(Bean.class, m_beanQName),
208                 new BeanDeserializerFactory(Bean.class, m_beanQName));
209         return call;
210     }
211 }
212
213
Popular Tags