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 15 public class PolicyDatabaseFactory { 16 static Log log = LogFactory.getLog(PolicyDatabaseFactory.class); 17 18 static PolicyDatabase instance; 19 static Class policyDatabaseImpl = JDBCPolicyDatabase.class; 20 private static boolean locked = false; 21 22 25 public static PolicyDatabase getInstance() { 26 try { 27 return instance == null ? instance = (PolicyDatabase) policyDatabaseImpl.newInstance() : instance; 28 } catch (Exception 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 40 public static void setFactoryImpl(Class policyDatabaseImpl, boolean lock) throws IllegalStateException { 41 if (locked) { 42 throw new IllegalStateException ("Policy database factory has been locked by another plugin."); 43 } 44 PolicyDatabaseFactory.policyDatabaseImpl = policyDatabaseImpl; 45 locked = lock; 46 } 47 } 48 | Popular Tags |