Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 package org.apache.xmlrpc.server;
00020
00021 import java.io.IOException;
00022 import java.net.URL;
00023 import java.util.Iterator;
00024 import java.util.Map;
00025 import java.util.Properties;
00026
00027 import org.apache.xmlrpc.XmlRpcException;
00028
00029
00039 public class PropertyHandlerMapping extends AbstractReflectiveHandlerMapping {
00049 public void load(ClassLoader pClassLoader, String pResource)
00050 throws IOException, XmlRpcException {
00051 URL url = pClassLoader.getResource(pResource);
00052 if (url == null) {
00053 throw new IOException("Unable to locate resource " + pResource);
00054 }
00055 load(pClassLoader, url);
00056 }
00057
00066 public void load(ClassLoader pClassLoader, URL pURL) throws IOException, XmlRpcException {
00067 Properties props = new Properties();
00068 props.load(pURL.openStream());
00069 load(pClassLoader, props);
00070 }
00071
00079 public void load(ClassLoader pClassLoader, Map pMap) throws XmlRpcException {
00080 for (Iterator iter = pMap.entrySet().iterator(); iter.hasNext(); ) {
00081 Map.Entry entry = (Map.Entry) iter.next();
00082 String key = (String) entry.getKey();
00083 String value = (String) entry.getValue();
00084 Class c = newHandlerClass(pClassLoader, value);
00085 registerPublicMethods(key, c);
00086 }
00087 }
00088
00089 protected Class newHandlerClass(ClassLoader pClassLoader, String pClassName)
00090 throws XmlRpcException {
00091 final Class c;
00092 try {
00093 c = pClassLoader.loadClass(pClassName);
00094 } catch (ClassNotFoundException e) {
00095 throw new XmlRpcException("Unable to load class: " + pClassName, e);
00096 }
00097 if (c == null) {
00098 throw new XmlRpcException(0, "Loading class " + pClassName + " returned null.");
00099 }
00100 return c;
00101 }
00102
00110 public void addHandler(String pKey, Class pClass) throws XmlRpcException {
00111 registerPublicMethods(pKey, pClass);
00112 }
00113
00116 public void removeHandler(String pKey) {
00117 for (Iterator i = handlerMap.keySet().iterator(); i.hasNext();) {
00118 String k = (String)i.next();
00119 if (k.startsWith(pKey)) i.remove();
00120 }
00121 }
00122 }