1 19 20 package com.sslexplorer.tunnels; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 31 public class TunnelDatabaseFactory { 32 static Log log = LogFactory.getLog(TunnelDatabaseFactory.class); 33 34 static TunnelDatabase instance; 35 static Class tunnelDatabaseImpl = JDBCTunnelDatabase.class; 36 private static boolean locked = false; 37 38 41 public static TunnelDatabase getInstance() { 42 try { 43 return instance == null ? instance = (TunnelDatabase) tunnelDatabaseImpl.newInstance() : instance; 44 } catch (Exception e) { 45 log.error("Could not create instance of class " + tunnelDatabaseImpl.getCanonicalName(), e); 46 return instance == null ? instance = new JDBCTunnelDatabase() : instance; 47 } 48 } 49 50 55 public static void setFactoryImpl(Class tunnelDatabaseImpl, boolean lock) throws IllegalStateException { 56 if (locked) { 57 throw new IllegalStateException ("System database factory has been locked by another plugin."); 58 } 59 TunnelDatabaseFactory.tunnelDatabaseImpl = tunnelDatabaseImpl; 60 locked = lock; 61 } 62 } 63 | Popular Tags |