KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > am > ban > BanGuard


1 /*
2  * $Id: BanGuard.java,v 1.3 2005/06/07 12:32:31 bel70 Exp $
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * The contents of this file are subject to the Mozilla Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License
8  * at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * The Original Code is JGossip forum code.
16  *
17  * The Initial Developer of the Original Code is the JResearch, Org.
18  * Portions created by the Initial Developer are Copyright (C) 2004
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Dmitriy Belov <bel@jresearch.org>
23  * .
24  * * ***** END LICENSE BLOCK ***** */

25 /*
26  * Created on 29.08.2004
27  *
28  */

29 package org.jresearch.gossip.am.ban;
30
31 import java.sql.SQLException JavaDoc;
32 import java.util.HashSet JavaDoc;
33
34 import org.jresearch.gossip.dao.UserDAO;
35 import org.jresearch.gossip.exception.SystemException;
36
37 /**
38  * @author Dmitry Belov
39  *
40  */

41 public class BanGuard {
42
43     private BanMap banMap = new BanMap();
44
45     private static BanGuard instance;
46
47     private static Object JavaDoc lock = new Object JavaDoc();
48
49     private BanGuard() throws SystemException {
50         load();
51     }
52
53     /**
54      * @throws SystemException
55      */

56     public void load() throws SystemException {
57         UserDAO dao = UserDAO.getInstance();
58         try {
59             banMap = new BanMap();
60             dao.fillBanMap(banMap);
61         } catch (SQLException JavaDoc e) {
62             throw new SystemException(e);
63         }
64     }
65
66     /**
67      * @return
68      * @throws SystemException
69      */

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 JavaDoc e) {
85             throw new SystemException(e);
86         }
87     }
88
89     /**
90      * @param name
91      * @param login
92      * @throws SystemException
93      */

94     public boolean checkBan(String JavaDoc name, int type) throws SystemException {
95         HashSet JavaDoc set = banMap.get(type);
96         if (set == null) {
97             return false;
98         }
99         return set.contains(name);
100     }
101
102 }
Popular Tags