james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Charles <e...@apache.org>
Subject Re: svn commit: r1005919 - in /james/server/trunk: core-api/src/main/java/org/apache/james/services/ core-library/src/main/java/org/apache/james/filepair/ core-library/src/main/java/org/apache/james/services/ mail-library/src/main/java/org/apache/james/mai...
Date Sat, 09 Oct 2010 05:33:06 GMT
I like this commit.
(not sure to understand all the magic, but I like it)


On 8/10/2010 19:38, norman@apache.org wrote:
> Author: norman
> Date: Fri Oct  8 17:38:50 2010
> New Revision: 1005919
>
> URL: http://svn.apache.org/viewvc?rev=1005919&view=rev
> Log:
> Rework components to make james components as less depend on spring as possible.
>
> Added:
>      james/server/trunk/mail-library/src/main/java/org/apache/james/mailstore/JamesMailStore.java
>        - copied, changed from r1005333, james/server/trunk/mail-library/src/main/java/org/apache/james/mailstore/AbstractMailStore.java
>      james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/JamesProtocolHandlerChain.java
>        - copied, changed from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringProtocolHandlerChain.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/ConfigurationProvider.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/LogProvider.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringConfigurationProvider.java
>        - copied, changed from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringConfigurationRegistry.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringLogProvider.java
>        - copied, changed from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringLogRegistry.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/RestrictedLifeCycleBeanPostProcessor.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationProvider.java
>        - copied, changed from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationRegistry.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringLogProvider.java
>        - copied, changed from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringLogRegistry.java
>      james/server/trunk/user-library/src/main/java/org/apache/james/impl/AbstractStore.java
>        - copied, changed from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/AbstractStore.java
>      james/server/trunk/user-library/src/main/java/org/apache/james/impl/user/JamesUsersStore.java
>        - copied, changed from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringUsersStore.java
>      james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/JamesVirtualUserTableStore.java
>        - copied, changed from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringVirtualUserTableStore.java
> Removed:
>      james/server/trunk/mail-library/src/main/java/org/apache/james/mailstore/AbstractMailStore.java
>      james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/ProtocolHandlerChainImpl.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/AbstractStore.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/Registry.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringMailStore.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringProtocolHandlerChain.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringUsersStore.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringVirtualUserTableStore.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringConfigurationRegistry.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringLogRegistry.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationRegistry.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringLogRegistry.java
> Modified:
>      james/server/trunk/core-api/src/main/java/org/apache/james/services/InstanceFactory.java
>      james/server/trunk/core-library/src/main/java/org/apache/james/filepair/AbstractFileRepository.java
>      james/server/trunk/core-library/src/main/java/org/apache/james/services/AbstractJSR250InstanceFactory.java
>      james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/AbstractLoader.java
>      james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/JamesMailetLoader.java
>      james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/JamesMatcherLoader.java
>      james/server/trunk/pop3server/src/test/java/org/apache/james/pop3server/AbstractAsyncPOP3ServerTest.java
>      james/server/trunk/remotemanager/src/test/java/org/apache/james/remotemanager/AbstractRemoteManagerTest.java
>      james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/AbstractSMTPServerTest.java
>      james/server/trunk/spring-common/pom.xml
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringInstanceFactory.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/CommonsConfigurableBeanPostProcessor.java
>      james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/LogEnabledBeanPostProcessor.java
>      james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml
>
> Modified: james/server/trunk/core-api/src/main/java/org/apache/james/services/InstanceFactory.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/core-api/src/main/java/org/apache/james/services/InstanceFactory.java?rev=1005919&r1=1005918&r2=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/core-api/src/main/java/org/apache/james/services/InstanceFactory.java (original)
> +++ james/server/trunk/core-api/src/main/java/org/apache/james/services/InstanceFactory.java Fri Oct  8 17:38:50 2010
> @@ -19,6 +19,9 @@
>
>   package org.apache.james.services;
>
> +import org.apache.commons.configuration.HierarchicalConfiguration;
> +import org.apache.commons.logging.Log;
> +
>   /**
>    * Loads instances of given types.
>    */
> @@ -31,7 +34,10 @@ public interface InstanceFactory {
>        * @param type may be interface or concrete, not null
>        * @return an instance of the type
>        */
> -    public Object newInstance(String className) throws InstanceException, ClassNotFoundException;
> +    public<T>  T newInstance(Class<T>  clazz) throws InstanceException;
> +
> +    public<T>  T newInstance(Class<T>  clazz, Log log, HierarchicalConfiguration config) throws InstanceException;
> +
>
>       @SuppressWarnings("serial")
>       public class InstanceException extends Exception {
>
> Modified: james/server/trunk/core-library/src/main/java/org/apache/james/filepair/AbstractFileRepository.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/filepair/AbstractFileRepository.java?rev=1005919&r1=1005918&r2=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/core-library/src/main/java/org/apache/james/filepair/AbstractFileRepository.java (original)
> +++ james/server/trunk/core-library/src/main/java/org/apache/james/filepair/AbstractFileRepository.java Fri Oct  8 17:38:50 2010
> @@ -71,13 +71,14 @@ public abstract class AbstractFileReposi
>       private FileSystem fileSystem;
>
>       private Log logger;
> +
> +    private String destination;
>
>       public void configure(HierarchicalConfiguration configuration) throws ConfigurationException{
> -        final String destination = configuration.getString( "[@destinationURL]" );
> -        setDestination( destination );
> -
> +        destination = configuration.getString( "[@destinationURL]" );
>       }
>
> +
>       @Resource(name="filesystem")
>       public void setFileSystem(FileSystem fileSystem) {
>           this.fileSystem = fileSystem;
> @@ -97,8 +98,10 @@ public abstract class AbstractFileReposi
>       public void init()
>           throws Exception
>       {
> +
>           getLogger().info( "Init " + getClass().getName() + " Store" );
> -
> +        setDestination( destination );
> +
>           File directory;
>
>           try
>
> Modified: james/server/trunk/core-library/src/main/java/org/apache/james/services/AbstractJSR250InstanceFactory.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/services/AbstractJSR250InstanceFactory.java?rev=1005919&r1=1005918&r2=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/core-library/src/main/java/org/apache/james/services/AbstractJSR250InstanceFactory.java (original)
> +++ james/server/trunk/core-library/src/main/java/org/apache/james/services/AbstractJSR250InstanceFactory.java Fri Oct  8 17:38:50 2010
> @@ -27,6 +27,9 @@ import javax.annotation.PostConstruct;
>   import javax.annotation.PreDestroy;
>   import javax.annotation.Resource;
>
> +import org.apache.commons.configuration.HierarchicalConfiguration;
> +import org.apache.commons.logging.Log;
> +
>   /**
>    * Abstract base class which implements a JSR250 based LoaderService
>    *
> @@ -41,19 +44,21 @@ public abstract class AbstractJSR250Inst
>        *
>        * @see org.apache.james.api.kernel.Factory#newInstance(java.lang.String)
>        */
> -    public final Object newInstance(String className) throws InstanceException, ClassNotFoundException {
> +    public final<T>  T newInstance(Class<T>  clazz) throws InstanceException {
> +        return newInstance(clazz, null, null);
> +    }
> +
> +    public  final<T>  T newInstance(Class<T>  clazz, Log log, HierarchicalConfiguration config) throws InstanceException {
>           try {
> -            Object obj = create(className);
> +            T obj = clazz.newInstance();
>               injectResources(obj);
>               postConstruct(obj);
>               synchronized (this) {
>                   loaderRegistry.add(obj);
>               }
>               return obj;
> -        } catch (ClassNotFoundException e) {
> -            throw e;
>           } catch (Exception e) {
> -            throw new InstanceException("Unable to load instance of class " + className, e);
> +            throw new InstanceException("Unable to load instance of class " + clazz, e);
>           }
>       }
>
>
> Copied: james/server/trunk/mail-library/src/main/java/org/apache/james/mailstore/JamesMailStore.java (from r1005333, james/server/trunk/mail-library/src/main/java/org/apache/james/mailstore/AbstractMailStore.java)
> URL: http://svn.apache.org/viewvc/james/server/trunk/mail-library/src/main/java/org/apache/james/mailstore/JamesMailStore.java?p2=james/server/trunk/mail-library/src/main/java/org/apache/james/mailstore/JamesMailStore.java&p1=james/server/trunk/mail-library/src/main/java/org/apache/james/mailstore/AbstractMailStore.java&r1=1005333&r2=1005919&rev=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/mail-library/src/main/java/org/apache/james/mailstore/AbstractMailStore.java (original)
> +++ james/server/trunk/mail-library/src/main/java/org/apache/james/mailstore/JamesMailStore.java Fri Oct  8 17:38:50 2010
> @@ -26,6 +26,7 @@ import java.util.List;
>   import java.util.Map;
>
>   import javax.annotation.PostConstruct;
> +import javax.annotation.Resource;
>
>   import org.apache.commons.collections.map.ReferenceMap;
>   import org.apache.commons.configuration.CombinedConfiguration;
> @@ -35,14 +36,14 @@ import org.apache.commons.logging.Log;
>   import org.apache.james.lifecycle.Configurable;
>   import org.apache.james.lifecycle.LogEnabled;
>   import org.apache.james.mailstore.MailStore;
> +import org.apache.james.services.InstanceFactory;
>
>   /**
>    * Provides a registry of mail repositories. A mail repository is uniquely
>    * identified by its destinationURL, type and model.
>    *
>    */
> -public abstract class AbstractMailStore
> -    implements MailStore, LogEnabled, Configurable {
> +public class JamesMailStore implements MailStore, LogEnabled, Configurable {
>
>       // Prefix for repository names
>       private static final String REPOSITORY_NAME = "Repository";
> @@ -68,6 +69,8 @@ public abstract class AbstractMailStore
>
>       private Log logger;
>
> +    private InstanceFactory factory;
> +
>   	//private LoaderService loader;
>
>
> @@ -84,6 +87,11 @@ public abstract class AbstractMailStore
>       }
>
>
> +    @Resource(name="instanceFactory")
> +    public void setInstanceFactory(InstanceFactory factory) {
> +        this.factory = factory;
> +    }
> +
>       @PostConstruct
>       @SuppressWarnings("unchecked")
>       public void init()
> @@ -243,8 +251,8 @@ public abstract class AbstractMailStore
>                   config.addConfiguration(defConf);
>               }
>
> -            try {
> -                reply = load(repClass, config, logger);
> +            try {
> +                reply = factory.newInstance(Thread.currentThread().getContextClassLoader().loadClass(repClass), logger, config);
>
>                   repositories.put(repID, reply);
>                   if (getLogger().isInfoEnabled()) {
> @@ -277,10 +285,8 @@ public abstract class AbstractMailStore
>        * @return a new repository name
>        */
>       public static final String getName() {
> -        synchronized (AbstractMailStore.class) {
> +        synchronized (JamesMailStore.class) {
>               return REPOSITORY_NAME + id++;
>           }
>       }
> -
> -    protected abstract Object load(String className, HierarchicalConfiguration config, Log log) throws Exception;
>   }
>
> Modified: james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/AbstractLoader.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/AbstractLoader.java?rev=1005919&r1=1005918&r2=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/AbstractLoader.java (original)
> +++ james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/AbstractLoader.java Fri Oct  8 17:38:50 2010
> @@ -31,7 +31,6 @@ import org.apache.commons.logging.Log;
>   import org.apache.james.lifecycle.Configurable;
>   import org.apache.james.lifecycle.LogEnabled;
>   import org.apache.james.services.InstanceFactory;
> -import org.apache.james.services.InstanceFactory.InstanceException;
>   import org.apache.mailet.MailetContext;
>   import org.apache.mailet.MailetException;
>
> @@ -52,7 +51,7 @@ public abstract class AbstractLoader imp
>
>       private Log logger;
>
> -    private InstanceFactory factory;
> +    protected InstanceFactory factory;
>
>
>       /*
> @@ -82,13 +81,6 @@ public abstract class AbstractLoader imp
>           return logger;
>       }
>
> -    protected Object load(String className) throws ClassNotFoundException {
> -        try {
> -            return factory.newInstance(className);
> -        } catch (InstanceException e) {
> -            return null;
> -        }
> -    }
>
>       @SuppressWarnings("unchecked")
>       protected void getPackages(HierarchicalConfiguration conf, String packageType)
>
> Modified: james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/JamesMailetLoader.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/JamesMailetLoader.java?rev=1005919&r1=1005918&r2=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/JamesMailetLoader.java (original)
> +++ james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/JamesMailetLoader.java Fri Oct  8 17:38:50 2010
> @@ -54,7 +54,7 @@ public class JamesMailetLoader extends A
>               for (final String packageName:packages) {
>                   final String className = packageName + mailetName;
>                   try {
> -                    final Mailet mailet = (Mailet) load(className);;
> +                    final Mailet mailet = (Mailet)factory.newInstance(Thread.currentThread().getContextClassLoader().loadClass(className));
>
>                       final MailetConfigImpl configImpl = new MailetConfigImpl();
>                       configImpl.setMailetName(mailetName);
>
> Modified: james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/JamesMatcherLoader.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/JamesMatcherLoader.java?rev=1005919&r1=1005918&r2=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/JamesMatcherLoader.java (original)
> +++ james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/JamesMatcherLoader.java Fri Oct  8 17:38:50 2010
> @@ -57,7 +57,7 @@ public class JamesMatcherLoader extends
>               for (final String packageName: packages) {
>                   final String className = packageName + matchName;
>                   try {
> -                    final Matcher matcher = (Matcher) load(className);
> +                    final Matcher matcher = (Matcher) factory.newInstance(Thread.currentThread().getContextClassLoader().loadClass(className));
>
>                       final MatcherConfigImpl configImpl = new MatcherConfigImpl();
>                       configImpl.setMatcherName(matchName);
>
> Copied: james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/JamesProtocolHandlerChain.java (from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringProtocolHandlerChain.java)
> URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/JamesProtocolHandlerChain.java?p2=james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/JamesProtocolHandlerChain.java&p1=james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringProtocolHandlerChain.java&r1=1005333&r2=1005919&rev=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringProtocolHandlerChain.java (original)
> +++ james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/JamesProtocolHandlerChain.java Fri Oct  8 17:38:50 2010
> @@ -16,85 +16,63 @@
>    * specific language governing permissions and limitations      *
>    * under the License.                                           *
>    ****************************************************************/
> -package org.apache.james.container.spring;
> +package org.apache.james.socket;
>
>   import java.util.Iterator;
>   import java.util.LinkedList;
>   import java.util.List;
> -import java.util.Map;
> +
> +import javax.annotation.PostConstruct;
> +import javax.annotation.Resource;
>
>   import org.apache.commons.configuration.ConfigurationException;
>   import org.apache.commons.configuration.DefaultConfigurationBuilder;
>   import org.apache.commons.configuration.HierarchicalConfiguration;
>   import org.apache.commons.logging.Log;
> +import org.apache.james.lifecycle.Configurable;
> +import org.apache.james.lifecycle.LogEnabled;
>   import org.apache.james.protocols.api.ExtensibleHandler;
>   import org.apache.james.protocols.api.HandlersPackage;
>   import org.apache.james.protocols.api.ProtocolHandlerChain;
>   import org.apache.james.protocols.api.WiringException;
> -import org.springframework.beans.BeansException;
> -import org.springframework.beans.FatalBeanException;
> -import org.springframework.beans.factory.BeanNameAware;
> -import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
> -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
> -import org.springframework.beans.factory.support.BeanDefinitionBuilder;
> -import org.springframework.beans.factory.support.BeanDefinitionRegistry;
> -import org.springframework.context.ApplicationContext;
> -import org.springframework.context.ApplicationContextAware;
> -import org.springframework.context.ApplicationEvent;
> -import org.springframework.context.ApplicationListener;
> -import org.springframework.context.event.ContextRefreshedEvent;
> +import org.apache.james.services.InstanceFactory;
>
>
>   /**
> - * ProtocolHandlerchain implementation which register all configured Handlers
> - * in the BeanFactory of the Spring context.
> + * ProtocolHandlerchain implementation which instance all the configured handlers
>    *
>    *
>    */
>   @SuppressWarnings("unchecked")
> -public class SpringProtocolHandlerChain implements BeanFactoryPostProcessor, ProtocolHandlerChain, ApplicationContextAware, ApplicationListener, BeanNameAware {
> -
> -    private final List<String>  handlers = new LinkedList<String>();
> -    private Registry<HierarchicalConfiguration>  confProvider;
> -    private Registry<Log>  logProvider;
> +public class JamesProtocolHandlerChain implements ProtocolHandlerChain, Configurable, LogEnabled {
> +
>       private Log log;
> -    private ApplicationContext context;
>       private String coreHandlersPackage;
> -    private String name;
> +    private LinkedList handlers = new LinkedList();
> +    private HierarchicalConfiguration config;
> +    private InstanceFactory factory;
>
> -    public void setConfigurationRegistry(Registry<HierarchicalConfiguration>  confProvider) {
> -        this.confProvider = confProvider;
> -    }
> -
> -    public void setLogRegistry(Registry<Log>  logProvider) {
> -        this.logProvider = logProvider;
> -    }
>
>       public void setCoreHandlersPackage(String coreHandlersPackage) {
>           this.coreHandlersPackage = coreHandlersPackage;
>       }
> -    /*
> -     * (non-Javadoc)
> -     * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
> -     */
> -    public void postProcessBeanFactory(ConfigurableListableBeanFactory arg0) throws BeansException {
> -        HierarchicalConfiguration handlerchainConfig;
> -        BeanDefinitionRegistry registry = (BeanDefinitionRegistry) arg0;
> +
> +    @Resource(name="instanceFactory")
> +    public void setInstanceFactory(InstanceFactory factory) {
> +        this.factory = factory;
> +    }
> +
> +
> +    @PostConstruct
> +    public void init() throws Exception {
> +        HierarchicalConfiguration handlerchainConfig = config.configurationAt("handler.handlerchain");
> +        if (handlerchainConfig.getString("[@coreHandlersPackage]") == null)
> +            handlerchainConfig.addProperty("[@coreHandlersPackage]", coreHandlersPackage);
>
> -        try {
> -            log = logProvider.getForComponent(name);
> -            handlerchainConfig = confProvider.getForComponent(name).configurationAt("handler.handlerchain");
> -            if (handlerchainConfig.getString("[@coreHandlersPackage]") == null)
> -                handlerchainConfig.addProperty("[@coreHandlersPackage]", coreHandlersPackage);
> -
> -            loadHandlers(registry, handlerchainConfig);
> -        } catch (Exception e) {
> -            throw new FatalBeanException("Unable to instance ProtocolHandlerChain",e);
> -        }
> -
> +        loadHandlers(handlerchainConfig);
>
> +        wireExtensibleHandlers();
>       }
> -
>
>       /**
>        * ExtensibleHandler wiring
> @@ -102,14 +80,10 @@ public class SpringProtocolHandlerChain
>        * @throws WiringException
>        */
>       private void wireExtensibleHandlers() throws WiringException {
> -        String[] beanNames = context.getBeanNamesForType(ExtensibleHandler.class);
> -
> -        for (int a = 0; a<  beanNames.length; a++) {
> -            String name = beanNames[a];
> -
> -            // check if the bean is one of our handlers
> -            if (handlers.contains(name)) {
> -                final ExtensibleHandler extensibleHandler = (ExtensibleHandler) context.getBean(name);
> +        for (int a = 0; a<  handlers.size(); a++) {
> +            final Object obj = handlers.get(a);
> +            if (obj instanceof ExtensibleHandler) {
> +                final ExtensibleHandler extensibleHandler = (ExtensibleHandler) obj;
>                   final List<Class<?>>  markerInterfaces = extensibleHandler.getMarkerInterfaces();
>                   for (int i = 0; i<  markerInterfaces.size(); i++) {
>                       final Class<?>  markerInterface = markerInterfaces.get(i);
> @@ -117,6 +91,7 @@ public class SpringProtocolHandlerChain
>                       extensibleHandler.wireExtensions(markerInterface, extensions);
>                   }
>               }
> +
>           }
>
>       }
> @@ -129,38 +104,30 @@ public class SpringProtocolHandlerChain
>        * @param config The configuration
>        * @throws ConfigurationException Get thrown on error
>        */
> -    private void loadClass(BeanDefinitionRegistry registry, String className,
> -            org.apache.commons.configuration.HierarchicalConfiguration config) throws Exception {
> -        final Class<?>  handlerClass = context.getClassLoader().loadClass(className);
> -
> -
> -
> +    private void loadClass(String className, org.apache.commons.configuration.HierarchicalConfiguration config) throws Exception {
> +        Class<?>  clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
> +        Object obj = factory.newInstance(clazz, log, config);
> +
>
>           // if it is a commands handler add it to the map with key as command
>           // name
> -        if (HandlersPackage.class.isAssignableFrom(handlerClass)) {
> -            List<String>  c = ((HandlersPackage) handlerClass.newInstance()).getHandlers();
> +        if (obj instanceof HandlersPackage) {
> +
> +            List<String>  c = ((HandlersPackage) obj).getHandlers();
>
>               for (Iterator<String>  i = c.iterator(); i.hasNext(); ) {
>                   String cName = i.next();
>
>                   HierarchicalConfiguration cmdConf = addHandler(cName);
>
> -                loadClass(registry, cName, cmdConf);
> +                loadClass(cName, cmdConf);
>               }
>
>           } else {
> -        	String beanName = name + ":" + className;
> -        	
> -            confProvider.registerForComponent(beanName, config);
> -            logProvider.registerForComponent(beanName, log);
> -
> -            registry.registerBeanDefinition(beanName, BeanDefinitionBuilder.genericBeanDefinition(className).setLazyInit(false).getBeanDefinition());
> -            // fill the big handler table
> -            handlers.add(beanName);
> +            handlers.add(obj);
>
>               if (log.isInfoEnabled()) {
> -                log.info("Added Handler: " + beanName);
> +                log.info("Added Handler: " + className);
>               }
>
>           }
> @@ -186,17 +153,15 @@ public class SpringProtocolHandlerChain
>        * @see org.apache.james.socket.shared.ProtocolHandlerChain#getHandlers(java.lang.Class)
>        */
>       public<T>  LinkedList<T>  getHandlers(Class<T>  type) {
> -        LinkedList<T>  result = new LinkedList<T>();
> -        Map<String,T>  beans = context.getBeansOfType(type);
> -
> -        for (Iterator<String>  i = handlers.iterator(); i.hasNext(); ) {
> -            String handler = i.next();
> -            T bean = beans.get(handler);
> -            if (bean != null) {
> -                result.add(bean);
> +        LinkedList<T>  classHandlers = new LinkedList<T>();
> +        Iterator hList = handlers.iterator();
> +        while (hList.hasNext()) {
> +            Object obj = hList.next();
> +            if (type.isInstance(obj)) {
> +                classHandlers.add((T)obj);
>               }
>           }
> -        return result;
> +        return classHandlers;
>       }
>
>       /**
> @@ -205,13 +170,13 @@ public class SpringProtocolHandlerChain
>        * @param configuration
>        *            configuration under handlerchain node
>        */
> -    private void loadHandlers(BeanDefinitionRegistry registry, HierarchicalConfiguration commonsConf) throws Exception {
> +    private void loadHandlers(HierarchicalConfiguration commonsConf) throws Exception {
>
>               List<org.apache.commons.configuration.HierarchicalConfiguration>  children = ((HierarchicalConfiguration) commonsConf).configurationsAt("handler");
>
>               String coreCmdName = commonsConf.getString("[@coreHandlersPackage]");
>               // load the core handlers
> -            loadClass(registry, coreCmdName,
> +            loadClass(coreCmdName,
>                       addHandler(coreCmdName));
>
>               // load the configured handlers
> @@ -226,7 +191,7 @@ public class SpringProtocolHandlerChain
>                           if (!className.equals(coreCmdName)) {
>
>                               // load the handler
> -                            loadClass(registry, className, hConf);
> +                            loadClass(className, hConf);
>                           }
>                       }
>                   }
> @@ -236,38 +201,20 @@ public class SpringProtocolHandlerChain
>       }
>
>
> +
>       /*
>        * (non-Javadoc)
> -     * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
> +     * @see org.apache.james.lifecycle.Configurable#configure(org.apache.commons.configuration.HierarchicalConfiguration)
>        */
> -    public void setApplicationContext(ApplicationContext context) throws BeansException {
> -        this.context = context;
> +    public void configure(HierarchicalConfiguration config) throws ConfigurationException {
> +        this.config = config;
>       }
> -
> -
> -    /*
> -     * (non-Javadoc)
> -     * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
> -     */
> -    public void setBeanName(String name) {
> -        this.name = name;
> -    }
> -
> -
> +
>       /*
>        * (non-Javadoc)
> -     * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
> +     * @see org.apache.james.lifecycle.LogEnabled#setLog(org.apache.commons.logging.Log)
>        */
> -    public void onApplicationEvent(ApplicationEvent event) {
> -        if (event instanceof ContextRefreshedEvent) {
> -            try {
> -                // wire the extensions after the startup of the application was complete
> -                // This is needed to be sure that every dependency was injected and every bean was
> -                // initialized
> -                wireExtensibleHandlers();
> -            } catch (WiringException e) {
> -                throw new RuntimeException("Unable to wire handlers", e);
> -            }
> -        }
> +    public void setLog(Log log) {
> +        this.log = log;
>       }
>   }
> \ No newline at end of file
>
> Modified: james/server/trunk/pop3server/src/test/java/org/apache/james/pop3server/AbstractAsyncPOP3ServerTest.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server/src/test/java/org/apache/james/pop3server/AbstractAsyncPOP3ServerTest.java?rev=1005919&r1=1005918&r2=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/pop3server/src/test/java/org/apache/james/pop3server/AbstractAsyncPOP3ServerTest.java (original)
> +++ james/server/trunk/pop3server/src/test/java/org/apache/james/pop3server/AbstractAsyncPOP3ServerTest.java Fri Oct  8 17:38:50 2010
> @@ -51,7 +51,7 @@ import org.apache.james.mailbox.MailboxS
>   import org.apache.james.lifecycle.LifecycleUtil;
>   import org.apache.james.mailbox.store.Authenticator;
>   import org.apache.james.services.MailServer;
> -import org.apache.james.socket.netty.ProtocolHandlerChainImpl;
> +import org.apache.james.socket.JamesProtocolHandlerChain;
>   import org.apache.james.userrepository.MockUsersRepository;
>   import org.apache.james.util.POP3BeforeSMTPHelper;
>   import org.apache.james.util.TestUtil;
> @@ -66,7 +66,7 @@ public abstract class AbstractAsyncPOP3S
>       private MockJSR250Loader serviceManager;
>       protected DNSService dnsservice;
>       protected MockFileSystem fSystem;
> -    protected ProtocolHandlerChainImpl chain;
> +    protected JamesProtocolHandlerChain chain;
>       private InMemoryMailboxManager manager;
>
>       public AbstractAsyncPOP3ServerTest() {
> @@ -76,7 +76,7 @@ public abstract class AbstractAsyncPOP3S
>       protected void setUp() throws Exception {
>           setUpServiceManager();
>
> -        chain = new ProtocolHandlerChainImpl();
> +        chain = new JamesProtocolHandlerChain();
>           chain.setInstanceFactory(serviceManager);
>           chain.setLog(new SimpleLog("ChainLog"));
>
> @@ -86,7 +86,7 @@ public abstract class AbstractAsyncPOP3S
>
>       protected void finishSetUp(POP3TestConfiguration testConfiguration) throws Exception {
>           testConfiguration.init();
> -        chain.configure(testConfiguration.configurationAt("handler.handlerchain"));
> +        chain.configure(testConfiguration);
>           chain.init();
>           initPOP3Server(testConfiguration);
>       }
>
> Modified: james/server/trunk/remotemanager/src/test/java/org/apache/james/remotemanager/AbstractRemoteManagerTest.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager/src/test/java/org/apache/james/remotemanager/AbstractRemoteManagerTest.java?rev=1005919&r1=1005918&r2=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/remotemanager/src/test/java/org/apache/james/remotemanager/AbstractRemoteManagerTest.java (original)
> +++ james/server/trunk/remotemanager/src/test/java/org/apache/james/remotemanager/AbstractRemoteManagerTest.java Fri Oct  8 17:38:50 2010
> @@ -58,7 +58,7 @@ import org.apache.james.management.Spool
>   import org.apache.james.management.SpoolManagementException;
>   import org.apache.james.management.SpoolManagementService;
>   import org.apache.james.services.MailServer;
> -import org.apache.james.socket.netty.ProtocolHandlerChainImpl;
> +import org.apache.james.socket.JamesProtocolHandlerChain;
>   import org.apache.james.test.mock.james.MockUsersStore;
>   import org.apache.james.userrepository.MockUsersRepository;
>   import org.apache.james.util.InternetPrintWriter;
> @@ -78,12 +78,12 @@ public abstract class AbstractRemoteMana
>   	protected DNSService dnsservice;
>   	protected MockFileSystem filesystem;
>   	private MockVirtualUserTableManagementService vutManagement;
> -	protected ProtocolHandlerChainImpl chain;
> +	protected JamesProtocolHandlerChain chain;
>   	
>   	protected void setUp() throws Exception {
>   		setUpFakeLoader();
>
> -		chain = new ProtocolHandlerChainImpl();
> +        chain = new JamesProtocolHandlerChain();
>   	    chain.setInstanceFactory(serviceManager);
>   	    chain.setLog(new SimpleLog("ChainLog"));
>   	
> @@ -100,7 +100,7 @@ public abstract class AbstractRemoteMana
>   	protected void finishSetUp(RemoteManagerTestConfiguration testConfiguration)
>   			throws Exception {
>   		testConfiguration.init();
> -        chain.configure(testConfiguration.configurationAt("handler.handlerchain"));
> +        chain.configure(testConfiguration);
>   		chain.init();
>   		initRemoteManager(testConfiguration);
>   	}
>
> Modified: james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/AbstractSMTPServerTest.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/AbstractSMTPServerTest.java?rev=1005919&r1=1005918&r2=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/AbstractSMTPServerTest.java (original)
> +++ james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/AbstractSMTPServerTest.java Fri Oct  8 17:38:50 2010
> @@ -51,7 +51,7 @@ import org.apache.james.services.FileSys
>   import org.apache.james.services.MailServer;
>   import org.apache.james.services.MockFileSystem;
>   import org.apache.james.services.MockMailServer;
> -import org.apache.james.socket.netty.ProtocolHandlerChainImpl;
> +import org.apache.james.socket.JamesProtocolHandlerChain;
>   import org.apache.james.test.mock.DummyVirtualUserTableStore;
>   import org.apache.james.userrepository.MockUsersRepository;
>   import org.apache.james.util.TestUtil;
> @@ -150,7 +150,7 @@ public abstract class AbstractSMTPServer
>       protected MockMailStore store;
>       protected MockFileSystem fileSystem;
>       protected SMTPServerDNSServiceAdapter dnsAdapter;
> -    protected ProtocolHandlerChainImpl chain;
> +    protected JamesProtocolHandlerChain chain;
>
>       public AbstractSMTPServerTest() {
>           super("AsyncSMTPServerTest");
> @@ -164,7 +164,7 @@ public abstract class AbstractSMTPServer
>           m_testConfiguration = new SMTPTestConfiguration(m_smtpListenerPort);
>
>
> -        chain = new ProtocolHandlerChainImpl();
> +        chain = new JamesProtocolHandlerChain();
>           chain.setInstanceFactory(m_serviceManager);
>           chain.setLog(log);
>           setUpSMTPServer();
> @@ -175,7 +175,7 @@ public abstract class AbstractSMTPServer
>
>       protected void finishSetUp(SMTPTestConfiguration testConfiguration) throws Exception {
>           testConfiguration.init();
> -        chain.configure(testConfiguration.configurationAt("handler.handlerchain"));
> +        chain.configure(testConfiguration);
>           chain.init();
>
>           initSMTPServer(testConfiguration);
>
> Modified: james/server/trunk/spring-common/pom.xml
> URL: http://svn.apache.org/viewvc/james/server/trunk/spring-common/pom.xml?rev=1005919&r1=1005918&r2=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/spring-common/pom.xml (original)
> +++ james/server/trunk/spring-common/pom.xml Fri Oct  8 17:38:50 2010
> @@ -78,21 +78,9 @@
>     <dependencies>
>       <dependency>
>         <groupId>org.apache.james</groupId>
> -<artifactId>james-server-user-api</artifactId>
> -</dependency>
> -<dependency>
> -<groupId>org.apache.james</groupId>
>         <artifactId>james-server-core-api</artifactId>
>       </dependency>
>       <dependency>
> -<groupId>org.apache.james</groupId>
> -<artifactId>james-server-mail-library</artifactId>
> -</dependency>
> -<dependency>
> -<groupId>org.apache.james.protocols</groupId>
> -<artifactId>protocols-api</artifactId>
> -</dependency>
> -<dependency>
>         <groupId>org.springframework</groupId>
>         <artifactId>spring-beans</artifactId>
>       </dependency>
>
> Modified: james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringInstanceFactory.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringInstanceFactory.java?rev=1005919&r1=1005918&r2=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringInstanceFactory.java (original)
> +++ james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringInstanceFactory.java Fri Oct  8 17:38:50 2010
> @@ -19,22 +19,65 @@
>
>   package org.apache.james.container.spring;
>
> +import org.apache.commons.configuration.ConfigurationException;
> +import org.apache.commons.configuration.HierarchicalConfiguration;
> +import org.apache.commons.logging.Log;
> +import org.apache.james.lifecycle.Configurable;
> +import org.apache.james.lifecycle.LogEnabled;
>   import org.apache.james.services.InstanceFactory;
>   import org.springframework.beans.BeansException;
>   import org.springframework.beans.factory.BeanFactory;
>   import org.springframework.beans.factory.BeanFactoryAware;
>   import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
>
> +/**
> + * {@link InstanceFactory} implementation which use a {@link BeanFactory} to handle the loading / injection of resources
> + *
> + *
> + */
>   public class SpringInstanceFactory implements InstanceFactory, BeanFactoryAware{
>       private ConfigurableListableBeanFactory cFactory;
>
>
> +
> +    /*
> +     * (non-Javadoc)
> +     * @see org.apache.james.services.InstanceFactory#newInstance(java.lang.Class)
> +     */
> +    public<T>  T newInstance(Class<T>  clazz) throws InstanceException {
> +        return newInstance(clazz, null, null);
> +    }
> +
>       /*
>        * (non-Javadoc)
> -     * @see org.apache.james.api.kernel.InstanceFactory#newInstance(java.lang.String)
> +     * @see org.apache.james.services.InstanceFactory#newInstance(java.lang.Class, org.apache.commons.logging.Log, org.apache.commons.configuration.HierarchicalConfiguration)
>        */
> -    public Object newInstance(String className) throws InstanceException, ClassNotFoundException {
> -        return cFactory.createBean(cFactory.getBeanClassLoader().loadClass(className));
> +    @SuppressWarnings("unchecked")
> +    public<T>  T newInstance(Class<T>  clazz, Log log, HierarchicalConfiguration config) throws InstanceException {
> +        try {
> +            Object obj = clazz.newInstance();
> +            if (log != null) {
> +                if (obj instanceof LogEnabled) {
> +                    ((LogEnabled) obj).setLog(log);
> +                }
> +            }
> +            if (config != null) {
> +                if (obj instanceof Configurable) {
> +                    try {
> +                        ((Configurable) obj).configure(config);
> +                    } catch (ConfigurationException e) {
> +                        throw new InstanceException("Unable to config " + obj);
> +                    }
> +                }
> +            }
> +            cFactory.autowireBean(obj);
> +            return (T)cFactory.initializeBean(obj, obj.toString());
> +
> +        } catch (InstantiationException e) {
> +            throw new InstanceException("Unable to instance " + clazz , e);
> +        } catch (IllegalAccessException e) {
> +            throw new InstanceException("Unable to instance " + clazz , e);
> +        }
>       }
>
>       /*
>
> Modified: james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/CommonsConfigurableBeanPostProcessor.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/CommonsConfigurableBeanPostProcessor.java?rev=1005919&r1=1005918&r2=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/CommonsConfigurableBeanPostProcessor.java (original)
> +++ james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/CommonsConfigurableBeanPostProcessor.java Fri Oct  8 17:38:50 2010
> @@ -19,7 +19,6 @@
>   package org.apache.james.container.spring.lifecycle;
>
>   import org.apache.commons.configuration.HierarchicalConfiguration;
> -import org.apache.james.container.spring.Registry;
>   import org.apache.james.lifecycle.Configurable;
>
>   /**
> @@ -27,28 +26,24 @@ import org.apache.james.lifecycle.Config
>    *
>    *
>    */
> -public class CommonsConfigurableBeanPostProcessor extends
> -		AbstractLifeCycleBeanPostProcessor<Configurable>  {
> +public class CommonsConfigurableBeanPostProcessor extends RestrictedLifeCycleBeanPostProcessor<Configurable>  {
>
> -	private Registry<HierarchicalConfiguration>  provider;
> -	
> -	@Override
> -	protected void executeLifecycleMethodBeforeInit(Configurable bean, String beanname) throws Exception {
> -		HierarchicalConfiguration beanConfig = provider.getForComponent(beanname);
> -		if(beanConfig != null) {
> -		    bean.configure(beanConfig);
> -		}
> -	}
> +    private ConfigurationProvider provider;
>
> +    @Override
> +    protected void executeLifecycleMethodBeforeInitChecked(Configurable bean, String beanname) throws Exception {
> +        HierarchicalConfiguration config = provider.getConfiguration(beanname);
> +        bean.configure(config);
>
> +    }
>
> -	public void setConfigurationRegistry(Registry<HierarchicalConfiguration>  provider) {
> -		this.provider = provider;
> -	}
> -
> -	@Override
> -	protected Class<Configurable>  getLifeCycleInterface() {
> -		return Configurable.class;
> -	}
> +    public void setConfigurationProvider(ConfigurationProvider provider) {
> +        this.provider = provider;
> +    }
> +
> +    @Override
> +    protected Class<Configurable>  getLifeCycleInterface() {
> +        return Configurable.class;
> +    }
>
>   }
>
> Added: james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/ConfigurationProvider.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/ConfigurationProvider.java?rev=1005919&view=auto
> ==============================================================================
> --- james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/ConfigurationProvider.java (added)
> +++ james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/ConfigurationProvider.java Fri Oct  8 17:38:50 2010
> @@ -0,0 +1,39 @@
> +/****************************************************************
> + * Licensed to the Apache Software Foundation (ASF) under one   *
> + * or more contributor license agreements.  See the NOTICE file *
> + * distributed with this work for additional information        *
> + * regarding copyright ownership.  The ASF licenses this file   *
> + * to you under the Apache License, Version 2.0 (the            *
> + * "License"); you may not use this file except in compliance   *
> + * with the License.  You may obtain a copy of the License at   *
> + *                                                              *
> + *   http://www.apache.org/licenses/LICENSE-2.0                 *
> + *                                                              *
> + * Unless required by applicable law or agreed to in writing,   *
> + * software distributed under the License is distributed on an  *
> + * "AS IS" BASIS, 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.apache.james.container.spring.lifecycle;
> +
> +import org.apache.commons.configuration.ConfigurationException;
> +import org.apache.commons.configuration.HierarchicalConfiguration;
> +
> +/**
> + * Load {@link HierarchicalConfiguration} for beans
> + *
> + *
> + */
> +public interface ConfigurationProvider {
> +
> +    /**
> +     * Load the configuration for the bean with the given name
> +     *
> +     * @param beanName
> +     * @return config
> +     * @throws ConfigurationException
> +     */
> +    public HierarchicalConfiguration getConfiguration(String beanName) throws ConfigurationException;
> +}
>
> Modified: james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/LogEnabledBeanPostProcessor.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/LogEnabledBeanPostProcessor.java?rev=1005919&r1=1005918&r2=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/LogEnabledBeanPostProcessor.java (original)
> +++ james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/LogEnabledBeanPostProcessor.java Fri Oct  8 17:38:50 2010
> @@ -18,8 +18,6 @@
>    ****************************************************************/
>   package org.apache.james.container.spring.lifecycle;
>
> -import org.apache.commons.logging.Log;
> -import org.apache.james.container.spring.Registry;
>   import org.apache.james.lifecycle.LogEnabled;
>
>   /**
> @@ -27,21 +25,22 @@ import org.apache.james.lifecycle.LogEna
>    *
>    *
>    */
> -public class LogEnabledBeanPostProcessor extends AbstractLifeCycleBeanPostProcessor<LogEnabled>  {
> +public class LogEnabledBeanPostProcessor extends RestrictedLifeCycleBeanPostProcessor<LogEnabled>  {
>
> -	private Registry<Log>  provider;
> +    private LogProvider provider;
> +
> +    @Override
> +    protected Class<LogEnabled>  getLifeCycleInterface() {
> +        return LogEnabled.class;
> +    }
> +
> +    public void setLogProvider(LogProvider provider) {
> +        this.provider = provider;
> +    }
> +
> +    @Override
> +    protected void executeLifecycleMethodBeforeInitChecked(LogEnabled bean, String beanname) throws Exception {
> +        bean.setLog(provider.getLog(beanname));
> +    }
>
> -	@Override
> -	protected void executeLifecycleMethodBeforeInit(LogEnabled bean, String beanname) throws Exception {
> -		bean.setLog(provider.getForComponent(beanname));
> -	}
> -
> -	@Override
> -	protected Class<LogEnabled>  getLifeCycleInterface() {
> -		return LogEnabled.class;
> -	}	
> -	
> -	public void setLogRegistry(Registry<Log>  provider) {
> -		this.provider = provider;
> -	}
>   }
>
> Added: james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/LogProvider.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/LogProvider.java?rev=1005919&view=auto
> ==============================================================================
> --- james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/LogProvider.java (added)
> +++ james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/LogProvider.java Fri Oct  8 17:38:50 2010
> @@ -0,0 +1,37 @@
> +/****************************************************************
> + * Licensed to the Apache Software Foundation (ASF) under one   *
> + * or more contributor license agreements.  See the NOTICE file *
> + * distributed with this work for additional information        *
> + * regarding copyright ownership.  The ASF licenses this file   *
> + * to you under the Apache License, Version 2.0 (the            *
> + * "License"); you may not use this file except in compliance   *
> + * with the License.  You may obtain a copy of the License at   *
> + *                                                              *
> + *   http://www.apache.org/licenses/LICENSE-2.0                 *
> + *                                                              *
> + * Unless required by applicable law or agreed to in writing,   *
> + * software distributed under the License is distributed on an  *
> + * "AS IS" BASIS, 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.apache.james.container.spring.lifecycle;
> +
> +import org.apache.commons.logging.Log;
> +
> +/**
> + * Provide {@link Log} instances for Beans
> + *
> + *
> + */
> +public interface LogProvider {
> +
> +    /**
> +     * Return the Log for the bean with the given name
> +     *
> +     * @param name
> +     * @return log
> +     */
> +    public Log getLog(String beanName);
> +}
>
> Copied: james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringConfigurationProvider.java (from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringConfigurationRegistry.java)
> URL: http://svn.apache.org/viewvc/james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringConfigurationProvider.java?p2=james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringConfigurationProvider.java&p1=james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringConfigurationRegistry.java&r1=1005333&r2=1005919&rev=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringConfigurationRegistry.java (original)
> +++ james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringConfigurationProvider.java Fri Oct  8 17:38:50 2010
> @@ -18,7 +18,7 @@
>    ****************************************************************/
>   package org.apache.james.container.spring.lifecycle;
>
> -public class OsgiSpringConfigurationRegistry extends SpringConfigurationRegistry{
> +public class OsgiSpringConfigurationProvider extends SpringConfigurationProvider{
>
>   	/**
>   	 * Load configuration from classpath.
>
> Copied: james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringLogProvider.java (from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringLogRegistry.java)
> URL: http://svn.apache.org/viewvc/james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringLogProvider.java?p2=james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringLogProvider.java&p1=james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringLogRegistry.java&r1=1005333&r2=1005919&rev=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringLogRegistry.java (original)
> +++ james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/OsgiSpringLogProvider.java Fri Oct  8 17:38:50 2010
> @@ -21,7 +21,7 @@ package org.apache.james.container.sprin
>   import org.apache.commons.logging.Log;
>   import org.apache.commons.logging.LogFactory;
>
> -public class OsgiSpringLogRegistry extends SpringLogRegistry{
> +public class OsgiSpringLogProvider extends SpringLogProvider{
>
>   	/**
>   	 * Use {@link LogFactory} to create a Log
>
> Added: james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/RestrictedLifeCycleBeanPostProcessor.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/RestrictedLifeCycleBeanPostProcessor.java?rev=1005919&view=auto
> ==============================================================================
> --- james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/RestrictedLifeCycleBeanPostProcessor.java (added)
> +++ james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/RestrictedLifeCycleBeanPostProcessor.java Fri Oct  8 17:38:50 2010
> @@ -0,0 +1,81 @@
> +/****************************************************************
> + * Licensed to the Apache Software Foundation (ASF) under one   *
> + * or more contributor license agreements.  See the NOTICE file *
> + * distributed with this work for additional information        *
> + * regarding copyright ownership.  The ASF licenses this file   *
> + * to you under the Apache License, Version 2.0 (the            *
> + * "License"); you may not use this file except in compliance   *
> + * with the License.  You may obtain a copy of the License at   *
> + *                                                              *
> + *   http://www.apache.org/licenses/LICENSE-2.0                 *
> + *                                                              *
> + * Unless required by applicable law or agreed to in writing,   *
> + * software distributed under the License is distributed on an  *
> + * "AS IS" BASIS, 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.apache.james.container.spring.lifecycle;
> +
> +import org.springframework.beans.BeansException;
> +import org.springframework.context.ApplicationContext;
> +import org.springframework.context.ApplicationContextAware;
> +
> +/**
> + * {@link AbstractLifeCycleBeanPostProcessor} sub-class which will only try to apply LifeCycle callbacks on beans which are registered on the {@link ApplicationContext}.
> + *
> + *
> + * @param<T>
> + */
> +public abstract class RestrictedLifeCycleBeanPostProcessor<T>  extends AbstractLifeCycleBeanPostProcessor<T>  implements ApplicationContextAware{
> +
> +    private ApplicationContext context;
> +
> +    @Override
> +    protected final void executeLifecycleMethodAfterInit(T bean, String beanname) throws Exception {
> +        // check if the bean is registered in the context. If not it was create by the InstanceFactory and so there is no need to execute the callback
> +        if (context.containsBeanDefinition(beanname)) {
> +            executeLifecycleMethodAfterInitChecked(bean, beanname);
> +        }
> +    }
> +
> +    @Override
> +    protected final void executeLifecycleMethodBeforeInit(T bean, String beanname) throws Exception {
> +        // check if the bean is registered in the context. If not it was create by the InstanceFactory and so there is no need to execute the callback
> +        if (context.containsBeanDefinition(beanname)) {
> +            executeLifecycleMethodBeforeInitChecked(bean, beanname);
> +        }
> +    }
> +
> +    /*
> +     * (non-Javadoc)
> +     * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
> +     */
> +    public void setApplicationContext(ApplicationContext context) throws BeansException {
> +        this.context = context;
> +    }
> +
> +    /**
> +     * Execute method on bean which is registered in the {@link ApplicationContext}. Subclasses should override this if needed
> +     *
> +     * @param bean
> +     * @param beanname
> +     * @throws Exception
> +     */
> +    protected void executeLifecycleMethodAfterInitChecked(T bean, String beanname) throws Exception {
> +
> +    }
> +
> +    /**
> +     * Execute method on bean which is registered in the {@link ApplicationContext}. Subclasses should override this if needed
> +     *
> +     * @param bean
> +     * @param beanname
> +     * @throws Exception
> +     */
> +    protected void executeLifecycleMethodBeforeInitChecked(T bean, String beanname) throws Exception {
> +
> +    }
> +
> +}
>
> Copied: james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationProvider.java (from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationRegistry.java)
> URL: http://svn.apache.org/viewvc/james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationProvider.java?p2=james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationProvider.java&p1=james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationRegistry.java&r1=1005333&r2=1005919&rev=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationRegistry.java (original)
> +++ james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationProvider.java Fri Oct  8 17:38:50 2010
> @@ -26,7 +26,6 @@ import java.util.Map;
>   import org.apache.commons.configuration.ConfigurationException;
>   import org.apache.commons.configuration.HierarchicalConfiguration;
>   import org.apache.commons.configuration.XMLConfiguration;
> -import org.apache.james.container.spring.Registry;
>   import org.springframework.beans.factory.InitializingBean;
>   import org.springframework.context.ResourceLoaderAware;
>   import org.springframework.core.io.Resource;
> @@ -37,33 +36,12 @@ import org.springframework.core.io.Resou
>    *
>    *
>    */
> -public class SpringConfigurationRegistry implements Registry<HierarchicalConfiguration>, ResourceLoaderAware, InitializingBean {
> +public class SpringConfigurationProvider implements ConfigurationProvider, ResourceLoaderAware, InitializingBean {
>
>   	private ResourceLoader loader;
>   	private Map<String,HierarchicalConfiguration>  confMap = new HashMap<String,HierarchicalConfiguration>();
>       private Map<String,String>  resources;
>
> -	/*
> -	 * (non-Javadoc)
> -	 * @see org.apache.james.container.spring.Registry#getForComponent(java.lang.String)
> -	 */
> -	public HierarchicalConfiguration getForComponent(String name)
> -			throws RegistryException {
> -	    HierarchicalConfiguration conf = confMap.get(name);
> -	    if (conf != null) {
> -	        return conf;
> -	    } else {
> -	        Resource r = loader.getResource(getConfigPrefix()+ name + ".xml");
> -	        if (r.exists()) {
> -	            try {
> -                    return getConfig(r);
> -                } catch (Exception e) {
> -                    throw new RegistryException("Unable to load configuration for component " + name,e);
> -                }
> -	        }
> -	    }
> -	    throw new RegistryException("Unable to load configuration for component " + name);
> -	}
>
>
>   	/**
> @@ -117,9 +95,26 @@ public class SpringConfigurationRegistry
>               while (it.hasNext()) {
>                   String key = it.next();
>                   String value = resources.get(key);
> -                confMap.put(key,getForComponent(value));
> +                confMap.put(key,getConfiguration(value));
> +            }
> +        }
> +    }
> +
> +    public HierarchicalConfiguration getConfiguration(String name) throws ConfigurationException {
> +        HierarchicalConfiguration conf = confMap.get(name);
> +        if (conf != null) {
> +            return conf;
> +        } else {
> +            Resource r = loader.getResource(getConfigPrefix()+ name + ".xml");
> +            if (r.exists()) {
> +                try {
> +                    return getConfig(r);
> +                } catch (Exception e) {
> +                    throw new ConfigurationException("Unable to load configuration for component " + name, e);
> +                }
>               }
>           }
> +        throw new ConfigurationException("Unable to load configuration for component " + name);
>       }
>
>   }
>
> Copied: james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringLogProvider.java (from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringLogRegistry.java)
> URL: http://svn.apache.org/viewvc/james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringLogProvider.java?p2=james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringLogProvider.java&p1=james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringLogRegistry.java&r1=1005333&r2=1005919&rev=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringLogRegistry.java (original)
> +++ james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/lifecycle/SpringLogProvider.java Fri Oct  8 17:38:50 2010
> @@ -24,7 +24,6 @@ import java.util.Map;
>
>   import org.apache.commons.logging.Log;
>   import org.apache.commons.logging.impl.Log4JLogger;
> -import org.apache.james.container.spring.Registry;
>   import org.springframework.beans.factory.InitializingBean;
>
>   /**
> @@ -32,25 +31,12 @@ import org.springframework.beans.factory
>    *
>    *
>    */
> -public class SpringLogRegistry implements Registry<Log>, InitializingBean {
> +public class SpringLogProvider implements LogProvider, InitializingBean {
>
>       private final Map<String,Log>  logMap = new HashMap<String,Log>();
>       private Map<String, String>  logs;
>       private final static String PREFIX = "james.";
>
> -    /*
> -     * (non-Javadoc)
> -     * @see org.apache.james.container.spring.Registry#getForComponent(java.lang.String)
> -     */
> -	public Log getForComponent(String componentname) throws RegistryException{
> -	    Log log = logMap.get(componentname);
> -	    if (log != null) {
> -	        return log;
> -	    } else {
> -	        return createLog(PREFIX + componentname);
> -	    }
> -	}
> -	
>   	/**
>   	 * Use {@link Log4JLogger} to create the Log
>   	 *
> @@ -88,4 +74,13 @@ public class SpringLogRegistry implement
>               }
>           }
>       }
> +
> +    public Log getLog(String name) {
> +        Log log = logMap.get(name);
> +        if (log != null) {
> +            return log;
> +        } else {
> +            return createLog(PREFIX + name);
> +        }
> +    }
>   }
>
> Modified: james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml
> URL: http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml?rev=1005919&r1=1005918&r2=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml (original)
> +++ james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml Fri Oct  8 17:38:50 2010
> @@ -70,14 +70,13 @@
>       -->
>
>       <bean class="org.apache.james.container.spring.lifecycle.CommonsConfigurableBeanPostProcessor">
> -<property name="configurationRegistry" ref="configurationRegistry" />
> +<property name="configurationProvider" ref="configurationProvider" />
>           <property name="order" value="1" />
>       </bean>
>
> -<bean id="configurationRegistry" class="org.apache.james.container.spring.lifecycle.SpringConfigurationRegistry">
> +<bean id="configurationProvider" class="org.apache.james.container.spring.lifecycle.SpringConfigurationProvider">
>           <property name="configurationMappings">
>               <map>
> -<entry key="mailboxmanager" value="imapserver" />
>                   <entry key="mailetcontext" value="James"/>
>                   <entry key="lmtpProtocolHandlerChain" value="lmtpserver"/>
>                   <entry key="smtpProtocolHandlerChain" value="smtpserver"/>
> @@ -99,11 +98,11 @@
>       </bean>
>
>       <bean class="org.apache.james.container.spring.lifecycle.LogEnabledBeanPostProcessor">
> -<property name="logRegistry" ref="logRegistry" />
> +<property name="logProvider" ref="logProvider" />
>           <property name="order" value="0" />
>       </bean>
>
> -<bean id="logRegistry" class="org.apache.james.container.spring.lifecycle.SpringLogRegistry">
> +<bean id="logProvider" class="org.apache.james.container.spring.lifecycle.SpringLogProvider">
>           <property name="logMappings">
>               <map>
>                   <entry key="lmtpProtocolHandlerChain" value="lmtpserver"/>
> @@ -112,7 +111,6 @@
>                   <entry key="remoteProtocolHandlerChain" value="remoteManager"/>
>                   <entry key="mailProcessor" value="spoolmanager"/>
>                   <entry key="mailserver" value="James"/>
> -<entry key="poster" value="James"/>
>               </map>
>           </property>
>       </bean>
> @@ -204,9 +202,7 @@
>           <property name="protocolHandlerChain" ref="remoteProtocolHandlerChain"/>
>       </bean>
>
> -<bean id="remoteProtocolHandlerChain" class="org.apache.james.container.spring.SpringProtocolHandlerChain">
> -<property name="logRegistry" ref="logRegistry"/>
> -<property name="configurationRegistry" ref="configurationRegistry"/>
> +<bean id="remoteProtocolHandlerChain" class="org.apache.james.socket.JamesProtocolHandlerChain">
>           <property name="coreHandlersPackage" value="org.apache.james.remotemanager.core.CoreCmdHandlerLoader"/>
>       </bean>
>
> @@ -218,9 +214,7 @@
>           <property name="protocolHandlerChain" ref="pop3ProtocolHandlerChain"/>
>       </bean>
>
> -<bean id="pop3ProtocolHandlerChain" class="org.apache.james.container.spring.SpringProtocolHandlerChain">
> -<property name="logRegistry" ref="logRegistry"/>
> -<property name="configurationRegistry" ref="configurationRegistry"/>
> +<bean id="pop3ProtocolHandlerChain" class="org.apache.james.socket.JamesProtocolHandlerChain">
>           <property name="coreHandlersPackage" value="org.apache.james.pop3server.core.CoreCmdHandlerLoader"/>
>       </bean>
>
> @@ -229,9 +223,7 @@
>           <property name="protocolHandlerChain" ref="smtpProtocolHandlerChain"/>
>       </bean>
>
> -<bean id="smtpProtocolHandlerChain" class="org.apache.james.container.spring.SpringProtocolHandlerChain">
> -<property name="logRegistry" ref="logRegistry"/>
> -<property name="configurationRegistry" ref="configurationRegistry"/>
> +<bean id="smtpProtocolHandlerChain" class="org.apache.james.socket.JamesProtocolHandlerChain">
>           <property name="coreHandlersPackage" value="org.apache.james.smtpserver.CoreCmdHandlerLoader"/>
>       </bean>
>
> @@ -240,9 +232,7 @@
>           <property name="protocolHandlerChain" ref="lmtpProtocolHandlerChain"/>
>       </bean>
>
> -<bean id="lmtpProtocolHandlerChain" class="org.apache.james.container.spring.SpringProtocolHandlerChain">
> -<property name="logRegistry" ref="logRegistry"/>
> -<property name="configurationRegistry" ref="configurationRegistry"/>
> +<bean id="lmtpProtocolHandlerChain" class="org.apache.james.socket.JamesProtocolHandlerChain">
>           <property name="coreHandlersPackage" value="org.apache.james.lmtpserver.CoreCmdHandlerLoader"/>
>       </bean>
>
> @@ -250,14 +240,12 @@
>       <bean id="fetchmail" class="org.apache.james.fetchmail.FetchScheduler" />
>
>       <!-- The High Level Storage block -->
> -<bean id="mailstore" class="org.apache.james.container.spring.SpringMailStore" />
> +<bean id="mailstore" class="org.apache.james.mailstore.JamesMailStore" />
>
>
>       <!-- The User Storage block -->
> -<bean id="users-store" class="org.apache.james.container.spring.SpringUsersStore">
> +<bean id="users-store" class="org.apache.james.impl.user.JamesUsersStore">
>           <property name="defaultRepository" value="LocalUsers"/>
> -<property name="logRegistry" ref="logRegistry"/>
> -<property name="configurationRegistry" ref="configurationRegistry"/>
>       </bean>
>
>       <!-- This is needed to link the smtpserver to the local user repository
> @@ -281,10 +269,8 @@
>       <bean id="virtualusertablemanagementservice" class="org.apache.james.impl.vut.VirtualUserTableManagement" />
>
>       <!-- VirtualUserTable Store -->
> -<bean id="virtualusertable-store" class="org.apache.james.container.spring.SpringVirtualUserTableStore">
> +<bean id="virtualusertable-store" class="org.apache.james.impl.vut.JamesVirtualUserTableStore">
>           <property name="defaultTable" value="DefaultVirtualUserTable"/>
> -<property name="logRegistry" ref="logRegistry"/>
> -<property name="configurationRegistry" ref="configurationRegistry"/>
>       </bean>
>
>
>
> Copied: james/server/trunk/user-library/src/main/java/org/apache/james/impl/AbstractStore.java (from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/AbstractStore.java)
> URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/impl/AbstractStore.java?p2=james/server/trunk/user-library/src/main/java/org/apache/james/impl/AbstractStore.java&p1=james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/AbstractStore.java&r1=1005333&r2=1005919&rev=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/AbstractStore.java (original)
> +++ james/server/trunk/user-library/src/main/java/org/apache/james/impl/AbstractStore.java Fri Oct  8 17:38:50 2010
> @@ -16,119 +16,79 @@
>    * specific language governing permissions and limitations      *
>    * under the License.                                           *
>    ****************************************************************/
> -package org.apache.james.container.spring;
> +package org.apache.james.impl;
>
> -import java.util.ArrayList;
>   import java.util.Collections;
> +import java.util.HashMap;
>   import java.util.List;
> +import java.util.Map;
>
> +import javax.annotation.PostConstruct;
> +import javax.annotation.Resource;
> +
> +import org.apache.commons.configuration.ConfigurationException;
>   import org.apache.commons.configuration.HierarchicalConfiguration;
>   import org.apache.commons.logging.Log;
> -import org.apache.james.container.spring.Registry.RegistryException;
> -import org.springframework.beans.BeansException;
> -import org.springframework.beans.FatalBeanException;
> -import org.springframework.beans.factory.BeanNameAware;
> -import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
> -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
> -import org.springframework.beans.factory.support.BeanDefinitionBuilder;
> -import org.springframework.beans.factory.support.BeanDefinitionRegistry;
> -import org.springframework.context.ApplicationContext;
> -import org.springframework.context.ApplicationContextAware;
> +import org.apache.james.lifecycle.Configurable;
> +import org.apache.james.lifecycle.LogEnabled;
> +import org.apache.james.services.InstanceFactory;
>
>   /**
>    * Abstract base class which implement Store behavior based on Spring
>    *
>    */
> -public abstract class AbstractStore implements BeanFactoryPostProcessor, BeanNameAware, ApplicationContextAware{
> +public abstract class AbstractStore<E>  implements Configurable, LogEnabled {
>
>
> -    protected String beanName;
> -    protected ApplicationContext context;
> -    protected Registry<Log>  logProvider;
> -    protected Registry<HierarchicalConfiguration>  confProvider;
>       protected Log log;
>
> -    protected final List<String>  objects = Collections.synchronizedList(new ArrayList<String>());
> -
> -    public void setConfigurationRegistry(Registry<HierarchicalConfiguration>  confProvider) {
> -        this.confProvider = confProvider;
> +    protected final Map<String, E>  objects = Collections.synchronizedMap(new HashMap<String, E>());
> +    private InstanceFactory factory;
> +    private HierarchicalConfiguration config;
> +
> +
> +    @Resource(name="instanceFactory")
> +    public void setInstanceFactory(InstanceFactory factory) {
> +        this.factory = factory;
>       }
> -
> -    public void setLogRegistry(Registry<Log>  logProvider) {
> -        this.logProvider = logProvider;
> -    }
> -
>
> -    /*
> -     * (non-Javadoc)
> -     *
> -     * @see
> -     * org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang
> -     * .String)
> -     */
> -    public void setBeanName(String beanName) {
> -        this.beanName = beanName;
> +    public void setLog(Log log) {
> +        this.log = log;
>       }
>
> -    /*
> -     * (non-Javadoc)
> -     *
> -     * @see
> -     * org.springframework.context.ApplicationContextAware#setApplicationContext
> -     * (org.springframework.context.ApplicationContext)
> -     */
> -    public void setApplicationContext(ApplicationContext context) throws BeansException {
> -        this.context = context;
> +    public void configure(HierarchicalConfiguration config) throws ConfigurationException {
> +        this.config = config;
>       }
>
> -    /*
> -     * (non-Javadoc)
> -     * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
> -     */
> -    public void postProcessBeanFactory(ConfigurableListableBeanFactory arg0) throws BeansException {
> -        // Store the log object for later usage
> -
> -        BeanDefinitionRegistry registry = (BeanDefinitionRegistry) arg0;
> -
> -        try {
> -            log = logProvider.getForComponent(beanName);
> -            List<HierarchicalConfiguration>  repConfs = getSubConfigurations(confProvider.getForComponent(beanName));
> -            ClassLoader theClassLoader = arg0.getBeanClassLoader();
> -            for (int i = 0; i<  repConfs.size(); i++) {
> -                final HierarchicalConfiguration repConf = repConfs.get(i);
> -                String repName = repConf.getString("[@name]", null);
> -                String repClass = repConf.getString("[@class]");
> -
> -                if (repName == null) {
> -                    repName = repClass;
> -                }
> -
> -                if (log.isDebugEnabled()) {
> -                    log.debug("Starting " + repClass);
> -                }
> -
> -                Class<?>  objectClass = (Class<?>) theClassLoader.loadClass(repClass);
> -
> -                // register configuration and log for the bean
> -                confProvider.registerForComponent(repName, repConf);
> -                logProvider.registerForComponent(repName, log);
> -
> -                registry.registerBeanDefinition(repName, BeanDefinitionBuilder.rootBeanDefinition(objectClass).setLazyInit(false).getBeanDefinition());
> -
> -                objects.add(repName);
> -
> -                if (log.isInfoEnabled()) {
> -                    StringBuffer logBuffer = new StringBuffer(64).append("Bean  ").append(repName).append(" started.");
> -                    log.info(logBuffer.toString());
> -                }
> +    @PostConstruct
> +    @SuppressWarnings("unchecked")
> +    public void init() throws Exception {
> +        ClassLoader loader = Thread.currentThread().getContextClassLoader();
> +        List<HierarchicalConfiguration>  repConfs = getSubConfigurations(config);
> +        for (int i = 0; i<  repConfs.size(); i++) {
> +            final HierarchicalConfiguration repConf = repConfs.get(i);
> +            String repName = repConf.getString("[@name]", null);
> +            String repClass = repConf.getString("[@class]");
> +
> +            if (repName == null) {
> +                repName = repClass;
> +            }
> +
> +            if (log.isDebugEnabled()) {
> +                log.debug("Starting " + repClass);
> +            }
> +
> +
> +            objects.put(repName, (E)factory.newInstance(loader.loadClass(repClass), log, repConf));
> +
> +            if (log.isInfoEnabled()) {
> +                StringBuffer logBuffer = new StringBuffer(64).append("Bean  ").append(repName).append(" started.");
> +                log.info(logBuffer.toString());
>               }
> -        } catch (RegistryException e) {
> -            throw new FatalBeanException("Unable to read configuration for " + beanName, e);
> -        } catch (ClassNotFoundException e) {
> -            throw new FatalBeanException("Unable to instance class", e);
>           }
> -
> +
>       }
>
> +
>       protected abstract List<HierarchicalConfiguration>  getSubConfigurations(HierarchicalConfiguration rootConf);
>   }
>
> Copied: james/server/trunk/user-library/src/main/java/org/apache/james/impl/user/JamesUsersStore.java (from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringUsersStore.java)
> URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/impl/user/JamesUsersStore.java?p2=james/server/trunk/user-library/src/main/java/org/apache/james/impl/user/JamesUsersStore.java&p1=james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringUsersStore.java&r1=1005333&r2=1005919&rev=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringUsersStore.java (original)
> +++ james/server/trunk/user-library/src/main/java/org/apache/james/impl/user/JamesUsersStore.java Fri Oct  8 17:38:50 2010
> @@ -16,7 +16,7 @@
>    * specific language governing permissions and limitations      *
>    * under the License.                                           *
>    ****************************************************************/
> -package org.apache.james.container.spring;
> +package org.apache.james.impl.user;
>
>   import java.util.Iterator;
>   import java.util.List;
> @@ -24,15 +24,13 @@ import java.util.List;
>   import org.apache.commons.configuration.HierarchicalConfiguration;
>   import org.apache.james.api.user.UsersRepository;
>   import org.apache.james.api.user.UsersStore;
> -import org.springframework.beans.factory.NoSuchBeanDefinitionException;
> +import org.apache.james.impl.AbstractStore;
>
>   /**
> - * UsersStore implementation which will parse the configuration file for users-store and add every configured repository
> - * to the Spring BeanFactory.
> - * @author norman
> + * UsersStore implementation which will parse the configuration file for users-store and add every configured repository
>    *
>    */
> -public class SpringUsersStore extends AbstractStore implements UsersStore {
> +public class JamesUsersStore extends AbstractStore<UsersRepository>  implements UsersStore {
>
>       private String defaultName;
>
> @@ -47,15 +45,8 @@ public class SpringUsersStore extends Ab
>               name = defaultName;
>           }
>
> -        UsersRepository response = null;
> +        UsersRepository response = objects.get(name);
>
> -        if (objects.contains(name)) {
> -            try {
> -                response = (UsersRepository) context.getBean(name, UsersRepository.class);
> -            } catch (NoSuchBeanDefinitionException e) {
> -                // Just catch the exception
> -            }
> -        }
>           if ((response == null)&&  (log.isWarnEnabled())) {
>               log.warn("No users repository called: " + name);
>           }
> @@ -72,7 +63,7 @@ public class SpringUsersStore extends Ab
>        * @see org.apache.james.api.user.UsersStore#getRepositoryNames()
>        */
>       public Iterator<String>  getRepositoryNames() {
> -        return objects.iterator();
> +        return objects.keySet().iterator();
>       }
>
>       @SuppressWarnings("unchecked")
>
> Copied: james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/JamesVirtualUserTableStore.java (from r1005333, james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringVirtualUserTableStore.java)
> URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/JamesVirtualUserTableStore.java?p2=james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/JamesVirtualUserTableStore.java&p1=james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringVirtualUserTableStore.java&r1=1005333&r2=1005919&rev=1005919&view=diff
> ==============================================================================
> --- james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/SpringVirtualUserTableStore.java (original)
> +++ james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/JamesVirtualUserTableStore.java Fri Oct  8 17:38:50 2010
> @@ -16,16 +16,16 @@
>    * specific language governing permissions and limitations      *
>    * under the License.                                           *
>    ****************************************************************/
> -package org.apache.james.container.spring;
> +package org.apache.james.impl.vut;
>
>   import java.util.List;
>
>   import org.apache.commons.configuration.HierarchicalConfiguration;
>   import org.apache.james.api.vut.VirtualUserTable;
>   import org.apache.james.api.vut.VirtualUserTableStore;
> -import org.springframework.beans.factory.NoSuchBeanDefinitionException;
> +import org.apache.james.impl.AbstractStore;
>
> -public class SpringVirtualUserTableStore extends AbstractStore implements VirtualUserTableStore{
> +public class JamesVirtualUserTableStore extends AbstractStore<VirtualUserTable>  implements VirtualUserTableStore{
>
>       private String defaultName;
>
> @@ -49,15 +49,8 @@ public class SpringVirtualUserTableStore
>               name = defaultName;
>           }
>
> -        VirtualUserTable response = null;
> +        VirtualUserTable response = objects.get(name);
>
> -        if (objects.contains(name)) {
> -            try {
> -                response = (VirtualUserTable) context.getBean(name, VirtualUserTable.class);
> -            } catch (NoSuchBeanDefinitionException e) {
> -                // Just catch the exception
> -            }
> -        }
>           if ((response == null)&&  (log.isWarnEnabled())) {
>               log.warn("No VirtualUserTable called: " + name);
>           }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message