KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > imapserver > BaseConnectionHandler


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

17
18
19 package org.apache.james.imapserver;
20
21 import org.apache.avalon.cornerstone.services.connection.ConnectionHandler;
22 import org.apache.avalon.framework.configuration.Configurable;
23 import org.apache.avalon.framework.configuration.Configuration;
24 import org.apache.avalon.framework.configuration.ConfigurationException;
25 import org.apache.avalon.framework.logger.AbstractLogEnabled;
26
27 import java.net.InetAddress JavaDoc;
28 import java.net.UnknownHostException JavaDoc;
29
30 /**
31  * THIS FILE RETRIEVED FROM THE MAIN TRUNK ATTIC, TO ENABLE IMAP PROPOSAL
32  * TO COMPILE - EXTENDED BY o.a.james.imapserver.BaseCommand.
33  * TODO: Use the AbstractJamesService for ImapServer, and get rid of this file.
34  *
35  * Different connection handlers extend this class
36  * Common Connection Handler code could be factored into this class.
37  * At present(April 28' 2001) there is not much in this class
38  *
39  */

40 public class BaseConnectionHandler extends AbstractLogEnabled implements Configurable {
41
42     /**
43      * The default timeout for the connection
44      */

45     private static int DEFAULT_TIMEOUT = 1800000;
46
47     /**
48      * The timeout for the connection
49      */

50     protected int timeout = DEFAULT_TIMEOUT;
51
52     /**
53      * The hello name for the connection
54      */

55     protected String JavaDoc helloName;
56
57     /**
58      * Get the hello name for this server
59      *
60      * @param configuration a configuration object containing server name configuration info
61      * @return the hello name for this server
62      */

63     public static String JavaDoc configHelloName(final Configuration configuration)
64         throws ConfigurationException {
65         String JavaDoc hostName = null;
66
67         try {
68             hostName = InetAddress.getLocalHost().getHostName();
69         } catch (UnknownHostException JavaDoc ue) {
70             // Default to localhost if we can't get the local host name.
71
hostName = "localhost";
72         }
73
74         Configuration helloConf = configuration.getChild("helloName");
75         boolean autodetect = helloConf.getAttributeAsBoolean("autodetect", true);
76
77         return autodetect ? hostName : helloConf.getValue("localhost");
78     }
79
80
81     /**
82      * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
83      */

84     public void configure( final Configuration configuration )
85         throws ConfigurationException {
86
87         timeout = configuration.getChild( "connectiontimeout" ).getValueAsInteger( DEFAULT_TIMEOUT );
88         helloName = configHelloName(configuration);
89         if (getLogger().isDebugEnabled()) {
90             getLogger().debug("Hello Name is: " + helloName);
91         }
92     }
93
94     /**
95      * Release a previously created ConnectionHandler e.g. for spooling.
96      *
97      * @param connectionHandler the ConnectionHandler to be released
98      */

99     public void releaseConnectionHandler(ConnectionHandler connectionHandler) {
100     }
101 }
102
Popular Tags