KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > ManagerFactory


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/ManagerFactory.java,v 1.10 2006/04/14 17:05:25 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.10 $
5  * $Date: 2006/04/14 17:05:25 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding mvnForum MUST remain
12  * intact in the scripts and in the outputted HTML.
13  * The "powered by" text/logo with a link back to
14  * http://www.mvnForum.com and http://www.MyVietnam.net in
15  * the footer of the pages MUST remain visible when the pages
16  * are viewed on the internet or intranet.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31  *
32  * Support can be obtained from support forums at:
33  * http://www.mvnForum.com/mvnforum/index
34  *
35  * Correspondence and Marketing Questions can be sent to:
36  * info at MyVietnam net
37  *
38  * @author: Luis Miguel Hernanz
39  * @author: Minh Nguyen
40  */

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 /**
52  * Instance that returns the right implementation for the different
53  * parts of the mvnforum system.
54  *
55  * @author <a HREF="luish@germinus.com">Luis Miguel Hernanz</a>
56  * @version $Revision: 1.10 $
57  */

58 // @todo : split this class to new class DAOFactory
59
public class ManagerFactory {
60
61     private static Log log = LogFactory.getLog(ManagerFactory.class);
62
63     /**
64      * Creates a new <code>ManagerFactory</code> instance.
65      */

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 JavaDoc c = Class.forName(MVNForumFactoryConfig.getOnlineUserFactoryClassName());
77                 onlineUserFactory = (OnlineUserFactory) c.newInstance();
78                 log.info("onlineUserFactory = " + onlineUserFactory);
79             } catch (Exception JavaDoc e) {
80                 log.error("Error returning the online user factory.", e);
81                 throw new RuntimeException JavaDoc(e.getMessage());
82             }
83         }
84         return onlineUserFactory;
85     }
86
87     public static synchronized Authenticator getAuthenticator() {
88         try {
89             String JavaDoc authenticatorClass = MVNForumFactoryConfig.getAuthenticatorClassName();
90             if ((null != authenticatorClass) && !authenticatorClass.trim().equals("")) {
91                 log.debug("Try loading the authenticator: " + authenticatorClass);
92                 if (authenticator == null) {
93                     Class JavaDoc c = Class.forName(authenticatorClass);
94                     authenticator = (Authenticator) c.newInstance();
95                     log.info("authenticator = " + authenticator);
96                 }
97                 return authenticator;
98             }
99         } catch (Exception JavaDoc 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 JavaDoc c = Class.forName(MVNForumFactoryConfig.getRequestProcessorClassName());
109                 requestProcessor = (RequestProcessor) c.newInstance();
110                 log.info("requestProcessor = " + requestProcessor);
111             } catch (Exception JavaDoc e) {
112                 // This should never happen
113
log.error("Error returning the requestProcessor.", e);
114                 throw new RuntimeException JavaDoc(e.getMessage());
115             }
116         }
117         return requestProcessor;
118     }
119
120     public static synchronized BinaryStorage getBinaryStorage() {
121         if (binaryStorage == null) {
122             try {
123                 Class JavaDoc c = Class.forName(MVNForumFactoryConfig.getBinaryStorageClassName());
124                 binaryStorage = (BinaryStorage) c.newInstance();
125                 log.info("binaryStorage = " + binaryStorage);
126             } catch (Exception JavaDoc e) {
127                 // This should never happen
128
log.error("Error returning the binaryStorage.", e);
129                 throw new RuntimeException JavaDoc(e.getMessage());
130             }
131         }
132         return binaryStorage;
133     }
134
135 }
136
Popular Tags