1 17 package org.alfresco.filesys.server.core; 18 19 import java.util.Enumeration ; 20 import java.util.Hashtable ; 21 22 26 public class SharedDeviceList 27 { 28 29 31 private Hashtable <String , SharedDevice> m_shares; 32 33 36 public SharedDeviceList() 37 { 38 39 41 m_shares = new Hashtable <String , SharedDevice>(); 42 } 43 44 49 public SharedDeviceList(SharedDeviceList shrList) 50 { 51 52 54 m_shares = new Hashtable <String , SharedDevice>(); 55 56 58 addShares(shrList); 59 } 60 61 67 public final boolean addShare(SharedDevice shr) 68 { 69 70 72 if (m_shares.containsKey(shr.getName())) 73 return false; 74 75 77 m_shares.put(shr.getName(), shr); 78 return true; 79 } 80 81 86 public final void addShares(SharedDeviceList shrList) 87 { 88 89 91 Enumeration <SharedDevice> enm = shrList.enumerateShares(); 92 93 while (enm.hasMoreElements()) 94 addShare(enm.nextElement()); 95 } 96 97 103 public final SharedDevice deleteShare(String name) 104 { 105 106 108 return (SharedDevice) m_shares.remove(name); 109 } 110 111 116 public final Enumeration <SharedDevice> enumerateShares() 117 { 118 return m_shares.elements(); 119 } 120 121 127 public final SharedDevice findShare(String name) 128 { 129 return m_shares.get(name); 130 } 131 132 140 public final SharedDevice findShare(String name, int typ, boolean nocase) 141 { 142 143 145 Enumeration <String > keys = m_shares.keys(); 146 147 while (keys.hasMoreElements()) 148 { 149 150 152 String curName = keys.nextElement(); 153 154 if ((nocase == false && curName.equals(name)) || (nocase == true && curName.equalsIgnoreCase(name))) 155 { 156 157 159 SharedDevice share = (SharedDevice) m_shares.get(curName); 160 if (share.getType() == typ || typ == ShareType.UNKNOWN) 161 return share; 162 } 163 } 164 165 167 return null; 168 } 169 170 175 public final int numberOfShares() 176 { 177 return m_shares.size(); 178 } 179 180 185 public final int removeUnavailableShares() 186 { 187 188 190 Enumeration <SharedDevice> shrEnum = enumerateShares(); 191 int remCnt = 0; 192 193 while (shrEnum.hasMoreElements()) 194 { 195 196 198 SharedDevice shr = shrEnum.nextElement(); 199 if (shr.getContext() != null && shr.getContext().isAvailable() == false) 200 { 201 deleteShare(shr.getName()); 202 remCnt++; 203 } 204 } 205 206 208 return remCnt; 209 } 210 211 214 public final void removeAllShares() 215 { 216 m_shares.clear(); 217 } 218 219 224 public String toString() 225 { 226 227 229 StringBuffer str = new StringBuffer (); 230 str.append("["); 231 232 234 Enumeration <String > enm = m_shares.keys(); 235 236 while (enm.hasMoreElements()) 237 { 238 String name = enm.nextElement(); 239 str.append(name); 240 str.append(","); 241 } 242 243 245 if (str.length() > 1) 246 str.setLength(str.length() - 1); 247 str.append("]"); 248 249 251 return str.toString(); 252 } 253 } | Popular Tags |