KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xmlrpc > MultiCall


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

16
17
18 package org.apache.xmlrpc;
19
20 import java.util.Hashtable JavaDoc;
21 import java.util.Vector JavaDoc;
22
23 /**
24  * The <code>system.multicall</code> handler performs several RPC
25  * calls at a time.
26  *
27  * @author <a HREF="mailto:adam@megacz.com">Adam Megacz</a>
28  * @author <a HREF="mailto:andrew@kungfoocoder.org">Andrew Evers</a>
29  * @author Daniel L. Rall
30  * @version $Id: MultiCall.java,v 1.5 2005/04/22 10:25:57 hgomez Exp $
31  * @since 1.2
32  */

33 public class MultiCall
34 implements ContextXmlRpcHandler
35 {
36     public Object JavaDoc execute(String JavaDoc method, Vector JavaDoc params, XmlRpcContext context)
37             throws Exception JavaDoc
38     {
39         if ("multicall".equals(method))
40         {
41             return multicall(params, context);
42         }
43
44         throw new NoSuchMethodException JavaDoc("No method '" + method + "' in " + this.getClass().getName());
45     }
46
47     public Vector JavaDoc multicall(Vector JavaDoc requests, XmlRpcContext context)
48     {
49         // The array of calls is passed as a single parameter of type array.
50
requests=(Vector JavaDoc)requests.elementAt(0);
51         Vector JavaDoc response = new Vector JavaDoc();
52         XmlRpcServerRequest request;
53         for (int i = 0; i < requests.size(); i++)
54         {
55             try
56             {
57                 Hashtable JavaDoc call = (Hashtable JavaDoc) requests.elementAt(i);
58                 request = new XmlRpcRequest((String JavaDoc) call.get("methodName"),
59                                             (Vector JavaDoc) call.get("params"));
60                 Object JavaDoc handler = context.getHandlerMapping().getHandler(request.getMethodName());
61                 Vector JavaDoc v = new Vector JavaDoc();
62                 v.addElement(XmlRpcWorker.invokeHandler(handler, request, context));
63                 response.addElement(v);
64             }
65             catch (Exception JavaDoc x)
66             {
67                 String JavaDoc message = x.toString();
68                 int code = (x instanceof XmlRpcException ?
69                             ((XmlRpcException) x).code : 0);
70                 Hashtable JavaDoc h = new Hashtable JavaDoc();
71                 h.put("faultString", message);
72                 h.put("faultCode", new Integer JavaDoc(code));
73                 response.addElement(h);
74             }
75         }
76         return response;
77     }
78 }
79
Popular Tags