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