KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > dods > cache > base > BaseCacheManager


1 /*
2  * Created on May 18, 2005
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package org.enhydra.dods.cache.base;
8
9 import org.enhydra.dods.DODS;
10 import org.enhydra.dods.cache.CacheConstants;
11
12 import com.lutris.appserver.server.sql.DatabaseManagerException;
13 import com.lutris.appserver.server.sql.standard.StandardLogicalDatabase;
14 import com.lutris.logging.Logger;
15
16 /**
17  * @author P.Djojic May 18, 2005 11:47:11 PM
18  *
19  * TODO BaseCacheManager
20  */

21 public class BaseCacheManager {
22     
23     private static DODSCacheAbstractFactory cacheFactory = null;
24     
25     public static boolean isCacheManagerConfigured() {
26         return cacheFactory!=null;
27     }
28     
29     private static void configureCacheFactory() {
30         String JavaDoc logicalDbName = null;
31         String JavaDoc cacheFactoryClassName = null;
32         Class JavaDoc cacheFactoryClass = null;
33         try {
34             logicalDbName = DODS.getDatabaseManager().getDefaultDB();
35             cacheFactoryClassName = ((StandardLogicalDatabase)DODS
36                                                 .getDatabaseManager()
37                                                 .findLogicalDatabase(logicalDbName))
38                                                 .getDatabaseConfiguration()
39                                                 .getDodsCacheFactory();
40             if (cacheFactoryClassName != null) {
41                 try {
42                     cacheFactoryClass = Class.forName(cacheFactoryClassName);
43                     cacheFactory = (DODSCacheAbstractFactory)cacheFactoryClass.newInstance();
44                 } catch (Exception JavaDoc e) {
45                     DODS.getLogChannel()
46                         .write(Logger.ERROR,
47                         "Failed to make DODSCacheFactory :"
48                         + cacheFactoryClassName
49                         + " creating "
50                         + CacheConstants.DEFAULT_DODS_CACHE_FACTORY
51                         + " instead");
52                     cacheFactory = null;
53                 }
54             }
55             if (cacheFactoryClassName == null || cacheFactory == null) {
56                 try {
57                     cacheFactoryClass = Class.forName(CacheConstants.DEFAULT_DODS_CACHE_FACTORY);
58                     cacheFactory = (DODSCacheAbstractFactory) cacheFactoryClass.newInstance();
59                 } catch (Exception JavaDoc e) {
60                     String JavaDoc str = "Failed to make "+CacheConstants.DEFAULT_DODS_CACHE_FACTORY;
61                     DODS.getLogChannel().write(Logger.CRITICAL, str);
62                     throw new Error JavaDoc(str);
63                 }
64             }
65         } catch (DatabaseManagerException e){
66             DODS.getLogChannel().write(Logger.CRITICAL,"Failed to make DODSCacheFactory - CRITICAL ERROR");
67         }
68     }
69     
70     public static DODSCache getDODSCache(int maxSize) {
71         if(!isCacheManagerConfigured()) {
72             configureCacheFactory();
73         }
74             return cacheFactory.newDODSCache(maxSize);
75     }
76 }
77
Popular Tags