X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fgeneral%2FBeanKernel.java;h=619c7da3594f6afbc46a394ba14e2b74db242394;hb=da0699d61503e0fcd21f41bd05aa8a2d993c3010;hp=d05eef3dd6b507c8706a5d2dd865b3de4edc06c6;hpb=32a62ca2c752e33a7873ac868a7a1f289caedcd4;p=utils diff --git a/support/general/src/main/java/org/wamblee/general/BeanKernel.java b/support/general/src/main/java/org/wamblee/general/BeanKernel.java index d05eef3d..619c7da3 100644 --- a/support/general/src/main/java/org/wamblee/general/BeanKernel.java +++ b/support/general/src/main/java/org/wamblee/general/BeanKernel.java @@ -1,5 +1,5 @@ /* - * Copyright 2005 the original author or authors. + * Copyright 2005-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,18 +12,20 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + */ package org.wamblee.general; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.wamblee.io.ClassPathResource; import org.wamblee.io.InputResource; +import java.io.IOException; +import java.io.InputStream; + +import java.util.Properties; + /** * The standard means to obtain the bean factory. This works by reading a * property {@value #BEAN_FACTORY_CLASS} from a property file named @@ -32,7 +34,6 @@ import org.wamblee.io.InputResource; * a no-arg constructor. */ public final class BeanKernel { - private static final Log LOG = LogFactory.getLog(BeanKernel.class); /** @@ -81,32 +82,39 @@ public final class BeanKernel { BEAN_FACTORY = lookupBeanFactory(BEAN_KERNEL_PROP_FILE); } } + return BEAN_FACTORY; } /** * Lookup the bean factory based on the properties file. * + * * @return Bean factory. + * */ static BeanFactory lookupBeanFactory(String aPropertyFilename) { InputResource resource = new ClassPathResource(aPropertyFilename); InputStream is; + try { is = resource.getInputStream(); } catch (IOException e) { throw new BeanFactoryException("Cannot open resource " + resource, - e); + e); } + try { Properties props = new Properties(); props.load(is); + String className = props.getProperty(BEAN_FACTORY_CLASS); Class beanFactory = Class.forName(className); + return (BeanFactory) beanFactory.newInstance(); } catch (Exception e) { - throw new BeanFactoryException("Cannot read from resource " - + resource, e); + throw new BeanFactoryException("Cannot read from resource " + + resource, e); } finally { try { is.close();