1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package com.germinus.easyconf;
17  
18  import org.apache.commons.configuration.Configuration;
19  import java.util.Properties;
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  
23  
24  /***
25   * M?todos de utilidad para trabajar con par?metros de configuraci?n que representan
26   * clases
27   * Fecha: 09-jul-2004 -- 12:06:34
28   * @author Jes?s J?imez Rodr?guez <jesusjaimez@germinus.com>
29   */
30  public class ClassParameter {
31  
32      private static final Log log = LogFactory.getLog(ClassParameter.class);
33  
34      public static Object getNewInstance(Configuration conf, String propertyName)
35              throws ClassNotFoundException, IllegalAccessException,
36              InstantiationException {
37          String className = conf.getString(propertyName);
38          log.info("Returning " + className + " class instance.");
39          return ClasspathUtil.locateClass(className).newInstance();
40      }
41  
42      public static Object getNewInstance(Properties props, String propertyName)
43              throws ClassNotFoundException, IllegalAccessException,
44              InstantiationException {
45          String className = props.getProperty(propertyName);
46          log.info("Returning " + className + " class instance.");
47          return ClasspathUtil.locateClass(className).newInstance();
48      }
49  }