PropertyHandlerMapping.java
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one
00003  * or more contributor license agreements.  See the NOTICE file
00004  * distributed with this work for additional information
00005  * regarding copyright ownership.  The ASF licenses this file
00006  * to you under the Apache License, Version 2.0 (the
00007  * "License"); you may not use this file except in compliance
00008  * with the License.  You may obtain a copy of the License at
00009  *
00010  *   http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing,
00013  * software distributed under the License is distributed on an
00014  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00015  * KIND, either express or implied.  See the License for the
00016  * specific language governing permissions and limitations
00017  * under the License.    
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 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49