001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/ManagerFactory.java,v 1.20 2007/10/09 11:09:21 lexuanttkhtn Exp $
003: * $Author: lexuanttkhtn $
004: * $Revision: 1.20 $
005: * $Date: 2007/10/09 11:09:21 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author: Luis Miguel Hernanz
039: * @author: Minh Nguyen
040: */
041: package com.mvnforum;
042:
043: import org.apache.commons.logging.Log;
044: import org.apache.commons.logging.LogFactory;
045:
046: import com.mvnforum.auth.Authenticator;
047: import com.mvnforum.auth.OnlineUserFactory;
048: import com.mvnforum.auth.service.MvnAuthServiceFactory;
049:
050: /**
051: * Instance that returns the right implementation for the different
052: * parts of the mvnforum system.
053: *
054: * @author <a href="luish@germinus.com">Luis Miguel Hernanz</a>
055: * @version $Revision: 1.20 $
056: */
057: // @todo : split this class to new class DAOFactory
058: public class ManagerFactory {
059:
060: private static Log log = LogFactory.getLog(ManagerFactory.class);
061:
062: /**
063: * Creates a new <code>ManagerFactory</code> instance.
064: */
065: protected ManagerFactory() {
066: }
067:
068: private static OnlineUserFactory onlineUserFactory = null;
069: private static Authenticator authenticator = null;
070: private static RequestProcessor requestProcessor = null;
071:
072: public static synchronized OnlineUserFactory getOnlineUserFactory() {
073: if (onlineUserFactory == null) {
074: try {
075: //Class c = Class.forName(MVNForumFactoryConfig.getOnlineUserFactoryClassName());
076: //onlineUserFactory = (OnlineUserFactory) c.newInstance();
077: onlineUserFactory = MvnAuthServiceFactory
078: .getMvnAuthService().getOnlineUserFactory();
079: log.info("onlineUserFactory = " + onlineUserFactory);
080: } catch (Exception e) {
081: log
082: .error(
083: "Error returning the online user factory.",
084: e);
085: throw new RuntimeException(e.getMessage());
086: }
087: }
088: return onlineUserFactory;
089: }
090:
091: public static synchronized Authenticator getAuthenticator() {
092:
093: if (authenticator != null) {
094: return authenticator;
095: }
096:
097: try {
098: String authenticatorClass = MVNForumFactoryConfig
099: .getAuthenticatorClassName();
100: if ((null != authenticatorClass)
101: && (authenticatorClass.trim().length() > 0)) {
102: log.debug("Try loading the authenticator: "
103: + authenticatorClass);
104: if (authenticator == null) {
105: Class c = Class.forName(authenticatorClass);
106: authenticator = (Authenticator) c.newInstance();
107: log.info("authenticator = " + authenticator);
108: }
109: return authenticator;
110: }
111: } catch (Exception e) {
112: log.error("Error getting the authentication object", e);
113: }
114: return null;
115: }
116:
117: public static synchronized RequestProcessor getRequestProcessor() {
118: if (requestProcessor == null) {
119: try {
120: Class c = Class.forName(MVNForumFactoryConfig
121: .getRequestProcessorClassName());
122: requestProcessor = (RequestProcessor) c.newInstance();
123: log.info("requestProcessor = " + requestProcessor);
124: } catch (Exception e) {
125: // This should never happen
126: log.error("Error returning the requestProcessor.", e);
127: throw new RuntimeException(e.getMessage());
128: }
129: }
130: return requestProcessor;
131: }
132:
133: }
|