1 package com.sslexplorer.core; 2 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 6 13 public class AbstractFactory { 14 static Log log = LogFactory.getLog(AbstractFactory.class); 15 16 static AbstractFactory instance; 17 static Class factoryImpl = null; 18 private static boolean locked = false; 19 20 27 public static AbstractFactory getAbstractInstance() { 28 try { 29 if(instance == null) { 30 if(factoryImpl == null) { 31 throw new Exception ("Not factory implementation class has been set."); 32 } 33 instance = (AbstractFactory) factoryImpl.newInstance(); 34 } 35 return instance; 36 } catch (Exception e) { 37 log.error("Could not create instance of class " + factoryImpl.getCanonicalName(), e); 38 return instance == null ? instance = new AbstractFactory() : instance; 39 } 40 } 41 42 50 public static void setFactoryImpl(Class factoryImpl, boolean lock) throws IllegalStateException { 51 if (locked) { 52 throw new IllegalStateException ("Factory has been locked by someone else."); 53 } 54 AbstractFactory.factoryImpl = factoryImpl; 55 locked = lock; 56 } 57 } 58 | Popular Tags |