1 41 package com.mvnforum; 42 43 import net.myvietnam.mvncore.service.BinaryStorage; 44 45 import org.apache.commons.logging.Log; 46 import org.apache.commons.logging.LogFactory; 47 48 import com.mvnforum.auth.Authenticator; 49 import com.mvnforum.auth.OnlineUserFactory; 50 51 58 public class ManagerFactory { 60 61 private static Log log = LogFactory.getLog(ManagerFactory.class); 62 63 66 protected ManagerFactory() {} 67 68 private static OnlineUserFactory onlineUserFactory = null; 69 private static Authenticator authenticator = null; 70 private static RequestProcessor requestProcessor = null; 71 private static BinaryStorage binaryStorage = null; 72 73 public static synchronized OnlineUserFactory getOnlineUserFactory() { 74 if (onlineUserFactory == null) { 75 try { 76 Class c = Class.forName(MVNForumFactoryConfig.getOnlineUserFactoryClassName()); 77 onlineUserFactory = (OnlineUserFactory) c.newInstance(); 78 log.info("onlineUserFactory = " + onlineUserFactory); 79 } catch (Exception e) { 80 log.error("Error returning the online user factory.", e); 81 throw new RuntimeException (e.getMessage()); 82 } 83 } 84 return onlineUserFactory; 85 } 86 87 public static synchronized Authenticator getAuthenticator() { 88 try { 89 String authenticatorClass = MVNForumFactoryConfig.getAuthenticatorClassName(); 90 if ((null != authenticatorClass) && !authenticatorClass.trim().equals("")) { 91 log.debug("Try loading the authenticator: " + authenticatorClass); 92 if (authenticator == null) { 93 Class c = Class.forName(authenticatorClass); 94 authenticator = (Authenticator) c.newInstance(); 95 log.info("authenticator = " + authenticator); 96 } 97 return authenticator; 98 } 99 } catch (Exception e){ 100 log.error("Error getting the authentication object", e); 101 } 102 return null; 103 } 104 105 public static synchronized RequestProcessor getRequestProcessor() { 106 if (requestProcessor == null) { 107 try { 108 Class c = Class.forName(MVNForumFactoryConfig.getRequestProcessorClassName()); 109 requestProcessor = (RequestProcessor) c.newInstance(); 110 log.info("requestProcessor = " + requestProcessor); 111 } catch (Exception e) { 112 log.error("Error returning the requestProcessor.", e); 114 throw new RuntimeException (e.getMessage()); 115 } 116 } 117 return requestProcessor; 118 } 119 120 public static synchronized BinaryStorage getBinaryStorage() { 121 if (binaryStorage == null) { 122 try { 123 Class c = Class.forName(MVNForumFactoryConfig.getBinaryStorageClassName()); 124 binaryStorage = (BinaryStorage) c.newInstance(); 125 log.info("binaryStorage = " + binaryStorage); 126 } catch (Exception e) { 127 log.error("Error returning the binaryStorage.", e); 129 throw new RuntimeException (e.getMessage()); 130 } 131 } 132 return binaryStorage; 133 } 134 135 } 136 | Popular Tags |