KickJava   Java API By Example, From Geeks To Geeks.

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


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.Vector JavaDoc;
21
22 /**
23  * Wraps calls to the XML-RPC standard system.* methods (such as
24  * <code>system.multicall</code>).
25  *
26  * @author <a HREF="mailto:adam@megacz.com">Adam Megacz</a>
27  * @author <a HREF="mailto:andrew@kungfoocoder.org">Andrew Evers</a>
28  * @author Daniel L. Rall
29  * @since 1.2
30  */

31 public class SystemHandler
32 implements ContextXmlRpcHandler
33 {
34     private DefaultHandlerMapping systemMapping = null;
35
36     /**
37      * Creates a new instance. This instance contains no system calls. Use the
38      * addDefaultSystemHandlers() method to add the 'default' set of handlers,
39      * or add handlers manually.
40      */

41     public SystemHandler()
42     {
43         this.systemMapping = new DefaultHandlerMapping();
44     }
45
46    /**
47      * Creates a new instance that delegates calls via the
48      * specified {@link org.apache.xmlrpc.XmlRpcHandlerMapping}. This
49      * method will add the system.multicall handler when a non-null
50      * handlerMapping is specified. The value itself is ignored.
51      *
52      * @deprecated use new SystemHandler() and addDefaultSystemHandlers() instead.
53      */

54     public SystemHandler(XmlRpcHandlerMapping handlerMapping)
55     {
56         this();
57         if (handlerMapping != null)
58         {
59           addDefaultSystemHandlers();
60         }
61     }
62
63     /**
64      * Creates a new instance that delegates its multicalls via
65      * the mapping used by the specified {@link org.apache.xmlrpc.XmlRpcServer}.
66      * This method will add the default handlers when the specfied server's
67      * getHandlerMapping() returns a non-null handler mapping.
68      *
69      * @param server The server to retrieve the XmlRpcHandlerMapping from.
70      *
71      * @deprecated use new SystemHandler() and addDefaultSystemHandlers() instead.
72      */

73     protected SystemHandler(XmlRpcServer server)
74     {
75         this(server.getHandlerMapping());
76     }
77
78     /**
79      * Add the default system handlers. The default system handlers are:
80      * <dl>
81      * <dt>system.multicall</dt>
82      * <dd>Make multiple XML-RPC calls in one request and receive multiple
83      * responses.</dd>
84      * </dl>
85      */

86     public void addDefaultSystemHandlers()
87     {
88         addSystemHandler("multicall", new MultiCall());
89     }
90
91     /**
92      * @see org.apache.xmlrpc.DefaultHandlerMapping#addHandler(String, Object)
93      */

94     public void addSystemHandler(String JavaDoc handlerName, ContextXmlRpcHandler handler)
95     {
96         systemMapping.addHandler(handlerName, handler);
97     }
98
99     /**
100      * @see org.apache.xmlrpc.DefaultHandlerMapping#removeHandler(String)
101      */

102     public void removeSystemHandler(String JavaDoc handlerName)
103     {
104         systemMapping.removeHandler(handlerName);
105     }
106
107     /**
108      * Execute a &lt;ignored&gt;.&lt;name&gt; call by calling the handler for
109      * &lt;name&gt; in the the system handler mapping.
110      */

111     public Object JavaDoc execute(String JavaDoc method, Vector JavaDoc params, XmlRpcContext context)
112             throws Exception JavaDoc
113     {
114         Object JavaDoc handler = null;
115         String JavaDoc systemMethod = null;
116         int dot = method.lastIndexOf('.');
117         if (dot > -1)
118         {
119             // The last portion of the XML-RPC method name is the systen
120
// method name.
121
systemMethod = method.substring(dot + 1);
122
123             // Add the "." in at the end, the systemMapping will strip it off
124
handler = systemMapping.getHandler(systemMethod + ".");
125             if (handler != null)
126             {
127                 return ((ContextXmlRpcHandler) handler).execute(systemMethod, params, context);
128             }
129         }
130
131         throw new NoSuchMethodException JavaDoc("No method '" + method + "' registered.");
132     }
133 }
134
Popular Tags