KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > sps > common > DataStoreManagerFactory


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.syncclient.sps.common;
20
21 import java.util.Hashtable JavaDoc;
22
23 import sync4j.syncclient.common.logging.Logger;
24
25 /**
26 * This class return dataStoreManager
27 * from Class.forName instance
28 * about user class DataStoreImpl
29 *
30 * @author Fabio Maggi @ Funambol
31 * $Id: DataStoreManagerFactory.java,v 1.4 2005/01/19 11:18:36 fabius Exp $
32 **/

33 public class DataStoreManagerFactory {
34
35      //---------------------------------------------------------------- Constants
36

37     public static final String JavaDoc DATASTORE_MANAGER_FILE_NAME_END = "StoreManager";
38
39     //----------------------------------------------------------------- Private data
40

41     private static Logger logger = new Logger();
42
43     //----------------------------------------------------------------- Public methods
44

45
46     /**
47      * The same as <code>getDataStoreManager(storeManager, storeManagerPackage, getClass().getClassLoader())</code>
48      *
49      * @return dataStoreManager
50      */

51     public static DataStoreManager getDataStoreManager(String JavaDoc storeManager, String JavaDoc storeManagerPackage) {
52         return getDataStoreManager(
53             storeManager, storeManagerPackage, DataStoreManager.class.getClassLoader()
54         );
55     }
56
57     public static DataStoreManager getDataStoreManager(String JavaDoc storeManager ,
58                                                        String JavaDoc storeManagerPackage,
59                                                        ClassLoader JavaDoc loader ) {
60         DataStoreManager dataStoreManager = null;
61
62         try {
63             String JavaDoc className = storeManagerPackage + '.' + storeManager + DATASTORE_MANAGER_FILE_NAME_END;
64             if (logger.isLoggable(Logger.DEBUG)) {
65                 logger.debug("Creating a new instance of " + className);
66             }
67             dataStoreManager = (DataStoreManager) (loader.loadClass(className)).newInstance();
68         } catch (Exception JavaDoc e) {
69             e.printStackTrace();
70             if (logger.isLoggable(Logger.INFO)) {
71                 logger.info("Error in loading class: " + e.getMessage());
72             }
73         }
74
75         return dataStoreManager;
76     }
77
78
79 }
Popular Tags