KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > pop3 > POP3ServerCollection


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.mail.pop3;
17
18 import java.util.List JavaDoc;
19 import java.util.ListIterator JavaDoc;
20 import java.util.Vector JavaDoc;
21 import java.util.logging.Logger JavaDoc;
22
23 import org.columba.mail.config.AccountItem;
24 import org.columba.mail.config.AccountList;
25 import org.columba.mail.config.MailConfig;
26
27 public class POP3ServerCollection { // implements ActionListener
28

29     /** JDK 1.4+ logging framework logger, used for logging. */
30     private static final Logger JavaDoc LOG = Logger.getLogger("org.columba.mail.pop3");
31
32     private List JavaDoc serverList;
33
34     private POP3Server popServer;
35
36     private static POP3ServerCollection instance = new POP3ServerCollection();
37
38     public POP3ServerCollection() {
39         serverList = new Vector JavaDoc();
40
41         AccountList list = MailConfig.getInstance().getAccountList();
42
43         for (int i = 0; i < list.count(); i++) {
44             AccountItem accountItem = list.get(i);
45
46             if (accountItem.isPopAccount()) {
47                 add(accountItem);
48             }
49         }
50     }
51
52     public static POP3ServerCollection getInstance() {
53         return instance;
54     }
55
56     public ListIterator JavaDoc getServerIterator() {
57         return serverList.listIterator();
58     }
59
60     public POP3Server[] getList() {
61         POP3Server[] list = new POP3Server[count()];
62
63         ((Vector JavaDoc) serverList).copyInto(list);
64
65         return list;
66     }
67
68     public void add(AccountItem item) {
69         POP3Server server = new POP3Server(item);
70         serverList.add(server);
71
72         /*
73          * notifyListeners(new ModelChangedEvent(ModelChangedEvent.ADDED,
74          * server));
75          */

76     }
77
78     public POP3Server uidGet(int uid) {
79         int index = getIndex(uid);
80
81         if (index != -1) {
82             return get(index);
83         } else {
84             return null;
85         }
86     }
87
88     public POP3Server get(int index) {
89         return (POP3Server) serverList.get(index);
90     }
91
92     public int count() {
93         return serverList.size();
94     }
95
96     public void removePopServer(int uid) {
97         int index = getIndex(uid);
98         
99
100         if (index == -1) {
101             LOG.severe("could not find popserver");
102
103             return;
104         } else {
105             serverList.remove(index);
106         }
107
108         /*
109          * notifyListeners(new ModelChangedEvent(ModelChangedEvent.REMOVED));
110          */

111     }
112
113     public int getIndex(int uid) {
114         POP3Server c;
115         int number;
116         for (int i = 0; i < count(); i++) {
117             c = get(i);
118             number = c.getAccountItem().getUid();
119
120             if (number == uid) {
121                 return i;
122             }
123         }
124
125         return -1;
126     }
127
128     public void saveAll() {
129         POP3Server c;
130
131         for (int i = 0; i < count(); i++) {
132             c = get(i);
133
134             try {
135                 c.save();
136             } catch (Exception JavaDoc ex) {
137                 ex.printStackTrace();
138             }
139         }
140     }
141
142     public POP3Server getSelected() {
143         return popServer;
144     }
145
146     /*
147      * public void addModelListener(ModelChangeListener l) { listeners.add(l); }
148      *
149      * private void notifyListeners(ModelChangedEvent e) { for (Iterator it =
150      * listeners.iterator(); it.hasNext();) { ((ModelChangeListener)
151      * it.next()).modelChanged(e); // for (int i = 0; i < listeners.size(); i++) { //
152      * ((ModelChangeListener) listeners.get(i)).modelChanged(e); } }
153      */

154 }
155
Popular Tags