Index: POP3Server.java
===================================================================
RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/pop3server/POP3Server.java,v
retrieving revision 1.11
diff -u -r1.11 POP3Server.java
--- POP3Server.java	2 Oct 2002 06:12:02 -0000	1.11
+++ POP3Server.java	22 Oct 2002 01:40:07 -0000
@@ -9,11 +9,17 @@
 import org.apache.avalon.cornerstone.services.connection.AbstractService;
 import org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory;
 import org.apache.avalon.cornerstone.services.connection.DefaultHandlerFactory;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.component.Component;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import org.apache.avalon.framework.component.ComponentException;
+import org.apache.avalon.framework.component.ComponentManager;
+import org.apache.avalon.cornerstone.services.connection.ConnectionHandler;
+
 /**
  * <p>Accepts POP3 connections on a server socket and dispatches them to POP3Handlers.</p>
  *
@@ -25,6 +31,15 @@
  */
 public class POP3Server extends AbstractService implements Component {
 
+    /** needed to pass necessary components to Handler */
+    private ComponentManager m_componentManager;
+
+    /** needed to pass handler configuration */
+    private Configuration m_configuration;
+
+    /** parameters(configuration and components) needed by conneciton handler */
+    private POP3HandlerParams m_params;
+
     /**
      * Whether this service is enabled
      */
@@ -36,7 +51,36 @@
      * @return a ConnectionHandlerFactory that produces POP3Handlers
      */
     protected ConnectionHandlerFactory createFactory() {
-        return new DefaultHandlerFactory(POP3Handler.class);
+        return new DefaultHandlerFactory(POP3Handler.class) {
+                protected ConnectionHandler newHandler()
+                    throws Exception
+                {
+                    return new POP3Handler(getParams());
+                }
+            };
+    }
+
+    /** 
+     * lazily create a Params object 
+     * @return Params object. Contains all the configuration and
+     * components needed by Handler
+     */
+    private POP3HandlerParams getParams() throws Exception {
+        if ( m_params == null )
+            m_params = new POP3HandlerParams(m_configuration,m_componentManager);
+
+        // not needed anymore.
+        m_componentManager = null;
+        m_configuration = null;
+        return m_params;
+    }
+
+    /**
+     * @see org.apache.avalon.framework.component.Composable#compose(ComponentManager)
+     */
+    public void compose(final ComponentManager componentManager) throws ComponentException {
+        super.compose(componentManager);
+        m_componentManager = componentManager;
     }
 
     /**
@@ -44,6 +88,7 @@
      */
     public void configure(final Configuration configuration) throws ConfigurationException {
         enabled = configuration.getAttributeAsBoolean("enabled", true);
+        m_configuration = configuration.getChild("handler");
         if (enabled) {
             m_port = configuration.getChild("port").getValueAsInteger(25);
             try {
