01: /*
02: * Copyright 2001, 2002 The JA-SIG Collaborative. All rights reserved. See
03: * license distributed with this file and available online at
04: * http://www.uportal.org/license.html
05: */
06: package org.jasig.portal.utils.cache;
07:
08: import org.apache.commons.logging.Log;
09: import org.apache.commons.logging.LogFactory;
10: import org.jasig.portal.utils.cache.WhirlyCacheCacheFactory;
11: import org.jasig.portal.spring.PortalApplicationContextFacade;
12:
13: /**
14: *
15: * Convenience locator class for locating the CacheFactory without each class
16: * needing the cache factory to do the lookup in the application context.
17: *
18: * @author Scott Battaglia
19: * @version $Revision: 36756 $ $Date: 2006-11-14 14:52:16 -0700 (Tue, 14 Nov 2006) $
20: * @since 2.5
21: *
22: * @see CacheFactory
23: *
24: */
25: public class CacheFactoryLocator {
26:
27: /** Instance of Commons Logging for logging purposes */
28: private static final Log log = LogFactory
29: .getLog(CacheFactoryLocator.class);
30:
31: /** String name of the CacheFactory we wish to retrieve. */
32: private static final String CACHE_FACTORY_BEAN = "cacheFactory";
33:
34: /** Single instance of the cache factory that uPortal will use. */
35: private static CacheFactory cacheFactory;
36:
37: static {
38: // This form of initialization is necessary b/c we can't bootstrap the entire bean
39: // container to perform tasks based on Ant scripts (e.g. publish channels or portlets).
40: try {
41: cacheFactory = ((CacheFactory) PortalApplicationContextFacade
42: .getPortalApplicationContext().getBean(
43: CACHE_FACTORY_BEAN));
44: } catch (Throwable t) {
45: log.warn("The 'cacheFactory' bean is unavailable");
46: cacheFactory = new WhirlyCacheCacheFactory(); // default...
47: }
48: }
49:
50: /**
51: * Method to retrieve the cache factory
52: * @return the cache factory.
53: */
54: public static final CacheFactory getCacheFactory() {
55: return cacheFactory;
56: }
57: }
|