View Javadoc

1   /*
2    * Copyright 2004-2005 Germinus XXI
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  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  }