SpringComponent now supports adding properties as beans instead of
[utils] / system / spring / src / main / java / org / wamblee / system / spring / SpringComponent.java
index 1da30a324ed53c4c9812306669e2adc287b5b6a8..d0abbcd173b8f20152744cac6b4b35df1cd94f53 100644 (file)
@@ -15,6 +15,7 @@
  */ 
 package org.wamblee.system.spring;
 
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 
@@ -49,6 +50,7 @@ public class SpringComponent extends AbstractComponent<Scope> {
        private String[] _configFiles;
        private Map<String, ProvidedInterface> _provided;
        private Map<RequiredInterface, String> _required;
+       private Map<String, Properties> _propertyObjects;
 
        /**
         * Constructs a spring system.
@@ -75,6 +77,8 @@ public class SpringComponent extends AbstractComponent<Scope> {
                _configFiles = aConfigFiles;
                _provided = aProvided;
                _required = aRequired;
+               _propertyObjects = new HashMap<String, Properties>(); 
+               
        }
 
        /**
@@ -94,6 +98,14 @@ public class SpringComponent extends AbstractComponent<Scope> {
                        setProperty((String) key, aProperties.getProperty((String) key));
                }
        }
+       
+       public void addProperties(String aBeanname, Properties aProperties) { 
+           _propertyObjects.put(aBeanname, aProperties);
+       }
+       
+       public Properties getProperties(String aBeanname) { 
+           return _propertyObjects.get(aBeanname);
+       }
 
        @Override
        protected Scope doStart(Scope aExternalScope) {
@@ -107,6 +119,7 @@ public class SpringComponent extends AbstractComponent<Scope> {
                        GenericApplicationContext parentContext = new GenericApplicationContext();
 
                        registerRequiredServices(parentContext);
+                       registerPropertyObjects(parentContext);
 
                        parentContext.refresh();
                        
@@ -164,6 +177,18 @@ public class SpringComponent extends AbstractComponent<Scope> {
                        aParentContext.registerBeanDefinition(beanName, definition);
                }
        }
+       
+       private void registerPropertyObjects(GenericApplicationContext aParentContext) {
+        for (String beanName: _propertyObjects.keySet()) { 
+            ConstructorArgumentValues cargs = new ConstructorArgumentValues();
+            cargs.addGenericArgumentValue(PropertySetter.createPropertyFile(_propertyObjects.get(beanName)));
+            BeanDefinition definition = new RootBeanDefinition(
+                    ConfiguredProperties.class, cargs,
+                    new MutablePropertyValues());
+            aParentContext.registerBeanDefinition(beanName, definition);
+        }
+    }
+
 
        @Override
        protected void doStop(Scope aRuntime) {