james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r415916 - /james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java
Date Wed, 21 Jun 2006 05:38:04 GMT
Author: norman
Date: Tue Jun 20 22:38:04 2006
New Revision: 415916

URL: http://svn.apache.org/viewvc?rev=415916&view=rev
Log:
Make the smptHandlerChain Initializable and Contextualizable. See JAMES-547

Modified:
    james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java

Modified: james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java?rev=415916&r1=415915&r2=415916&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java (original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java Tue Jun
20 22:38:04 2006
@@ -17,11 +17,15 @@
 
 package org.apache.james.smtpserver;
 
+import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
@@ -30,6 +34,7 @@
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Properties;
@@ -38,7 +43,7 @@
   * The SMTPHandlerChain is per service object providing access
   * ConnectHandlers, Commandhandlers and message handlers
   */
-public class SMTPHandlerChain extends AbstractLogEnabled implements Configurable, Serviceable
{
+public class SMTPHandlerChain extends AbstractLogEnabled implements Configurable, Serviceable,
Contextualizable, Initializable {
 
     private HashMap commandHandlerMap = new HashMap();
     private ArrayList messageHandlers = new ArrayList();
@@ -46,12 +51,18 @@
 
     private final CommandHandler unknownHandler = new UnknownCmdHandler();
     private ServiceManager serviceManager;
-
+    private Context context;
+    
     private final static String[] mandatoryCommands = { "MAIL" , "RCPT", "DATA"};
 
     public void service(ServiceManager arg0) throws ServiceException {
         serviceManager = arg0;
     }
+    
+    public void contextualize(Context arg0) throws ContextException {
+        context = arg0;
+    }
+
 
 
     /**
@@ -99,6 +110,8 @@
 
                             //enable logging
                             ContainerUtil.enableLogging(handler, getLogger());
+                            
+                            ContainerUtil.contextualize(handler,context);
 
                             //servicing the handler
                             ContainerUtil.service(handler,serviceManager);
@@ -153,6 +166,11 @@
                                 getLogger().error("Failed to service Commandhandler: " +
className,e);
                             }
                             throw new ConfigurationException("Failed to add Commandhandler:
" + className,e);
+                        } catch (ContextException e) {
+                            if (getLogger().isErrorEnabled()) {
+                                getLogger().error("Failed to service Commandhandler: " +
className,e);
+                            }
+                            throw new ConfigurationException("Failed to add Commandhandler:
" + className,e);
                         }
                     }
                 }
@@ -190,6 +208,22 @@
 
         }
     }
+    
+    /**
+     * @see org.apache.avalon.framework.activity.Initializable#initialize()
+     */
+    public void initialize() throws Exception {
+        Iterator h = commandHandlerMap.keySet().iterator();
+    
+        while(h.hasNext()) {
+            List handlers = (List) commandHandlerMap.get(h.next());
+            Iterator h2 = handlers.iterator();
+            while (h2.hasNext()) {
+              ContainerUtil.initialize(h2.next());
+            }
+        }
+    }
+
 
     /**
      * Add it to map (key as command name, value is an array list of commandhandlers)



---------------------------------------------------------------------
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