KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > cornerstone > services > connection > AbstractHandlerFactory


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

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 /**
33  * Helper class to extend to create handler factorys.
34  *
35  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
36  */

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     /**
63      * Construct an appropriate ConnectionHandler.
64      *
65      * @return the new ConnectionHandler
66      * @exception Exception if an error occurs
67      */

68     public ConnectionHandler createConnectionHandler()
69         throws Exception JavaDoc
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     /**
88      * Overide this method to create actual instance of connection handler.
89      *
90      * @return the new ConnectionHandler
91      * @exception Exception if an error occurs
92      */

93     protected abstract ConnectionHandler newHandler()
94         throws Exception JavaDoc;
95 }
96
Popular Tags