1 17 18 package org.apache.avalon.cornerstone.services.connection; 19 20 import org.apache.avalon.framework.component.WrapperComponentManager; 21 import org.apache.avalon.framework.configuration.Configurable; 22 import org.apache.avalon.framework.configuration.Configuration; 23 import org.apache.avalon.framework.configuration.ConfigurationException; 24 import org.apache.avalon.framework.container.ContainerUtil; 25 import org.apache.avalon.framework.context.Context; 26 import org.apache.avalon.framework.context.Contextualizable; 27 import org.apache.avalon.framework.logger.AbstractLogEnabled; 28 import org.apache.avalon.framework.service.ServiceException; 29 import org.apache.avalon.framework.service.ServiceManager; 30 import org.apache.avalon.framework.service.Serviceable; 31 32 37 public abstract class AbstractHandlerFactory 38 extends AbstractLogEnabled 39 implements Contextualizable, Serviceable, Configurable, ConnectionHandlerFactory 40 { 41 private Context m_context; 42 private ServiceManager m_serviceManager; 43 private Configuration m_configuration; 44 45 public void contextualize( final Context context ) 46 { 47 m_context = context; 48 } 49 50 public void service( final ServiceManager serviceManager ) 51 throws ServiceException 52 { 53 m_serviceManager = serviceManager; 54 } 55 56 public void configure( final Configuration configuration ) 57 throws ConfigurationException 58 { 59 m_configuration = configuration; 60 } 61 62 68 public ConnectionHandler createConnectionHandler() 69 throws Exception 70 { 71 final ConnectionHandler handler = newHandler(); 72 ContainerUtil.enableLogging( handler, getLogger() ); 73 ContainerUtil.contextualize( handler, m_context ); 74 ContainerUtil.service( handler, m_serviceManager ); 75 ContainerUtil.compose( handler, new WrapperComponentManager( m_serviceManager ) ); 76 ContainerUtil.configure( handler, m_configuration ); 77 ContainerUtil.initialize( handler ); 78 79 return handler; 80 } 81 82 public void releaseConnectionHandler( ConnectionHandler connectionHandler ) 83 { 84 ContainerUtil.dispose( connectionHandler ); 85 } 86 87 93 protected abstract ConnectionHandler newHandler() 94 throws Exception ; 95 } 96 | Popular Tags |