001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.mail.pop3;
017:
018: import java.util.List;
019: import java.util.ListIterator;
020: import java.util.Vector;
021: import java.util.logging.Logger;
022:
023: import org.columba.mail.config.AccountItem;
024: import org.columba.mail.config.AccountList;
025: import org.columba.mail.config.MailConfig;
026:
027: public class POP3ServerCollection { // implements ActionListener
028:
029: /** JDK 1.4+ logging framework logger, used for logging. */
030: private static final Logger LOG = Logger
031: .getLogger("org.columba.mail.pop3");
032:
033: private List serverList;
034:
035: private POP3Server popServer;
036:
037: private static POP3ServerCollection instance = new POP3ServerCollection();
038:
039: public POP3ServerCollection() {
040: serverList = new Vector();
041:
042: AccountList list = MailConfig.getInstance().getAccountList();
043:
044: for (int i = 0; i < list.count(); i++) {
045: AccountItem accountItem = list.get(i);
046:
047: if (accountItem.isPopAccount()) {
048: add(accountItem);
049: }
050: }
051: }
052:
053: public static POP3ServerCollection getInstance() {
054: return instance;
055: }
056:
057: public ListIterator getServerIterator() {
058: return serverList.listIterator();
059: }
060:
061: public POP3Server[] getList() {
062: POP3Server[] list = new POP3Server[count()];
063:
064: ((Vector) serverList).copyInto(list);
065:
066: return list;
067: }
068:
069: public void add(AccountItem item) {
070: POP3Server server = new POP3Server(item);
071: serverList.add(server);
072:
073: /*
074: * notifyListeners(new ModelChangedEvent(ModelChangedEvent.ADDED,
075: * server));
076: */
077: }
078:
079: public POP3Server uidGet(int uid) {
080: int index = getIndex(uid);
081:
082: if (index != -1) {
083: return get(index);
084: } else {
085: return null;
086: }
087: }
088:
089: public POP3Server get(int index) {
090: return (POP3Server) serverList.get(index);
091: }
092:
093: public int count() {
094: return serverList.size();
095: }
096:
097: public void removePopServer(int uid) {
098: int index = getIndex(uid);
099:
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 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: }
|