KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > policyframework > PolicyDatabaseFactory


1 package com.sslexplorer.policyframework;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5
6 import com.sslexplorer.jdbc.JDBCPolicyDatabase;
7
8 /**
9  * Policy factory for creating policy 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 PolicyDatabaseFactory {
16     static Log log = LogFactory.getLog(PolicyDatabaseFactory.class);
17
18     static PolicyDatabase instance;
19     static Class JavaDoc policyDatabaseImpl = JDBCPolicyDatabase.class;
20     private static boolean locked = false;
21
22     /**
23      * @return An instance of the policy database factory.
24      */

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

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