KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > tunnels > TunnelDatabaseFactory


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.tunnels;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 /**
26  * System database factory for creating system databases.
27  *
28  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
29  *
30  */

31 public class TunnelDatabaseFactory {
32     static Log log = LogFactory.getLog(TunnelDatabaseFactory.class);
33
34     static TunnelDatabase instance;
35     static Class JavaDoc tunnelDatabaseImpl = JDBCTunnelDatabase.class;
36     private static boolean locked = false;
37
38     /**
39      * @return An instance of the tunnel database factory.
40      */

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

55     public static void setFactoryImpl(Class JavaDoc tunnelDatabaseImpl, boolean lock) throws IllegalStateException JavaDoc {
56         if (locked) {
57             throw new IllegalStateException JavaDoc("System database factory has been locked by another plugin.");
58         }
59         TunnelDatabaseFactory.tunnelDatabaseImpl = tunnelDatabaseImpl;
60         locked = lock;
61     }
62 }
63
Popular Tags