You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by er...@apache.org on 2010/12/27 14:48:26 UTC

svn commit: r1053066 - in /james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean: factory/ factory/mailetcontainer/ factory/mailrepositorystore/ factorypostprocessor/ postprocessor/

Author: eric
Date: Mon Dec 27 13:48:25 2010
New Revision: 1053066

URL: http://svn.apache.org/viewvc?rev=1053066&view=rev
Log:
Introduce abstract class for beanfactoryaware + simple code format

Added:
    james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/AbstractBeanFactoryAware.java
    james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/AbstractLifecycleBeanPostProcessor.java
      - copied, changed from r1052885, james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/AbstractJamesBeanPostProcessor.java
Removed:
    james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/AbstractJamesBeanPostProcessor.java
Modified:
    james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailetcontainer/MailetLoaderBeanFactory.java
    james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailetcontainer/MatcherLoaderBeanFactory.java
    james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailrepositorystore/MailRepositoryStoreBeanFactory.java
    james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/ConfigurationBeanFactoryPostProcessor.java
    james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/FileSystemBeanFactoryPostProcessor.java
    james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/ProtocolHandlerChainFactoryPostProcessor.java
    james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/ConfigurableBeanPostProcessor.java
    james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/LogEnabledBeanPostProcessor.java

Added: james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/AbstractBeanFactoryAware.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/AbstractBeanFactoryAware.java?rev=1053066&view=auto
==============================================================================
--- james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/AbstractBeanFactoryAware.java (added)
+++ james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/AbstractBeanFactoryAware.java Mon Dec 27 13:48:25 2010
@@ -0,0 +1,38 @@
+/****************************************************************
+ * 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.bean.factory;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+
+public abstract class AbstractBeanFactoryAware implements BeanFactoryAware {
+
+    private ConfigurableListableBeanFactory beanFactory;
+    
+    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
+        this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
+    }
+    
+    public ConfigurableListableBeanFactory getBeanFactory() {
+        return beanFactory;
+    }
+
+}

Modified: james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailetcontainer/MailetLoaderBeanFactory.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailetcontainer/MailetLoaderBeanFactory.java?rev=1053066&r1=1053065&r2=1053066&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailetcontainer/MailetLoaderBeanFactory.java (original)
+++ james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailetcontainer/MailetLoaderBeanFactory.java Mon Dec 27 13:48:25 2010
@@ -16,30 +16,25 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
-
 package org.apache.james.container.spring.bean.factory.mailetcontainer;
+
 import javax.mail.MessagingException;
 
+import org.apache.james.container.spring.bean.factory.AbstractBeanFactoryAware;
 import org.apache.james.mailetcontainer.api.MailetLoader;
 import org.apache.mailet.Mailet;
 import org.apache.mailet.MailetConfig;
 import org.apache.mailet.MailetException;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.BeanFactoryAware;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+
 /**
  * Loads Mailets for use inside James by using the {@link ConfigurableListableBeanFactory} of spring.
  * 
  * The Mailets are not registered in the factory after loading them!
  *
  */
-public class MailetLoaderBeanFactory implements MailetLoader, BeanFactoryAware {
-    
-    private ConfigurableListableBeanFactory beanFactory;
+public class MailetLoaderBeanFactory extends AbstractBeanFactoryAware implements MailetLoader {
     
-
     /*
      * (non-Javadoc)
      * @see org.apache.james.mailetcontainer.api.MailetLoader#getMailet(org.apache.mailet.MailetConfig)
@@ -57,12 +52,11 @@ public class MailetLoaderBeanFactory imp
             }
             
             // Use the classloader which is used for bean instance stuff
-            Class clazz = beanFactory.getBeanClassLoader().loadClass(fullName);
-            final Mailet mailet = (Mailet) beanFactory.createBean(clazz);
+            Class clazz = getBeanFactory().getBeanClassLoader().loadClass(fullName);
+            final Mailet mailet = (Mailet) getBeanFactory().createBean(clazz);
 
             // init the mailet
             mailet.init(config);
-
             
             return mailet;
             
@@ -87,11 +81,4 @@ public class MailetLoaderBeanFactory imp
         return mailetException;
     }
     
-    /*
-     * (non-Javadoc)
-     * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
-     */
-    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
-        this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
-    }
 }

Modified: james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailetcontainer/MatcherLoaderBeanFactory.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailetcontainer/MatcherLoaderBeanFactory.java?rev=1053066&r1=1053065&r2=1053066&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailetcontainer/MatcherLoaderBeanFactory.java (original)
+++ james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailetcontainer/MatcherLoaderBeanFactory.java Mon Dec 27 13:48:25 2010
@@ -16,19 +16,15 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
-
-
 package org.apache.james.container.spring.bean.factory.mailetcontainer;
+
 import javax.mail.MessagingException;
 
+import org.apache.james.container.spring.bean.factory.AbstractBeanFactoryAware;
 import org.apache.james.mailetcontainer.api.MatcherLoader;
 import org.apache.mailet.MailetException;
 import org.apache.mailet.Matcher;
 import org.apache.mailet.MatcherConfig;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.BeanFactoryAware;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 
 /**
@@ -37,19 +33,17 @@ import org.springframework.beans.factory
  * The Matchers are not registered in the factory after loading them!
  *
  */
-public class MatcherLoaderBeanFactory implements MatcherLoader, BeanFactoryAware {
-
+public class MatcherLoaderBeanFactory extends AbstractBeanFactoryAware implements MatcherLoader {
     
-    private ConfigurableListableBeanFactory beanFactory;
-
-
     /*
      * (non-Javadoc)
      * @see org.apache.james.mailetcontainer.api.MatcherLoader#getMatcher(org.apache.mailet.MatcherConfig)
      */
     @SuppressWarnings("unchecked")
     public Matcher getMatcher(MatcherConfig config) throws MessagingException {
+        
         String matchName = config.getMatcherName();
+        
         try {
             
             String fullName;
@@ -59,13 +53,14 @@ public class MatcherLoaderBeanFactory im
                 fullName = matchName;
             }
             // Use the classloader which is used for bean instance stuff
-            Class clazz = beanFactory.getBeanClassLoader().loadClass(fullName);
-            final Matcher matcher = (Matcher) beanFactory.createBean(clazz);
+            Class clazz = getBeanFactory().getBeanClassLoader().loadClass(fullName);
+            final Matcher matcher = (Matcher) getBeanFactory().createBean(clazz);
 
             // init the matcher
             matcher.init(config);
             
             return matcher;
+
         } catch (MessagingException me) {
             throw me;
         } catch (Exception e) {
@@ -88,12 +83,4 @@ public class MatcherLoaderBeanFactory im
         return mailetException;
     }
     
-    /*
-     * (non-Javadoc)
-     * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
-     */
-    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
-        this.beanFactory =  (ConfigurableListableBeanFactory) beanFactory;
-    }
-
 }

Modified: james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailrepositorystore/MailRepositoryStoreBeanFactory.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailrepositorystore/MailRepositoryStoreBeanFactory.java?rev=1053066&r1=1053065&r2=1053066&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailrepositorystore/MailRepositoryStoreBeanFactory.java (original)
+++ james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/mailrepositorystore/MailRepositoryStoreBeanFactory.java Mon Dec 27 13:48:25 2010
@@ -16,9 +16,6 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
-
-
 package org.apache.james.container.spring.bean.factory.mailrepositorystore;
 
 import java.util.ArrayList;
@@ -34,13 +31,11 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.DefaultConfigurationBuilder;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.logging.Log;
+import org.apache.james.container.spring.bean.factory.AbstractBeanFactoryAware;
 import org.apache.james.lifecycle.api.Configurable;
 import org.apache.james.lifecycle.api.LogEnabled;
 import org.apache.james.mailrepository.api.MailRepository;
 import org.apache.james.mailrepository.api.MailRepositoryStore;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.BeanFactoryAware;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 
 /**
@@ -48,27 +43,30 @@ import org.springframework.beans.factory
  * identified by its destinationURL, type and model.
  *
  */
-public class MailRepositoryStoreBeanFactory implements MailRepositoryStore, LogEnabled, Configurable, BeanFactoryAware {
+public class MailRepositoryStoreBeanFactory extends AbstractBeanFactoryAware implements MailRepositoryStore, LogEnabled, Configurable {
 
-
-    // map of [destinationURL + type]->Repository
+    /**
+     * Map of [destinationURL + type]->Repository
+     */
     private Map<String, MailRepository> repositories;
 
-    // map of [protocol(destinationURL) + type ]->classname of repository;
+    /**
+     * Map of [protocol(destinationURL) + type ]->classname of repository;
+     */
     private Map<String,String> classes;
 
-    // map of [protocol(destinationURL) + type ]->default config for repository.
+    /**
+     * Map of [protocol(destinationURL) + type ]->default config for repository.
+     */
     private Map<String,HierarchicalConfiguration> defaultConfigs;
 
     /**
-     * The Avalon configuration used by the instance
+     * The configuration used by the instance
      */
-    private HierarchicalConfiguration          configuration;
+    private HierarchicalConfiguration configuration;
 
     private Log logger;
 
-    private ConfigurableListableBeanFactory beanFactory;
-
     public void setLog(Log logger) {
         this.logger = logger;
     }
@@ -80,7 +78,6 @@ public class MailRepositoryStoreBeanFact
     public void configure(HierarchicalConfiguration configuration) throws ConfigurationException{
         this.configuration = configuration;
     }
-
     
     @PostConstruct
     @SuppressWarnings("unchecked")
@@ -115,10 +112,12 @@ public class MailRepositoryStoreBeanFact
      *                                Configuration object
      */
     @SuppressWarnings("unchecked")
-    public synchronized void registerRepository(HierarchicalConfiguration repConf)
-        throws ConfigurationException {
+    public synchronized void registerRepository(HierarchicalConfiguration repConf) throws ConfigurationException {
+
         String className = repConf.getString("[@class]");
+        
         boolean infoEnabled = getLogger().isInfoEnabled();
+        
         List<String> protocols = repConf.getList("protocols.protocol");
         
         for ( int i = 0; i < protocols.size(); i++ )
@@ -133,6 +132,7 @@ public class MailRepositoryStoreBeanFact
             }
             
             String key = protocol ;
+            
             if (infoEnabled) {
                 StringBuffer infoBuffer =
                     new StringBuffer(128)
@@ -144,9 +144,11 @@ public class MailRepositoryStoreBeanFact
                         .append(key);
                 getLogger().info(infoBuffer.toString());
             }
+            
             if (classes.get(key) != null) {
                 throw new ConfigurationException("The combination of protocol and type comprise a unique key for repositories.  This constraint has been violated.  Please check your repository configuration.");
             }
+            
             classes.put(key, className);
             if (defConf != null) {
                 defaultConfigs.put(key, defConf);
@@ -166,10 +168,8 @@ public class MailRepositoryStoreBeanFact
      * </repository>
      *
      * @param hint the Configuration object used to look up the repository
-     *
      * @return the selected repository
-     *
-     * @throws ServiceException if any error occurs while parsing the 
+     * @throws MailRepostoryStoreException if any error occurs while parsing the 
      *                            Configuration or retrieving the 
      *                            MailRepository
      */
@@ -228,8 +228,8 @@ public class MailRepositoryStoreBeanFact
             
             try {               
                 // Use the classloader which is used for bean instance stuff
-                Class<MailRepository> clazz = (Class<MailRepository>) beanFactory.getBeanClassLoader().loadClass(repClass);
-                reply = (MailRepository) beanFactory.autowire(clazz, ConfigurableListableBeanFactory.AUTOWIRE_NO, false);
+                Class<MailRepository> clazz = (Class<MailRepository>) getBeanFactory().getBeanClassLoader().loadClass(repClass);
+                reply = (MailRepository) getBeanFactory().autowire(clazz, ConfigurableListableBeanFactory.AUTOWIRE_NO, false);
 
                 if (reply instanceof LogEnabled) {
                     ((LogEnabled) reply).setLog(logger);
@@ -239,9 +239,8 @@ public class MailRepositoryStoreBeanFact
                     ((Configurable) reply).configure(config);
                 } 
                 
-                reply = (MailRepository) beanFactory.initializeBean(reply, key);
+                reply = (MailRepository) getBeanFactory().initializeBean(reply, key);
                 
-
                 repositories.put(repID, reply);
                 if (getLogger().isInfoEnabled()) {
                     logBuffer =
@@ -272,7 +271,4 @@ public class MailRepositoryStoreBeanFact
         return new ArrayList<String>(repositories.keySet());
     }
 
-    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
-        this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;        
-    }
 }

Modified: james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/ConfigurationBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/ConfigurationBeanFactoryPostProcessor.java?rev=1053066&r1=1053065&r2=1053066&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/ConfigurationBeanFactoryPostProcessor.java (original)
+++ james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/ConfigurationBeanFactoryPostProcessor.java Mon Dec 27 13:48:25 2010
@@ -54,21 +54,24 @@ public class ConfigurationBeanFactoryPos
      * Parse the configuration file and depending on it register the beans
      */
     public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
+
         ConfigurationProvider confProvider = beanFactory.getBean(ConfigurationProvider.class);
+        
         Iterator<String> beanNames = beans.keySet().iterator();
        
         // loop over the beans
         while (beanNames.hasNext()) {
+      
             String name = beanNames.next();
 
             try {
 
                 HierarchicalConfiguration config = confProvider.getConfiguration(name);
 
-                // get the configuration for the class
+                // Get the configuration for the class
                 String repClass = config.getString("[@class]");
 
-                // create the definitation and register it
+                // Create the definition and register it
                 BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
                 BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(repClass).getBeanDefinition();
                 registry.registerBeanDefinition(name, def);
@@ -92,4 +95,5 @@ public class ConfigurationBeanFactoryPos
         }
 
     }
+    
 }

Modified: james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/FileSystemBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/FileSystemBeanFactoryPostProcessor.java?rev=1053066&r1=1053065&r2=1053066&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/FileSystemBeanFactoryPostProcessor.java (original)
+++ james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/FileSystemBeanFactoryPostProcessor.java Mon Dec 27 13:48:25 2010
@@ -29,10 +29,11 @@ import org.springframework.beans.factory
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 
 /**
- * 
- *  {@link BeanFactoryPostProcessor} implementation which parse the spring configuration and search for property values which are
- *  prefixed with {@link #FS_PREFIX}. If such a property is found it will try to resolve the given path via the {@link FileSystem} service
- *  and replace it.
+ *  {@link BeanFactoryPostProcessor} implementation which parse the spring configuration 
+ *  and search for property values which are prefixed with {@link #FS_PREFIX}.
+ *  
+ *  If such a property is found it will try to resolve the given path via the {@link FileSystem} 
+ *  service and replace it.
  */
 public class FileSystemBeanFactoryPostProcessor implements BeanFactoryPostProcessor{
 
@@ -46,7 +47,6 @@ public class FileSystemBeanFactoryPostPr
         this.fs = fs;
     }
     
-    
     /*
      * (non-Javadoc)
      * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
@@ -56,13 +56,11 @@ public class FileSystemBeanFactoryPostPr
         for (int i = 0; i < names.length; i++) {
             BeanDefinition def = factory.getBeanDefinition(names[i]);
             visitor.visitBeanDefinition(def);
-           
         }
     }
     
     
     private final class FileSystemVisitor extends BeanDefinitionVisitor {
-
         @Override
         protected String resolveStringValue(String strVal) throws BeansException {
             if (strVal.startsWith(FS_PREFIX)) {
@@ -74,7 +72,6 @@ public class FileSystemBeanFactoryPostPr
             }
             return strVal;
         }
-        
     }
 
 }

Modified: james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/ProtocolHandlerChainFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/ProtocolHandlerChainFactoryPostProcessor.java?rev=1053066&r1=1053065&r2=1053066&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/ProtocolHandlerChainFactoryPostProcessor.java (original)
+++ james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/ProtocolHandlerChainFactoryPostProcessor.java Mon Dec 27 13:48:25 2010
@@ -73,10 +73,8 @@ public abstract class ProtocolHandlerCha
      * Return a DefaultConfiguration build on the given command name and
      * classname
      * 
-     * @param cmdName
-     *            The command name
-     * @param className
-     *            The class name
+     * @param cmdName The command name
+     * @param className The class name
      * @return DefaultConfiguration
      * @throws ConfigurationException
      */
@@ -116,7 +114,8 @@ public abstract class ProtocolHandlerCha
     }
 
     /**
-     * Lookup the {@link HierarchicalConfiguration} for the beanname which was configured via {@link #setBeanName(String)} and parse it for handlers which should be 
+     * Lookup the {@link HierarchicalConfiguration} for the beanname which was 
+     * configured via {@link #setBeanName(String)} and parse it for handlers which should be 
      * registered in the {@link ConfigurableListableBeanFactory}. 
      */
     public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

Copied: james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/AbstractLifecycleBeanPostProcessor.java (from r1052885, james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/AbstractJamesBeanPostProcessor.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/AbstractLifecycleBeanPostProcessor.java?p2=james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/AbstractLifecycleBeanPostProcessor.java&p1=james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/AbstractJamesBeanPostProcessor.java&r1=1052885&r2=1053066&rev=1053066&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/AbstractJamesBeanPostProcessor.java (original)
+++ james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/AbstractLifecycleBeanPostProcessor.java Mon Dec 27 13:48:25 2010
@@ -18,11 +18,9 @@
  ****************************************************************/
 package org.apache.james.container.spring.bean.postprocessor;
 
+import org.apache.james.container.spring.bean.factory.AbstractBeanFactoryAware;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.FatalBeanException;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.BeanFactoryAware;
-import org.springframework.beans.factory.ListableBeanFactory;
 import org.springframework.beans.factory.config.BeanPostProcessor;
 import org.springframework.core.Ordered;
 import org.springframework.core.PriorityOrdered;
@@ -31,57 +29,78 @@ import org.springframework.core.Priority
  * Abstract base class which BeanPostProcessors should extend if they provide an
  * LifeCycle handling
  * 
- * 
  * @param <T>
  */
-public abstract class AbstractJamesBeanPostProcessor<T> implements BeanPostProcessor, PriorityOrdered, BeanFactoryAware {
-
+public abstract class AbstractLifecycleBeanPostProcessor<T> extends AbstractBeanFactoryAware implements BeanPostProcessor, PriorityOrdered {
+    
     private int order = Ordered.HIGHEST_PRECEDENCE;
-    private ListableBeanFactory factory;
+
+    /**
+     * Return the class which mark the lifecycle.
+     * 
+     * @return interfaceClass
+     */
+    protected abstract Class<T> getLifeCycleInterface();
+
+    /**
+     * Method which gets executed if the bean implement the LifeCycleInterface.
+     * Override this if you wish perform any action. Default is todo nothing
+     * 
+     * @param bean
+     *            the actual bean
+     * @param beanname
+     *            then name of the bean
+     * @throws Exception
+     */
+    protected abstract void executeLifecycleMethodBeforeInit(T bean, String beanname) throws Exception;
+
+    /**
+     * Method which gets executed if the bean implement the LifeCycleInterface.
+     * Override this if you wish perform any action. Default is todo nothing
+     * 
+     * @param bean the actual bean
+     * @param beanname then name of the bean
+     * @param componentName the component name
+     * @throws Exception
+     */
+    protected abstract void executeLifecycleMethodAfterInit(T bean, String beanname) throws Exception;
 
     /*
      * (non-Javadoc)
      * 
-     * @see org.springframework.beans.factory.config.BeanPostProcessor#
-     * postProcessAfterInitialization(java.lang.Object, java.lang.String)
+     * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String)
      */
     @SuppressWarnings("unchecked")
-    public final Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
+    public final Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
         try {
             Class<T> lClass = getLifeCycleInterface();
-            if (lClass.isInstance(bean))
+            if (lClass.isInstance(bean)) {
                 // 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 (factory.containsBeanDefinition(name)) {
-                    executeLifecycleMethodAfterInit((T) bean, name);
+                if (getBeanFactory().containsBeanDefinition(name)) {
+                    executeLifecycleMethodBeforeInit((T) bean, name);
                 }
+            }
         } catch (Exception e) {
             throw new FatalBeanException("Unable to execute lifecycle method on bean" + name, e);
         }
         return bean;
     }
 
-    /**
-     * Return the class which mark the lifecycle
-     * 
-     * @return interfaceClass
-     */
-    protected abstract Class<T> getLifeCycleInterface();
-
     /*
      * (non-Javadoc)
      * 
-     * @see org.springframework.beans.factory.config.BeanPostProcessor#
-     * postProcessBeforeInitialization(java.lang.Object, java.lang.String)
+     * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String)
      */
     @SuppressWarnings("unchecked")
-    public final Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
+    public final Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
         try {
             Class<T> lClass = getLifeCycleInterface();
-            if (lClass.isInstance(bean))
+            if (lClass.isInstance(bean)) {
                 // 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 (factory.containsBeanDefinition(name)) {
-                    executeLifecycleMethodBeforeInit((T) bean, name);
+                if (getBeanFactory().containsBeanDefinition(name)) {
+                    executeLifecycleMethodAfterInit((T) bean, name);
                 }
+            }
         } catch (Exception e) {
             throw new FatalBeanException("Unable to execute lifecycle method on bean" + name, e);
         }
@@ -89,35 +108,8 @@ public abstract class AbstractJamesBeanP
     }
 
     /**
-     * Method which gets executed if the bean implement the LifeCycleInterface.
-     * Override this if you wish perform any action. Default is todo nothing
-     * 
-     * @param bean
-     *            the actual bean
-     * @param beanname
-     *            then name of the bean
-     * @throws Exception
-     */
-    protected void executeLifecycleMethodBeforeInit(T bean, String beanname) throws Exception {
-
-    }
-
-    /**
-     * Method which gets executed if the bean implement the LifeCycleInterface.
-     * Override this if you wish perform any action. Default is todo nothing
-     * 
-     * @param bean
-     *            the actual bean
-     * @param beanname
-     *            then name of the bean
-     * @param componentName
-     *            the component name
-     * @throws Exception
+     * @param order
      */
-    protected void executeLifecycleMethodAfterInit(T bean, String beanname) throws Exception {
-
-    }
-
     public void setOrder(int order) {
         this.order = order;
     }
@@ -131,14 +123,4 @@ public abstract class AbstractJamesBeanP
         return order;
     }
     
-
-    /*
-     * (non-Javadoc)
-     * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
-     */
-    public void setBeanFactory(BeanFactory factory) throws BeansException {
-        this.factory = (ListableBeanFactory) factory;
-    }
-
-
 }

Modified: james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/ConfigurableBeanPostProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/ConfigurableBeanPostProcessor.java?rev=1053066&r1=1053065&r2=1053066&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/ConfigurableBeanPostProcessor.java (original)
+++ james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/ConfigurableBeanPostProcessor.java Mon Dec 27 13:48:25 2010
@@ -24,13 +24,19 @@ import org.apache.james.lifecycle.api.Co
 
 /**
  * Inject Commons Configuration to beans which implement the Configurable interface
- * 
- *
  */
-public class ConfigurableBeanPostProcessor extends AbstractJamesBeanPostProcessor<Configurable> {
+public class ConfigurableBeanPostProcessor extends AbstractLifecycleBeanPostProcessor<Configurable> {
 
     private ConfigurationProvider provider;
 
+    public void setConfigurationProvider(ConfigurationProvider provider) {
+        this.provider = provider;
+    }
+
+    @Override
+    protected Class<Configurable> getLifeCycleInterface() {
+        return Configurable.class;
+    }
 
     @Override
     protected void executeLifecycleMethodBeforeInit(Configurable bean, String beanname) throws Exception {
@@ -38,13 +44,9 @@ public class ConfigurableBeanPostProcess
         bean.configure(config);
     }
 
-    public void setConfigurationProvider(ConfigurationProvider provider) {
-        this.provider = provider;
-    }
-
     @Override
-    protected Class<Configurable> getLifeCycleInterface() {
-        return Configurable.class;
+    protected void executeLifecycleMethodAfterInit(Configurable bean, String beanname) throws Exception {
+        // Do nothing
     }
 
 }

Modified: james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/LogEnabledBeanPostProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/LogEnabledBeanPostProcessor.java?rev=1053066&r1=1053065&r2=1053066&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/LogEnabledBeanPostProcessor.java (original)
+++ james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/LogEnabledBeanPostProcessor.java Mon Dec 27 13:48:25 2010
@@ -22,27 +22,30 @@ import org.apache.james.container.spring
 import org.apache.james.lifecycle.api.LogEnabled;
 
 /**
- * Inject Commons Log to beans which implement LogEnabled
- * 
- *
+ * Inject Commons Log to beans which implement LogEnabled.
  */
-public class LogEnabledBeanPostProcessor extends AbstractJamesBeanPostProcessor<LogEnabled> {
+public class LogEnabledBeanPostProcessor extends AbstractLifecycleBeanPostProcessor<LogEnabled> {
 
     private LogProvider provider;
 
+    public void setLogProvider(LogProvider provider) {
+        this.provider = provider;
+    }
+
     @Override
     protected Class<LogEnabled> getLifeCycleInterface() {
         return LogEnabled.class;
     }
 
-    public void setLogProvider(LogProvider provider) {
-        this.provider = provider;
-    }
-
     @Override
     protected void executeLifecycleMethodBeforeInit(LogEnabled bean, String beanname) throws Exception {
         bean.setLog(provider.getLog(beanname));
     }
 
+    @Override
+    protected void executeLifecycleMethodAfterInit(LogEnabled bean, String beanname) throws Exception {
+        // Do nothing
+    }
+
  
 }



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