Author: berndf
Date: Mon Aug 13 07:17:05 2007
New Revision: 565359
URL: http://svn.apache.org/viewvc?view=rev&rev=565359
Log:
add mechanism to replace originally configured James service (in
james-assembly.xml) by another bean.
this allows for keeping vanilla james-assembly unchanged while injecting
different services at the same time.
used for replacing default James/Phoenix FileSystem service with James/Spring
implementation
Modified:
james/server/sandbox/spring-integration/spring-deployment/src/main/config/beans-base-config.xml
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/adaptor/DefaultServiceManagerFactory.java
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/adaptor/ServiceManagerFactory.java
Modified:
james/server/sandbox/spring-integration/spring-deployment/src/main/config/beans-base-config.xml
URL:
http://svn.apache.org/viewvc/james/server/sandbox/spring-integration/spring-deployment/src/main/config/beans-base-config.xml?view=diff&rev=565359&r1=565358&r2=565359
==============================================================================
---
james/server/sandbox/spring-integration/spring-deployment/src/main/config/beans-base-config.xml
(original)
+++
james/server/sandbox/spring-integration/spring-deployment/src/main/config/beans-base-config.xml
Mon Aug 13 07:17:05 2007
@@ -27,7 +27,19 @@
beans which replace Avalon specific container logic
-->
- <bean id="serviceManager"
class="org.apache.james.container.spring.adaptor.DefaultServiceManagerFactory"
/>
+ <bean id="fileSystemOverride"
class="org.apache.james.container.spring.adaptor.FileSystemBridge"/>
+
+ <bean id="serviceManager"
class="org.apache.james.container.spring.adaptor.DefaultServiceManagerFactory" >
+ <property name="replacements">
+ <!-- replacement map.
+ key must point to an avalon service from james-assembly.xml
+ value must point to a bean
+ -->
+ <map>
+ <entry key="filesystem" value="fileSystemOverride" />
+ </map>
+ </property>
+ </bean>
<bean name="logWorker"
class="org.apache.james.container.spring.logging.SystemConsoleLogWorker" />
Modified:
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/adaptor/DefaultServiceManagerFactory.java
URL:
http://svn.apache.org/viewvc/james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/adaptor/DefaultServiceManagerFactory.java?view=diff&rev=565359&r1=565358&r2=565359
==============================================================================
---
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/adaptor/DefaultServiceManagerFactory.java
(original)
+++
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/adaptor/DefaultServiceManagerFactory.java
Mon Aug 13 07:17:05 2007
@@ -38,6 +38,7 @@
public class DefaultServiceManagerFactory implements ApplicationContextAware,
ServiceManagerFactory {
private ApplicationContext applicationContext;
+ private final Map replacements = new HashMap();
private class ServiceManagerBridge implements ServiceManager {
@@ -59,11 +60,20 @@
try {
roleClass = Class.forName(rolename);
} catch (ClassNotFoundException e) {
- throw new RuntimeException("cannot load class for role " +
roleClass, e);
+ throw new RuntimeException("cannot load class for role " +
rolename, e);
}
+
+ // if the service should be replaced by a bean, update the
name here.
+ if (replacements.containsKey(name)) {
+ name = (String)replacements.get(name);
+ }
+
// the object to be injected (reduced to roleClass)
Object injectionCandidate = applicationContext.getBean(name);
- if (!roleClass.isInstance(injectionCandidate)) throw new
RuntimeException("cannot assign object as role as specified");
+ if (!roleClass.isInstance(injectionCandidate)) {
+
+ throw new RuntimeException("cannot assign bean '" + name +
"' as role '" + rolename + "'");
+ }
if (avalonServices.containsKey(rolename)) {
throw new IllegalStateException("avalon service references
role name not unique: " + rolename);
@@ -103,5 +113,14 @@
return new
DefaultServiceManagerFactory.ServiceManagerBridge(avalonBeanDefinition.getServiceReferences());
}
-
+
+ /**
+ *
+ * @param replacements - Map<String, String>, the key indicating the
service reference to be replaced, the value
+ * indicating the replacement bean
+ */
+ public void setReplacements(Map replacements) {
+ this.replacements.putAll(replacements);
+ }
+
}
Modified:
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/adaptor/ServiceManagerFactory.java
URL:
http://svn.apache.org/viewvc/james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/adaptor/ServiceManagerFactory.java?view=diff&rev=565359&r1=565358&r2=565359
==============================================================================
---
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/adaptor/ServiceManagerFactory.java
(original)
+++
james/server/sandbox/spring-integration/spring-deployment/src/main/java/org/apache/james/container/spring/adaptor/ServiceManagerFactory.java
Mon Aug 13 07:17:05 2007
@@ -21,9 +21,15 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.springframework.beans.factory.config.BeanDefinition;
+import java.util.Map;
+
/**
*/
public interface ServiceManagerFactory {
ServiceManager getInstanceFor(String beanName, BeanDefinition
beanDefinition);
+
+ void setReplacements(Map replacements);
+
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]