1 package org.columba.mail.pop3; 17 18 import java.util.List ; 19 import java.util.ListIterator ; 20 import java.util.Vector ; 21 import java.util.logging.Logger ; 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 { 29 30 private static final Logger LOG = Logger.getLogger("org.columba.mail.pop3"); 31 32 private List serverList; 33 34 private POP3Server popServer; 35 36 private static POP3ServerCollection instance = new POP3ServerCollection(); 37 38 public POP3ServerCollection() { 39 serverList = new Vector (); 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 getServerIterator() { 57 return serverList.listIterator(); 58 } 59 60 public POP3Server[] getList() { 61 POP3Server[] list = new POP3Server[count()]; 62 63 ((Vector ) 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 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 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 154 } 155 | Popular Tags |