KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > security > SystemDatabaseFactory


1 package com.sslexplorer.security;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5
6 import com.sslexplorer.jdbc.JDBCSystemDatabase;
7
8 /**
9  * System database factory for creating system databases.
10  *
11  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
12  *
13  *
14  */

15 public class SystemDatabaseFactory {
16     static Log log = LogFactory.getLog(SystemDatabaseFactory.class);
17
18     static SystemDatabase instance;
19     static Class JavaDoc systemDatabaseImpl = JDBCSystemDatabase.class;
20     private static boolean locked = false;
21
22     /**
23      * @return An instance of the system database factory.
24      */

25     public static SystemDatabase getInstance() {
26         try {
27             return instance == null ? instance = (SystemDatabase) systemDatabaseImpl.newInstance() : instance;
28         } catch (Exception JavaDoc e) {
29             log.error("Could not create instance of class " + systemDatabaseImpl.getCanonicalName(), e);
30             return instance == null ? instance = new JDBCSystemDatabase() : instance;
31         }
32     }
33
34
35     /**
36      * @param systemDatabaseImpl the class of the system database
37      * @param lock weather to lock the system database after setting it.
38      * @throws IllegalStateException
39      */

40     public static void setFactoryImpl(Class JavaDoc systemDatabaseImpl, boolean lock) throws IllegalStateException JavaDoc {
41         if (locked) {
42             throw new IllegalStateException JavaDoc("System database factory has been locked by another plugin.");
43         }
44         SystemDatabaseFactory.systemDatabaseImpl = systemDatabaseImpl;
45         locked = lock;
46     }
47 }
48
Popular Tags