1 25 29 package org.jresearch.gossip.am.ban; 30 31 import java.sql.SQLException ; 32 import java.util.HashSet ; 33 34 import org.jresearch.gossip.dao.UserDAO; 35 import org.jresearch.gossip.exception.SystemException; 36 37 41 public class BanGuard { 42 43 private BanMap banMap = new BanMap(); 44 45 private static BanGuard instance; 46 47 private static Object lock = new Object (); 48 49 private BanGuard() throws SystemException { 50 load(); 51 } 52 53 56 public void load() throws SystemException { 57 UserDAO dao = UserDAO.getInstance(); 58 try { 59 banMap = new BanMap(); 60 dao.fillBanMap(banMap); 61 } catch (SQLException e) { 62 throw new SystemException(e); 63 } 64 } 65 66 70 public static BanGuard getInstance() throws SystemException { 71 if (instance == null) { 72 synchronized (lock) { 73 if (instance == null) { 74 instance = new BanGuard(); 75 } 76 } 77 } 78 return instance; 79 } 80 81 public BanMap getBanMap() throws SystemException { 82 try { 83 return (BanMap) this.banMap.clone(); 84 } catch (CloneNotSupportedException e) { 85 throw new SystemException(e); 86 } 87 } 88 89 94 public boolean checkBan(String name, int type) throws SystemException { 95 HashSet set = banMap.get(type); 96 if (set == null) { 97 return false; 98 } 99 return set.contains(name); 100 } 101 102 } | Popular Tags |