KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > properties > ProfilesFactory


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

16 public class ProfilesFactory {
17     static Log log = LogFactory.getLog(ProfilesFactory.class);
18
19     static PropertyDatabase instance;
20     static Class JavaDoc propertyDatabaseImpl = JDBCPropertyDatabase.class;
21     private static boolean locked = false;
22
23     /**
24      * @return An instance of the profile database.
25      */

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

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