KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.james.imapserver;
19
20 import org.apache.avalon.framework.component.Component;
21 import org.apache.avalon.framework.activity.Initializable;
22 import org.apache.james.imapserver.AuthenticationException;
23
24 import java.net.InetAddress JavaDoc;
25 import java.net.UnknownHostException JavaDoc;
26 import java.util.Collections JavaDoc;
27 import java.util.HashSet JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.Set JavaDoc;
30
31 /**
32  * A simple, single-server, implementation of IMAPSystem.
33  *
34  * References: rfc 2060, rfc 2193, rfc 2221
35  * @version 0.1 on 14 Dec 2000
36  */

37 public class SimpleSystem
38     implements IMAPSystem, Component, Initializable {
39
40     private static final String JavaDoc namespaceToken = "#";
41     private static final String JavaDoc hierarchySeparator = ".";
42     private static final String JavaDoc namespace
43         = "((\"#mail.\" \".\")) ((\"#users.\" \".\")) ((\"#shared.\" \".\"))";
44
45     private static String JavaDoc singleServer;
46     private Set JavaDoc servers = new HashSet JavaDoc();
47
48     /**
49      * @see org.apache.avalon.framework.activity.Initializable#initialize()
50      */

51     public void initialize() throws Exception JavaDoc {
52         String JavaDoc hostName = null;
53         try {
54             hostName = InetAddress.getLocalHost().getHostName();
55         } catch (UnknownHostException JavaDoc ue) {
56             hostName = "localhost";
57         }
58         singleServer = hostName;
59         servers.add(singleServer);
60     }
61
62     /**
63      * Returns the token indicating a namespace. Implementation dependent but
64      * by convention, '#'.
65      * Example: #news.org.apache vs #mail.org.apache
66      */

67     public String JavaDoc getNamespaceToken() {
68         return namespaceToken;
69     }
70
71     /**
72      * Returns the home server (server with user's INBOX) for specified user.
73      * Enables Login Referrals per RFC2221. (Ie user attempts to login to a
74      * server which is not their Home Server.) The returned string must comply
75      * with RFC2192, IMAP URL Scheme.
76      *
77      * @param username String representation of a user
78      * @return String holding an IMAP URL for the user's home server
79      * @throws AuthenticationException if this System does not recognise
80      * the user.
81      */

82     public String JavaDoc getHomeServer(String JavaDoc username)
83         throws AuthenticationException {
84         return singleServer;
85     }
86
87     /**
88      * Returns the character used as a mail hierarchy separator in a given
89      * namespace. A namespace must use the same separator at all levels of
90      * hierarchy.
91      * <p>Recommendations (from rfc 2683) are period (US)/ full stop (Brit),
92      * forward slash or backslash.
93      *
94      * @param namespace String identifying a namespace
95      * @return char, usually '.', '/', or '\'
96      */

97     public String JavaDoc getHierarchySeperator(String JavaDoc namespace) {
98         return hierarchySeparator;
99     }
100
101     /**
102      * Provides the set of namesapces a given user can access. Implementations
103      * should but are not required to reveal all namespaces that a user can
104      * access. Different namespaces may be handled by different
105      * <code>IMAPHosts</code>
106      *
107      * @param username String identifying a user of this System
108      * @return String whose contents should be a space seperated triple
109      * <personal namespaces(s)> space <other users' namespace(s)> space
110      * <shared namespace(s)>, per RFC2342
111      */

112     public String JavaDoc getNamespaces(String JavaDoc username) {
113         return namespace;
114     }
115
116     /**
117      * Returns an iterator over the collection of servers on which this user
118      * has access. The collection should be unmodifiable.
119      * Enable Mailbox Referrals - RFC 2193.
120      *
121      * @param username String identifying a user
122      * @return iterator over a collection of strings
123      */

124     public Iterator JavaDoc getAccessibleServers(String JavaDoc username) {
125         return Collections.unmodifiableSet(servers).iterator();
126     }
127 }
128
Popular Tags