KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > webforwards > WebForwardDatabaseFactory


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.webforwards;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 /**
26  * System database factory for creating web forward databases.
27  *
28  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
29  *
30  *
31  */

32 public class WebForwardDatabaseFactory {
33     static Log log = LogFactory.getLog(WebForwardDatabaseFactory.class);
34
35     static WebForwardDatabase instance;
36     static Class JavaDoc webForwardDatabaseImpl = JDBCWebForwardDatabase.class;
37     private static boolean locked = false;
38
39     /**
40      * @return An instance of the system database factory.
41      */

42     public static WebForwardDatabase getInstance() {
43         try {
44             return instance == null ? instance = (WebForwardDatabase) webForwardDatabaseImpl.newInstance() : instance;
45         } catch (Exception JavaDoc e) {
46             log.error("Could not create instance of class " + webForwardDatabaseImpl.getCanonicalName(), e);
47             return instance == null ? instance = new JDBCWebForwardDatabase() : instance;
48         }
49     }
50
51
52     /**
53      * @param webForwardDatabaseImpl the class of the webforward database
54      * @param lock weather to lock the policy database after setting it.
55      * @throws IllegalStateException
56      */

57     public static void setFactoryImpl(Class JavaDoc webForwardDatabaseImpl, boolean lock) throws IllegalStateException JavaDoc {
58         if (locked) {
59             throw new IllegalStateException JavaDoc("WebForward database factory has been locked by another plugin.");
60         }
61         WebForwardDatabaseFactory.webForwardDatabaseImpl = webForwardDatabaseImpl;
62         locked = lock;
63     }
64 }
65
Popular Tags