1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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