(no commit message)
[utils] / support / src / org / wamblee / general / BeanKernel.java
index fa48fb9719bd6458d8e30976ddb69dedf65e6c79..d05eef3dd6b507c8706a5d2dd865b3de4edc06c6 100644 (file)
@@ -25,9 +25,13 @@ import org.wamblee.io.ClassPathResource;
 import org.wamblee.io.InputResource;
 
 /**
- * The standard means to obtain the bean factory.
+ * The standard means to obtain the bean factory. This works by reading a
+ * property {@value #BEAN_FACTORY_CLASS} from a property file named
+ * {@value #BEAN_KERNEL_PROP_FILE} from the class path. This property identifies
+ * the bean factory implementation to use. The configured bean factory must have
+ * a no-arg constructor.
  */
-public class BeanKernel {
+public final class BeanKernel {
 
     private static final Log LOG = LogFactory.getLog(BeanKernel.class);
 
@@ -47,6 +51,14 @@ public class BeanKernel {
      */
     private static BeanFactory BEAN_FACTORY;
 
+    /**
+     * Disabled constructor.
+     * 
+     */
+    private BeanKernel() {
+        // Empty
+    }
+
     /**
      * Overrides the default mechanism for looking up the bean factory by
      * specifying it yourself.
@@ -59,13 +71,14 @@ public class BeanKernel {
     }
 
     /**
-     * Gets the bean factory. 
-     * @return Bean factory. 
+     * Gets the bean factory.
+     * 
+     * @return Bean factory.
      */
     public static BeanFactory getBeanFactory() {
         synchronized (BeanFactory.class) {
             if (BEAN_FACTORY == null) {
-                BEAN_FACTORY = lookupBeanFactory();
+                BEAN_FACTORY = lookupBeanFactory(BEAN_KERNEL_PROP_FILE);
             }
         }
         return BEAN_FACTORY;
@@ -76,8 +89,8 @@ public class BeanKernel {
      * 
      * @return Bean factory.
      */
-    private static BeanFactory lookupBeanFactory() {
-        InputResource resource = new ClassPathResource(BEAN_KERNEL_PROP_FILE);
+    static BeanFactory lookupBeanFactory(String aPropertyFilename) {
+        InputResource resource = new ClassPathResource(aPropertyFilename);
         InputStream is;
         try {
             is = resource.getInputStream();
@@ -87,7 +100,7 @@ public class BeanKernel {
         }
         try {
             Properties props = new Properties();
-            props.load(resource.getInputStream());
+            props.load(is);
             String className = props.getProperty(BEAN_FACTORY_CLASS);
             Class beanFactory = Class.forName(className);
             return (BeanFactory) beanFactory.newInstance();