1 18 package org.apache.roller.model; 19 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 import org.apache.roller.RollerException; 24 import org.apache.roller.config.RollerConfig; 25 import org.apache.commons.lang.StringUtils; 26 27 38 public abstract class RollerFactory 39 { 40 private static final String DEFAULT_IMPL = 41 "org.apache.roller.business.hibernate.HibernateRollerImpl"; 42 43 private static Roller rollerInstance = null; 44 45 private static Log mLogger = 46 LogFactory.getFactory().getInstance(RollerFactory.class); 47 48 52 private RollerFactory() 53 { 54 } 56 57 63 public static Roller getRoller() 64 { 65 if(rollerInstance == null) { 67 String roller_classname = 69 RollerConfig.getProperty("persistence.roller.classname"); 70 71 RollerFactory.setRoller(roller_classname); 73 } 74 75 return rollerInstance; 76 } 77 78 79 90 public static void setRoller(String roller_classname) 91 { 92 93 if (StringUtils.isEmpty( roller_classname )) 94 roller_classname = DEFAULT_IMPL; 95 96 try 97 { 98 Class rollerClass = Class.forName(roller_classname); 99 java.lang.reflect.Method instanceMethod = 100 rollerClass.getMethod("instantiate", (Class [])null); 101 102 rollerInstance = (Roller) 104 instanceMethod.invoke(rollerClass, (Object [])null); 105 106 mLogger.info("Using Roller Impl: " + roller_classname); 107 } 108 catch (Exception e) 109 { 110 mLogger.error("Error instantiating " + roller_classname, e); 112 try 113 { 114 if( ! DEFAULT_IMPL.equals(roller_classname)) 116 { 117 mLogger.info("** Trying DEFAULT_IMPL "+DEFAULT_IMPL+" **"); 118 119 Class rollerClass = Class.forName(DEFAULT_IMPL); 120 java.lang.reflect.Method instanceMethod = 121 rollerClass.getMethod("instantiate", (Class [])null); 122 123 rollerInstance = (Roller) 125 instanceMethod.invoke(rollerClass, (Object [])null); 126 } 127 else 128 { 129 throw new Exception ("Doh! Couldn't instantiate a roller class"); 131 } 132 133 } 134 catch (Exception re) 135 { 136 mLogger.fatal("Failed to instantiate fallback roller impl", re); 137 } 138 } 139 140 } 141 142 143 146 public static void setRoller(Roller roller) 147 { 148 if (roller != null) rollerInstance = roller; 149 } 150 } 151 | Popular Tags |