From: Juergen H. <jho...@us...> - 2007-04-30 16:08:49
|
Update of /cvsroot/springframework/spring/src/org/springframework/context/access In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv12877/src/org/springframework/context/access Modified Files: ContextSingletonBeanFactoryLocator.java Log Message: ContextLoader loads parent context based on "parentContextKey" parameter, not requiring "locatorFactorySelector" parama Index: ContextSingletonBeanFactoryLocator.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/context/access/ContextSingletonBeanFactoryLocator.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** ContextSingletonBeanFactoryLocator.java 14 Jan 2007 01:08:24 -0000 1.19 --- ContextSingletonBeanFactoryLocator.java 30 Apr 2007 16:08:45 -0000 1.20 *************** *** 30,55 **** /** ! * <p>Variant of SingletonBeanFactoryLocator which creates its internal bean ! * factory reference definition as an ApplicationContext instead of ! * SingletonBeanFactoryLocator's BeanFactory. For almost all usage scenarios, this ! * will not make a difference, since within that ApplicationContext or BeanFactory ! * you are still free to create either BeanFactories or ApplicationContexts. The ! * main reason one would need to use this class is if bean post-processing (or other ! * ApplicationContext specific features are needed in the bean reference definition ! * itself). * * <p><strong>Note:</strong> This class uses <strong>classpath*:beanRefContext.xml</strong> ! * as the default name for the bean factory reference definition. It is not possible ! * nor legal to share definitions with SingletonBeanFactoryLocator at the same time. ! * * @author Colin Sampaleanu * @author Juergen Hoeller * @see org.springframework.context.access.DefaultLocatorFactory */ public class ContextSingletonBeanFactoryLocator extends SingletonBeanFactoryLocator { ! private static final String BEANS_REFS_XML_NAME = "classpath*:beanRefContext.xml"; ! ! // the keyed singleton instances private static final Map instances = new HashMap(); --- 30,58 ---- /** ! * <p>Variant of {@link org.springframework.beans.factory.access.SingletonBeanFactoryLocator} ! * which creates its internal bean factory reference as an ! * {@link org.springframework.context.ApplicationContext} instead of ! * SingletonBeanFactoryLocator's simple BeanFactory. For almost all usage scenarios, ! * this will not make a difference, since within that ApplicationContext or BeanFactory ! * you are still free to define either BeanFactory or ApplicationContext instances. ! * The main reason one would need to use this class is if bean post-processing ! * (or other ApplicationContext specific features are needed in the bean reference ! * definition itself). * * <p><strong>Note:</strong> This class uses <strong>classpath*:beanRefContext.xml</strong> ! * as the default resource location for the bean factory reference definition files. ! * It is not possible nor legal to share definitions with SingletonBeanFactoryLocator ! * at the same time. ! * * @author Colin Sampaleanu * @author Juergen Hoeller + * @see org.springframework.beans.factory.access.SingletonBeanFactoryLocator * @see org.springframework.context.access.DefaultLocatorFactory */ public class ContextSingletonBeanFactoryLocator extends SingletonBeanFactoryLocator { ! private static final String DEFAULT_RESOURCE_LOCATION = "classpath*:beanRefContext.xml"; ! ! /** The keyed singleton instances */ private static final Map instances = new HashMap(); *************** *** 60,66 **** * thread's context class loader's <code>getResources</code> method with this * name will be combined to create a definition, which is just a BeanFactory. */ public static BeanFactoryLocator getInstance() throws BeansException { ! return getInstance(BEANS_REFS_XML_NAME); } --- 63,71 ---- * thread's context class loader's <code>getResources</code> method with this * name will be combined to create a definition, which is just a BeanFactory. + * @return the corresponding BeanFactoryLocator instance + * @throws BeansException in case of factory loading failure */ public static BeanFactoryLocator getInstance() throws BeansException { ! return getInstance(null); } *************** *** 74,87 **** * a standard URL prefix, then only one resource file will be loaded as the * definition. ! * @param selector the name of the resource(s) which will be read and combine to ! * form the definition for the SingletonBeanFactoryLocator instance. The one file ! * or multiple fragments with this name must form a valid ApplicationContext ! * definition. */ public static BeanFactoryLocator getInstance(String selector) throws BeansException { // For backwards compatibility, we prepend "classpath*:" to the selector name if there // is no other prefix (i.e. "classpath*:", "classpath:", or some URL prefix). ! if (!ResourcePatternUtils.isUrl(selector)) { ! selector = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + selector; } --- 79,98 ---- * a standard URL prefix, then only one resource file will be loaded as the * definition. ! * @param selector the location of the resource(s) which will be read and ! * combined to form the definition for the BeanFactoryLocator instance. ! * Any such files must form a valid ApplicationContext definition. ! * @return the corresponding BeanFactoryLocator instance ! * @throws BeansException in case of factory loading failure */ public static BeanFactoryLocator getInstance(String selector) throws BeansException { + String resourceLocation = selector; + if (resourceLocation == null) { + resourceLocation = DEFAULT_RESOURCE_LOCATION; + } + // For backwards compatibility, we prepend "classpath*:" to the selector name if there // is no other prefix (i.e. "classpath*:", "classpath:", or some URL prefix). ! if (!ResourcePatternUtils.isUrl(resourceLocation)) { ! resourceLocation = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resourceLocation; } *************** *** 91,98 **** instances.hashCode() + ", instances=" + instances); } ! BeanFactoryLocator bfl = (BeanFactoryLocator) instances.get(selector); if (bfl == null) { ! bfl = new ContextSingletonBeanFactoryLocator(selector); ! instances.put(selector, bfl); } return bfl; --- 102,109 ---- instances.hashCode() + ", instances=" + instances); } ! BeanFactoryLocator bfl = (BeanFactoryLocator) instances.get(resourceLocation); if (bfl == null) { ! bfl = new ContextSingletonBeanFactoryLocator(resourceLocation); ! instances.put(resourceLocation, bfl); } return bfl; *************** *** 102,137 **** /** ! * Constructor which uses the default "classpath*:beanRefContext.xml", as the name of the ! * definition file(s). All resources returned by the definition classloader's ! * getResources() method with this name will be combined to create a definition. ! */ ! protected ContextSingletonBeanFactoryLocator() { ! super(BEANS_REFS_XML_NAME); ! } ! ! /** ! * Constructor which uses the the specified name as the name of the definition file(s). ! * All resources returned by the definition ClassLoader's <code>getResources</code> ! * method with this name will be combined to create a definition. */ ! protected ContextSingletonBeanFactoryLocator(String resourceName) { ! super(resourceName); } /** ! * Overrides default method to create definition object as an ApplicationContext * instead of the default BeanFactory. This does not affect what can actually * be loaded by that definition. */ ! protected BeanFactory createDefinition(String resourceName, String factoryKey) throws BeansException { ! return new ClassPathXmlApplicationContext(new String[] {resourceName}, false); } /** ! * Overrides default method to initialize definition object, which this method ! * assumes is a ConfigurableApplicationContext. This implementation simply invokes * {@link ConfigurableApplicationContext#refresh ConfigurableApplicationContext.refresh()}. */ ! protected void initializeDefinition(BeanFactory groupDef) throws BeansException { if (groupDef instanceof ConfigurableApplicationContext) { ((ConfigurableApplicationContext) groupDef).refresh(); --- 113,141 ---- /** ! * Constructor which uses the the specified name as the resource name ! * of the definition file(s). ! * @param resourceLocation the Spring resource location to use ! * (either a URL or a "classpath:" / "classpath*:" pseudo URL) */ ! protected ContextSingletonBeanFactoryLocator(String resourceLocation) { ! super(resourceLocation); } /** ! * Overrides the default method to create definition object as an ApplicationContext * instead of the default BeanFactory. This does not affect what can actually * be loaded by that definition. + * <p>The default implementation simply builds a + * {@link org.springframework.context.support.ClassPathXmlApplicationContext}. */ ! protected BeanFactory createDefinition(String resourceLocation, String factoryKey) { ! return new ClassPathXmlApplicationContext(new String[] {resourceLocation}, false); } /** ! * Overrides the default method to refresh the ApplicationContext, invoking * {@link ConfigurableApplicationContext#refresh ConfigurableApplicationContext.refresh()}. */ ! protected void initializeDefinition(BeanFactory groupDef) { if (groupDef instanceof ConfigurableApplicationContext) { ((ConfigurableApplicationContext) groupDef).refresh(); *************** *** 140,150 **** /** ! * Overrides default method to work with an ApplicationContext. */ ! protected void destroyDefinition(BeanFactory groupDef, String resourceName) throws BeansException { if (groupDef instanceof ConfigurableApplicationContext) { if (logger.isTraceEnabled()) { ! logger.trace("ContextSingletonBeanFactoryLocator group with resourceName '" + ! resourceName + "' being released, as there are no more references"); } ((ConfigurableApplicationContext) groupDef).close(); --- 144,155 ---- /** ! * Overrides the default method to operate on an ApplicationContext, invoking ! * {@link ConfigurableApplicationContext#refresh ConfigurableApplicationContext.close()}. */ ! protected void destroyDefinition(BeanFactory groupDef, String selector) { if (groupDef instanceof ConfigurableApplicationContext) { if (logger.isTraceEnabled()) { ! logger.trace("Context group with selector '" + selector + ! "' being released, as there are no more references to it"); } ((ConfigurableApplicationContext) groupDef).close(); |