X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=system%2Fspring%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fspring%2FSpringComponent.java;h=83a5133bd74122ef48213941ddffcd9ce6137f6b;hb=2a22d6cf8dc6302a94f4121983d979d8f55da6ca;hp=1da30a324ed53c4c9812306669e2adc287b5b6a8;hpb=89c88ac43fae02ff527fd252cee058a9523b78e9;p=utils diff --git a/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java b/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java index 1da30a32..83a5133b 100644 --- a/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java +++ b/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java @@ -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 { private String[] _configFiles; private Map _provided; private Map _required; + private Map _propertyObjects; /** * Constructs a spring system. @@ -75,6 +77,8 @@ public class SpringComponent extends AbstractComponent { _configFiles = aConfigFiles; _provided = aProvided; _required = aRequired; + _propertyObjects = new HashMap(); + } /** @@ -94,6 +98,14 @@ public class SpringComponent extends AbstractComponent { 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 { GenericApplicationContext parentContext = new GenericApplicationContext(); registerRequiredServices(parentContext); + registerPropertyObjects(parentContext); parentContext.refresh(); @@ -156,14 +169,30 @@ public class SpringComponent extends AbstractComponent { // Register required services in a parent context for (RequiredInterface required: getRequiredInterfaces()) { String beanName = _required.get(required); - ConstructorArgumentValues cargs = new ConstructorArgumentValues(); - cargs.addGenericArgumentValue(required.getName()); - BeanDefinition definition = new RootBeanDefinition( - RequiredServiceBean.class, cargs, - new MutablePropertyValues()); - aParentContext.registerBeanDefinition(beanName, definition); + if ( beanName != null && beanName.length() > 0) { + ConstructorArgumentValues cargs = new ConstructorArgumentValues(); + cargs.addGenericArgumentValue(required.getName()); + BeanDefinition definition = new RootBeanDefinition( + RequiredServiceBean.class, cargs, + new MutablePropertyValues()); + aParentContext.registerBeanDefinition(beanName, definition); + } else { + // The required interface is not required by the spring config but by the sub-class directly. + } } } + + 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) {