View Javadoc

1   /*
2   MadCaching is a Tile Caching solution
3   Copyright (C) 2005  Mac Vu
4   
5   This program is free software; you can redistribute it and/or
6   modify it under the terms of the GNU General Public License
7   as published by the Free Software Foundation; either version 2
8   of the License, or (at your option) any later version.
9   
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  GNU General Public License for more details.
14  
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18   */
19  package com.macvu.tiles.cache;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  /***
25   * User: MVu
26   */
27  public class CacheFactoryManager {
28      Map cacheFactoryMap;
29      Map keyFactoryMap;
30  
31      public CacheFactoryManager() {
32          cacheFactoryMap = new HashMap();
33          keyFactoryMap = new HashMap();
34      }
35  
36      public synchronized CacheServiceFactory getCacheServiceFactory(String factoryName) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
37          CacheServiceFactory cacheServiceFactory = (CacheServiceFactory) cacheFactoryMap.get(factoryName);
38          if (cacheServiceFactory == null) {
39              Class clazz = CacheObjectWrapper.applicationClass(factoryName);
40              cacheServiceFactory = (CacheServiceFactory) clazz.newInstance();
41              cacheFactoryMap.put(factoryName, cacheServiceFactory);
42          }
43  
44          return cacheServiceFactory;
45      }
46  
47      public synchronized CacheKeyFactory getCacheKeyFactory(String factoryName) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
48          CacheKeyFactory cacheKeyFactory = (CacheKeyFactory) keyFactoryMap.get(factoryName);
49          if (cacheKeyFactory == null) {
50              Class clazz = CacheObjectWrapper.applicationClass(factoryName);
51              cacheKeyFactory = (CacheKeyFactory) clazz.newInstance();
52              cacheFactoryMap.put(factoryName, cacheKeyFactory);
53          }
54  
55          return cacheKeyFactory;
56      }
57  }
58