1 16 17 18 package org.apache.xmlrpc; 19 20 21 import java.util.Hashtable ; 22 23 34 public class DefaultHandlerMapping 35 implements XmlRpcHandlerMapping 36 { 37 private Hashtable handlers; 38 39 42 public DefaultHandlerMapping() 43 { 44 handlers = new Hashtable (); 45 } 46 47 57 public void addHandler(String handlerName, Object handler) 58 { 59 if (handler instanceof XmlRpcHandler || 60 handler instanceof AuthenticatedXmlRpcHandler || 61 handler instanceof ContextXmlRpcHandler) 62 { 63 handlers.put(handlerName, handler); 64 } 65 else if (handler != null) 66 { 67 handlers.put(handlerName, new Invoker(handler)); 68 } 69 } 70 71 77 public void removeHandler(String handlerName) 78 { 79 handlers.remove(handlerName); 80 } 81 82 91 public Object getHandler(String methodName) 92 throws Exception 93 { 94 Object handler = null; 95 String handlerName = null; 96 int dot = methodName.lastIndexOf('.'); 97 if (dot > -1) 98 { 99 handlerName = methodName.substring(0, dot); 102 handler = handlers.get(handlerName); 103 } 104 105 if (handler == null) 106 { 107 handler = handlers.get("$default"); 108 109 if (handler == null) 110 { 111 if (dot > -1) 112 { 113 throw new Exception ("RPC handler object \"" 114 + handlerName + "\" not found and no " 115 + "default handler registered"); 116 } 117 else 118 { 119 throw new Exception ("RPC handler object not found for \"" 120 + methodName 121 + "\": No default handler registered"); 122 } 123 } 124 } 125 126 return handler; 127 } 128 } 129 | Popular Tags |