01: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.spring;
07:
08: import org.springframework.beans.factory.BeanFactory;
09: import org.springframework.beans.factory.access.BeanFactoryLocator;
10: import org.springframework.beans.factory.access.BeanFactoryReference;
11: import org.springframework.beans.factory.access.SingletonBeanFactoryLocator;
12:
13: /**
14: * Static bean factory locator service for the uPortal framework.
15: * <br>
16: * This class reads the 'properties/beanRefFactory.xml' file to use for
17: * retrieving an application context's {@link BeanFactory}. This allows
18: * the factories to be used by any component of the uPortal framework in
19: * a singleton manner.
20: *
21: * @author Eric Dalquist <a href="mailto:edalquist@unicon.net">edalquist@unicon.net</a>
22: * @version $Revision: 35134 $ $Date: 2004-12-13 20:51:40 -0700 (Mon, 13 Dec 2004) $
23: */
24: public final class PortalApplicationContextFacade {
25: /**
26: * Location this class uses to initialize the {@link SingletonBeanFactoryLocator}
27: * used to marshall application contexts from.
28: */
29: public static String BEAN_REF_FACTORY_PATH = "properties/beanRefFactory.xml";
30:
31: /**
32: * Name of the default portal application context.
33: */
34: public static String PORTAL_CONTEXT_NAME = "org.jasig.portal";
35:
36: /**
37: * Calls {@link #getApplicationContext(String)} with
38: * {@link PortalApplicationContextFacade#PORTAL_CONTEXT_NAME} as the
39: * argument.
40: *
41: * @see #getApplicationContext(String)
42: */
43: public static BeanFactory getPortalApplicationContext() {
44: return getApplicationContext(PORTAL_CONTEXT_NAME);
45: }
46:
47: /**
48: * Gets the {@link BeanFactory} for the specified application context.
49: *
50: * @param contextName The name of the application context {@link BeanFactory} to return.
51: * @return The (singleton) {@link BeanFactory} for the application context.
52: */
53: public static BeanFactory getApplicationContext(
54: final String contextName) {
55: final BeanFactoryLocator locator = SingletonBeanFactoryLocator
56: .getInstance(BEAN_REF_FACTORY_PATH);
57: final BeanFactoryReference reference = locator
58: .useBeanFactory(contextName);
59: return reference.getFactory();
60: }
61:
62: /** ensure this class can't be instantiated */
63: private PortalApplicationContextFacade() {
64: }
65: }
|