KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > xmlrpc > TurbineXmlRpc


1 package org.apache.turbine.services.xmlrpc;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.io.InputStream JavaDoc;
20
21 import java.net.URL JavaDoc;
22
23 import java.util.Vector JavaDoc;
24
25 import org.apache.turbine.services.TurbineServices;
26 import org.apache.turbine.util.TurbineException;
27
28 /**
29  * This is a static accesor class for {@link XmlRpcService}.
30  *
31  * @author <a HREF="mailto:magnus@handtolvur.is">Magnús Þór Torfason</a>
32  * @author <a HREF="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
33  * @author <a HREF="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
34  * @version $Id: TurbineXmlRpc.java,v 1.8.2.2 2004/05/20 03:06:51 seade Exp $
35  */

36 public abstract class TurbineXmlRpc
37 {
38     /**
39      * Returns system's configured implementation of {@link XmlRpcService}.
40      *
41      * @return an implementaion of <code>XmlRpcService</code>
42      */

43     public static XmlRpcService getService()
44     {
45         return (XmlRpcService) TurbineServices.getInstance()
46                 .getService(XmlRpcService.SERVICE_NAME);
47     }
48
49     /**
50      * Execute a remote procedure call.
51      *
52      * @param url A URL.
53      * @param methodName A String with the method name.
54      * @param params A Vector with the parameters.
55      * @return An Object.
56      * @exception TurbineException
57      */

58     public static Object JavaDoc executeRpc(URL JavaDoc url, String JavaDoc methodName, Vector JavaDoc params)
59             throws TurbineException
60     {
61         return getService().executeRpc(url, methodName, params);
62     }
63
64     /**
65      * Execute a remote procedure call taht requires authentication
66      *
67      * @param url A URL.
68      * @param username The username to try and authenticate with
69      * @param password The password to try and authenticate with
70      * @param methodName A String with the method name.
71      * @param params A Vector with the parameters.
72      * @return An Object.
73      * @exception TurbineException
74      */

75     public static Object JavaDoc executeAuthenticatedRpc(URL JavaDoc url, String JavaDoc username,
76             String JavaDoc password, String JavaDoc methodName, Vector JavaDoc params)
77             throws TurbineException
78     {
79         return getService().executeAuthenticatedRpc(url, username, password,
80                 methodName, params);
81     }
82
83     /**
84      * Register an object as a handler for the XmlRpc Server part.
85      *
86      * @param handlerName The name under which we want
87      * to register the service
88      * @param handler The handler object
89      */

90     public static void registerHandler(String JavaDoc handlerName, Object JavaDoc handler)
91     {
92         getService().registerHandler(handlerName, handler);
93     }
94
95     /**
96      * Register an object as a the default handler for
97      * the XmlRpc Server part.
98      *
99      * @param handler The handler object
100      */

101     public static void registerHandler(Object JavaDoc handler)
102     {
103         getService().registerHandler(handler);
104     }
105
106     /**
107      * Unregister a handler.
108      *
109      * @param handlerName The name of the handler to unregister.
110      */

111     public static void unregisterHandler(String JavaDoc handlerName)
112     {
113         getService().unregisterHandler(handlerName);
114     }
115
116     /**
117      * Handle an XML-RPC request using the encapsulated server.
118      *
119      * You can use this method to handle a request from within
120      * a Turbine screen.
121      *
122      * @param is the stream to read request data from.
123      * @return the response body that needs to be sent to the client.
124      */

125     public static byte[] handleRequest(InputStream JavaDoc is)
126     {
127         return getService().handleRequest(is);
128     }
129
130     /**
131      * Handle an XML-RPC request using the encapsulated server with user
132      * authentication.
133      *
134      * You can use this method to handle a request from within
135      * a Turbine screen.
136      *
137      * <p> Note that the handlers need to implement AuthenticatedXmlRpcHandler
138      * interface to access the authentication infomration.
139      *
140      * @param is the stream to read request data from.
141      * @param user the user that is making the request.
142      * @param password the password given by user.
143      * @return the response body that needs to be sent to the client.
144      */

145     public static byte[] handleRequest(InputStream JavaDoc is, String JavaDoc user, String JavaDoc password)
146     {
147         return getService().handleRequest(is, user, password);
148     }
149
150     /**
151      * Method to allow a client to send a file to a server.
152      *
153      * @param serverURL
154      * @param sourceLocationProperty
155      * @param sourceFileName
156      * @param destinationLocationProperty
157      * @param destinationFileName
158      * @deprecated This is not scope of the Service itself but of an
159      * application which uses the service.
160      */

161     public static void send(String JavaDoc serverURL,
162                             String JavaDoc sourceLocationProperty,
163                             String JavaDoc sourceFileName,
164                             String JavaDoc destinationLocationProperty,
165                             String JavaDoc destinationFileName)
166             throws TurbineException
167     {
168         getService().send(serverURL,
169                 sourceLocationProperty,
170                 sourceFileName,
171                 destinationLocationProperty,
172                 destinationFileName);
173     }
174
175     /**
176      * Method to allow a client to send a file to a server that
177      * requires authentication
178      *
179      * @param serverURL
180      * @param username
181      * @param password
182      * @param sourceLocationProperty
183      * @param sourceFileName
184      * @param destinationLocationProperty
185      * @param destinationFileName
186      * @deprecated This is not scope of the Service itself but of an
187      * application which uses the service.
188      */

189     public static void send(String JavaDoc serverURL,
190                             String JavaDoc username,
191                             String JavaDoc password,
192                             String JavaDoc sourceLocationProperty,
193                             String JavaDoc sourceFileName,
194                             String JavaDoc destinationLocationProperty,
195                             String JavaDoc destinationFileName)
196             throws TurbineException
197     {
198         getService().send(serverURL,
199                 username,
200                 password,
201                 sourceLocationProperty,
202                 sourceFileName,
203                 destinationLocationProperty,
204                 destinationFileName);
205     }
206
207     /**
208      * Method to allow a client to get a file from a server.
209      *
210      * @param serverURL
211      * @param sourceLocationProperty
212      * @param sourceFileName
213      * @param destinationLocationProperty
214      * @param destinationFileName
215      * @deprecated This is not scope of the Service itself but of an
216      * application which uses the service.
217      */

218     public static void get(String JavaDoc serverURL,
219                            String JavaDoc sourceLocationProperty,
220                            String JavaDoc sourceFileName,
221                            String JavaDoc destinationLocationProperty,
222                            String JavaDoc destinationFileName)
223             throws TurbineException
224     {
225         getService().get(serverURL,
226                 sourceLocationProperty,
227                 sourceFileName,
228                 destinationLocationProperty,
229                 destinationFileName);
230     }
231
232     /**
233      * Method to allow a client to get a file to a server that
234      * requires authentication
235      *
236      * @param serverURL
237      * @param username
238      * @param password
239      * @param sourceLocationProperty
240      * @param sourceFileName
241      * @param destinationLocationProperty
242      * @param destinationFileName
243      * @deprecated This is not scope of the Service itself but of an
244      * application which uses the service.
245      */

246     public static void get(String JavaDoc serverURL,
247                            String JavaDoc username,
248                            String JavaDoc password,
249                            String JavaDoc sourceLocationProperty,
250                            String JavaDoc sourceFileName,
251                            String JavaDoc destinationLocationProperty,
252                            String JavaDoc destinationFileName)
253             throws TurbineException
254     {
255         getService().get(serverURL,
256                 username,
257                 password,
258                 sourceLocationProperty,
259                 sourceFileName,
260                 destinationLocationProperty,
261                 destinationFileName);
262     }
263
264     /**
265      * Method to allow a client to remove a file from
266      * the server
267      *
268      * @param serverURL
269      * @param sourceLocationProperty
270      * @param sourceFileName
271      * @deprecated This is not scope of the Service itself but of an
272      * application which uses the service.
273      */

274     public static void remove(String JavaDoc serverURL,
275                               String JavaDoc sourceLocationProperty,
276                               String JavaDoc sourceFileName)
277             throws TurbineException
278     {
279         getService().remove(serverURL,
280                 sourceLocationProperty,
281                 sourceFileName);
282     }
283
284     /**
285      * Method to allow a client to remove a file from
286      * a server that requires authentication
287      *
288      * @param serverURL
289      * @param username
290      * @param password
291      * @param sourceLocationProperty
292      * @param sourceFileName
293      * @deprecated This is not scope of the Service itself but of an
294      * application which uses the service.
295      */

296     public static void remove(String JavaDoc serverURL,
297                               String JavaDoc username,
298                               String JavaDoc password,
299                               String JavaDoc sourceLocationProperty,
300                               String JavaDoc sourceFileName)
301             throws TurbineException
302     {
303         getService().remove(serverURL,
304                 username,
305                 password,
306                 sourceLocationProperty,
307                 sourceFileName);
308     }
309
310     /**
311      * Switch client filtering on/off.
312      * @see #acceptClient(java.lang.String)
313      * @see #denyClient(java.lang.String)
314      */

315     public static void setParanoid(boolean state)
316     {
317         getService().setParanoid(state);
318     }
319
320     /**
321      * Add an IP address to the list of accepted clients. The parameter can
322      * contain '*' as wildcard character, e.g. "192.168.*.*". You must
323      * call setParanoid(true) in order for this to have
324      * any effect.
325      *
326      * @see #denyClient(java.lang.String)
327      * @see #setParanoid(boolean)
328      */

329     public static void acceptClient(String JavaDoc address)
330     {
331         getService().acceptClient(address);
332     }
333
334     /**
335      * Add an IP address to the list of denied clients. The parameter can
336      * contain '*' as wildcard character, e.g. "192.168.*.*". You must call
337      * setParanoid(true) in order for this to have any effect.
338      *
339      * @see #acceptClient(java.lang.String)
340      * @see #setParanoid(boolean)
341      */

342     public static void denyClient(String JavaDoc address)
343     {
344         getService().denyClient(address);
345     }
346 }
347
Popular Tags