Author: eric
Date: Mon Dec 20 12:12:08 2010
New Revision: 1051075

URL: http://svn.apache.org/viewvc?rev=1051075&view=rev
Log:
ProtocolHandlerChain is a Spring PostProcessor - Also split the 
FactorPostProcessor from the PostProcessor functions

Added:
    
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/ProtocolHandlerChainFactoryPostProcessor.java
      - copied, changed from r1051031, 
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/protocolhandlerchain/ProtocolHandlerChainBeanFactory.java
    
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/ProtocolHandlerChainPostProcessor.java
Removed:
    
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/protocolhandlerchain/

Copied: 
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/ProtocolHandlerChainFactoryPostProcessor.java
 (from r1051031, 
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/protocolhandlerchain/ProtocolHandlerChainBeanFactory.java)
URL: 
http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/ProtocolHandlerChainFactoryPostProcessor.java?p2=james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/ProtocolHandlerChainFactoryPostProcessor.java&p1=james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/protocolhandlerchain/ProtocolHandlerChainBeanFactory.java&r1=1051031&r2=1051075&rev=1051075&view=diff
==============================================================================
--- 
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factory/protocolhandlerchain/ProtocolHandlerChainBeanFactory.java
 (original)
+++ 
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/factorypostprocessor/ProtocolHandlerChainFactoryPostProcessor.java
 Mon Dec 20 12:12:08 2010
@@ -16,13 +16,12 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-package org.apache.james.container.spring.bean.factory.protocolhandlerchain;
+package org.apache.james.container.spring.bean.factorypostprocessor;
 
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 
-
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.ConfigurationUtils;
 import org.apache.commons.configuration.DefaultConfigurationBuilder;
@@ -33,12 +32,10 @@ import org.apache.james.container.spring
 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.config.BeanDefinition;
 import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
-import org.springframework.beans.factory.config.BeanPostProcessor;
 import 
org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 import org.springframework.beans.factory.support.BeanDefinitionRegistry;
@@ -54,13 +51,15 @@ import org.springframework.beans.factory
  * 
  */
 @SuppressWarnings("unchecked")
-public class ProtocolHandlerChainBeanFactory implements ProtocolHandlerChain, 
BeanFactoryPostProcessor, BeanPostProcessor {
+public abstract class ProtocolHandlerChainFactoryPostProcessor implements 
ProtocolHandlerChain, BeanFactoryPostProcessor {
 
     private String coreHandlersPackage;
+    
     private List<String> handlers = new LinkedList<String>();
+    
     private String beanname;
-    private ConfigurableListableBeanFactory beanFactory;
     
+    private ConfigurableListableBeanFactory beanFactory;
     
     public void setBeanName(String beanname) {
         this.beanname = beanname;
@@ -106,19 +105,32 @@ public class ProtocolHandlerChainBeanFac
         
         return classHandlers;
     }
-
+    
+    /**
+     * Returns the Handlers List.
+     * 
+     * @return
+     */
+    public List<String> getHandlers() {
+        return handlers;
+    }
 
     /**
      * 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 {
+
         this.beanFactory = beanFactory;
+        
         ConfigurationProvider confProvider = 
beanFactory.getBean(ConfigurationProvider.class);
+        
         LogProvider logProvider = beanFactory.getBean(LogProvider.class);
         
         try {
+
             Log log = logProvider.getLog(beanname);
+            
             HierarchicalConfiguration config = 
confProvider.getConfiguration(beanname);
             HierarchicalConfiguration handlerchainConfig = 
config.configurationAt("handler.handlerchain");
             List<org.apache.commons.configuration.HierarchicalConfiguration> 
children = handlerchainConfig.configurationsAt("handler");
@@ -128,7 +140,6 @@ public class ProtocolHandlerChainBeanFac
                 handlerchainConfig.addProperty("[...@corehandlerspackage]", 
coreHandlersPackage);
 
             String coreCmdName = 
handlerchainConfig.getString("[...@corehandlerspackage]");
-
             
             BeanDefinitionRegistry registry = (BeanDefinitionRegistry) 
beanFactory;
 
@@ -188,37 +199,4 @@ public class ProtocolHandlerChainBeanFac
         return beanname + ":" + name;
     }
 
-
-    /**
-     * Check if the bean was registered within the instance and if so see if 
it is an {...@link ExtensibleHandler} implementation
-     * 
-     * If thats the case it will do all the needed wiring 
-     */
-    public Object postProcessBeforeInitialization(Object bean, String 
beanName) throws BeansException {
-        
-        // check if ths instance is responsible for the bean and if so if the 
bean is an instance of ExtensibleHandler
-        if (handlers.contains(beanName) && bean instanceof ExtensibleHandler) {
-            final ExtensibleHandler extensibleHandler = (ExtensibleHandler) 
bean;
-            final List<Class<?>> markerInterfaces = 
extensibleHandler.getMarkerInterfaces();
-            for (int i = 0; i < markerInterfaces.size(); i++) {
-                final Class<?> markerInterface = markerInterfaces.get(i);
-                final List<?> extensions = getHandlers(markerInterface);
-                try {
-                    // ok now time for try the wiring
-                    extensibleHandler.wireExtensions(markerInterface, 
extensions);
-                } catch (WiringException e) {
-                    throw new FatalBeanException("Unable to wire the handler " 
+ bean + " with name " + beanName, e);
-                }
-            }
-        }
-        
-        return bean;
-    }
-
-    /**
-     * Nothing todo so just return the bean
-     */
-    public Object postProcessAfterInitialization(Object bean, String beanName) 
throws BeansException {
-        return bean;
-    }
-}
\ No newline at end of file
+}

Added: 
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/ProtocolHandlerChainPostProcessor.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/ProtocolHandlerChainPostProcessor.java?rev=1051075&view=auto
==============================================================================
--- 
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/ProtocolHandlerChainPostProcessor.java
 (added)
+++ 
james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/bean/postprocessor/ProtocolHandlerChainPostProcessor.java
 Mon Dec 20 12:12:08 2010
@@ -0,0 +1,65 @@
+/****************************************************************
+ * 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.postprocessor;
+
+import java.util.List;
+
+import 
org.apache.james.container.spring.bean.factorypostprocessor.ProtocolHandlerChainFactoryPostProcessor;
+import org.apache.james.protocols.api.ExtensibleHandler;
+import org.apache.james.protocols.api.WiringException;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.FatalBeanException;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+
+public class ProtocolHandlerChainPostProcessor extends 
ProtocolHandlerChainFactoryPostProcessor implements BeanPostProcessor {
+
+    /**
+     * Check if the bean was registered within the instance and if so see if 
it is an {...@link ExtensibleHandler} implementation
+     * 
+     * If thats the case it will do all the needed wiring 
+     */
+    public Object postProcessBeforeInitialization(Object bean, String 
beanName) throws BeansException {
+        
+        // check if ths instance is responsible for the bean and if so if the 
bean is an instance of ExtensibleHandler
+        if (getHandlers().contains(beanName) && bean instanceof 
ExtensibleHandler) {
+            final ExtensibleHandler extensibleHandler = (ExtensibleHandler) 
bean;
+            final List<Class<?>> markerInterfaces = 
extensibleHandler.getMarkerInterfaces();
+            for (int i = 0; i < markerInterfaces.size(); i++) {
+                final Class<?> markerInterface = markerInterfaces.get(i);
+                final List<?> extensions = getHandlers(markerInterface);
+                try {
+                    // ok now time for try the wiring
+                    extensibleHandler.wireExtensions(markerInterface, 
extensions);
+                } catch (WiringException e) {
+                    throw new FatalBeanException("Unable to wire the handler " 
+ bean + " with name " + beanName, e);
+                }
+            }
+        }
+        
+        return bean;
+    }
+
+    /**
+     * Nothing todo so just return the bean
+     */
+    public Object postProcessAfterInitialization(Object bean, String beanName) 
throws BeansException {
+        return bean;
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to