1 package org.roller.model; 2 3 4 import org.apache.commons.logging.Log; 5 import org.apache.commons.logging.LogFactory; 6 import org.roller.RollerException; 7 import org.roller.config.RollerConfig; 8 import org.roller.util.StringUtils; 9 10 21 public abstract class RollerFactory 22 { 23 private static final String DEFAULT_IMPL = 24 "org.roller.business.hibernate.HibernateRollerImpl"; 25 26 private static Roller rollerInstance = null; 27 28 private static Log mLogger = 29 LogFactory.getFactory().getInstance(RollerFactory.class); 30 31 35 private RollerFactory() 36 { 37 } 39 40 46 public static Roller getRoller() 47 { 48 if(rollerInstance == null) { 50 String roller_classname = 52 RollerConfig.getProperty("persistence.roller.classname"); 53 54 RollerFactory.setRoller(roller_classname); 56 } 57 58 return rollerInstance; 59 } 60 61 62 73 public static void setRoller(String roller_classname) 74 { 75 76 if (StringUtils.isEmpty( roller_classname )) 77 roller_classname = DEFAULT_IMPL; 78 79 try 80 { 81 Class rollerClass = Class.forName(roller_classname); 82 java.lang.reflect.Method instanceMethod = 83 rollerClass.getMethod("instantiate", (Class [])null); 84 85 rollerInstance = (Roller) 87 instanceMethod.invoke(rollerClass, (Class [])null); 88 89 mLogger.info("Using Roller Impl: " + roller_classname); 90 } 91 catch (Exception e) 92 { 93 mLogger.error("Error instantiating " + roller_classname, e); 95 try 96 { 97 if( ! DEFAULT_IMPL.equals(roller_classname)) 99 { 100 mLogger.info("** Trying DEFAULT_IMPL "+DEFAULT_IMPL+" **"); 101 102 Class rollerClass = Class.forName(DEFAULT_IMPL); 103 java.lang.reflect.Method instanceMethod = 104 rollerClass.getMethod("instantiate", (Class [])null); 105 106 rollerInstance = (Roller) 108 instanceMethod.invoke(rollerClass, (Class [])null); 109 } 110 else 111 { 112 throw new Exception ("Doh! Couldn't instantiate a roller class"); 114 } 115 116 } 117 catch (Exception re) 118 { 119 mLogger.fatal("Failed to instantiate fallback roller impl", re); 120 } 121 } 122 123 } 124 125 126 129 public static void setRoller(Roller roller) 130 { 131 if (roller != null) rollerInstance = roller; 132 } 133 } 134 | Popular Tags |