KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > ristretto > imap > NamespaceCollection


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is Ristretto Mail API.
15  *
16  * The Initial Developers of the Original Code are
17  * Timo Stich and Frederik Dietz.
18  * Portions created by the Initial Developers are Copyright (C) 2004
19  * All Rights Reserved.
20  *
21  * Contributor(s):
22  *
23  * Alternatively, the contents of this file may be used under the terms of
24  * either the GNU General Public License Version 2 or later (the "GPL"), or
25  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26  * in which case the provisions of the GPL or the LGPL are applicable instead
27  * of those above. If you wish to allow use of your version of this file only
28  * under the terms of either the GPL or the LGPL, and not to allow others to
29  * use your version of this file under the terms of the MPL, indicate your
30  * decision by deleting the provisions above and replace them with the notice
31  * and other provisions required by the GPL or the LGPL. If you do not delete
32  * the provisions above, a recipient may use your version of this file under
33  * the terms of any one of the MPL, the GPL or the LGPL.
34  *
35  * ***** END LICENSE BLOCK ***** */

36 package org.columba.ristretto.imap;
37
38 import java.util.ArrayList JavaDoc;
39 import java.util.Arrays JavaDoc;
40 import java.util.Iterator JavaDoc;
41 import java.util.List JavaDoc;
42
43 /**
44  * The collection of namespaces defined on
45  * an IMAP server.
46  *
47  * @author tstich
48  */

49 public class NamespaceCollection {
50
51     /**
52      * Namespace type.
53      */

54     public static final int PERSONAL = 0;
55     /**
56      * Namespace type.
57      */

58     public static final int OTHER_USER = 1;
59     /**
60      * Namespace type.
61      */

62     public static final int SHARED = 2;
63     
64     
65     private List JavaDoc personal;
66     private List JavaDoc otherUser;
67     private List JavaDoc shared;
68     
69     /**
70      * Constructs the NamespaceCollection.
71      */

72     public NamespaceCollection() {
73         personal = new ArrayList JavaDoc();
74         otherUser = new ArrayList JavaDoc();
75         shared = new ArrayList JavaDoc();
76     }
77     
78     /**
79      * Add a personal namespace.
80      *
81      * @param ns
82      */

83     public void addPersonalNamespace(Namespace ns) {
84         personal.add(ns);
85     }
86     
87     /**
88      * Add a Other-User namespace.
89      *
90      * @param ns
91      */

92     public void addOtherUserNamespace(Namespace ns) {
93         otherUser.add(ns);
94     }
95     
96     /**
97      * Add a shared namespace.
98      *
99      * @param ns
100      */

101     public void addSharedNamespace(Namespace ns) {
102         shared.add(ns);
103     }
104     
105     /**
106      * Gets the first personal namespaces.
107      *
108      * @return the personal namespaces
109      */

110     public Namespace getPersonalNamespace() {
111         return (Namespace) personal.get(0);
112     }
113     
114     /**
115      * Gets the ith personal namespace.
116      *
117      * @param i
118      * @return the ith personal namespace
119      */

120     public Namespace getPersonalNamespace(int i) {
121         return (Namespace) personal.get(i);
122     }
123
124     /**
125      * Gets the first other-user namespace
126      *
127      * @return the first other-user namespace
128      */

129     public Namespace getOtherUserNamespace() {
130         return (Namespace) otherUser.get(0);
131     }
132
133     /**
134      * Gets the ith other-user namespace
135      *
136      * @param i
137      * @return the ith other-user namespace
138      */

139     public Namespace getOtherUserNamespace(int i) {
140         return (Namespace) otherUser.get(i);
141     }
142
143     /**
144      * Gets the first shared namespace
145      *
146      * @return the first shared namespace
147      */

148     public Namespace getSharedNamespace() {
149         return (Namespace) shared.get(0);
150     }
151     
152     /**
153      * Gets the ith shared namespace.
154      *
155      * @param i
156      * @return the ith shared namespace
157      */

158     public Namespace getSharedNamespace(int i) {
159         return (Namespace) shared.get(i);
160     }
161
162     
163     /**
164      * Get the Iterator over the personal namespaces.
165      *
166      * @return the iterator over the personal namespaces
167      *
168      */

169     public Iterator JavaDoc getPersonalIterator() {
170         return personal.iterator();
171     }
172
173     /**
174      * Gets the iterator over the other-user namespaces.
175      *
176      * @return the iterator over the other-user namespaces.
177      */

178     public Iterator JavaDoc getOtherUserIterator() {
179         return otherUser.iterator();
180     }
181
182     /**
183      * Gets the iterator over the shared namespaces.
184      *
185      * @return the iterator over the shared namespaces
186      */

187     public Iterator JavaDoc getSharedIterator() {
188         return shared.iterator();
189     }
190
191     /**
192      * Add a namespace of the specfied type.
193      *
194      * @param type the type of the namespace
195      * @param ns
196      */

197     public void addNamespace(int type, Namespace ns) {
198         switch( type ) {
199             case PERSONAL : {
200                 addPersonalNamespace(ns);
201                 break;
202             }
203             
204             case OTHER_USER : {
205                 addOtherUserNamespace(ns);
206                 break;
207             }
208             
209             case SHARED : {
210                 addSharedNamespace(ns);
211                 break;
212             }
213         }
214     }
215     
216     /**
217      * @param namespaces
218      */

219     public void addPersonalNamespace(Namespace[] namespaces) {
220         personal.addAll(Arrays.asList(namespaces));
221     }
222
223     /**
224      * @param namespaces
225      */

226     public void addOtherUserNamespace(Namespace[] namespaces) {
227         otherUser.addAll(Arrays.asList(namespaces));
228     }
229     
230     /**
231      * @param namespaces
232      */

233     public void addSharedNamespace(Namespace[] namespaces) {
234         shared.addAll(Arrays.asList(namespaces));
235     }
236     
237     /**
238      * Gets the number of personal namespaces.
239      *
240      * @return the number of personal namespaces
241      */

242     public int getPersonalNamespaceSize() {
243         return personal.size();
244     }
245
246     /**
247      * Gets the number of other-user namespaces.
248      *
249      * @return the number of other-user namespaces
250      */

251     public int getOtherUserNamespaceSize() {
252         return otherUser.size();
253     }
254
255     /**
256      * Gets the number of shared namespaces.
257      *
258      * @return the number of shared namespaces
259      */

260     public int getSharedNamespaceSize() {
261         return shared.size();
262     }
263
264 }
265
Popular Tags