View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2006 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
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 Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  package ch.elca.el4j.core.config;
18  
19  import org.springframework.beans.BeansException;
20  import org.springframework.beans.factory.BeanNameAware;
21  import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
22  import org.springframework.beans.factory.config.PropertyOverrideConfigurer;
23  
24  import ch.elca.el4j.core.context.ModuleApplicationContext;
25  import ch.elca.el4j.services.monitoring.notification.CoreNotificationHelper;
26  
27  /**
28   * HACK!!!
29   *
30   * This property override configurer is used to circumvent the problem with
31   * the abstract application context. The application context instantiates the
32   * ordered bean factory post processor at the same time, so further loaded
33   * property override configurers don't have any influence on later loaded
34   * property override configurers. See
35   * <a href="http://opensource2.atlassian.com/projects/spring/browse/SPR-1657">
36   * Spring JIRA entry
37   * </a> for more details. This bean must be used as prototype and must have
38   * attribute <code>id</code> set.
39   *
40   * @svnLink $Revision: 3883 $;$Date: 2009-08-04 15:35:01 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/core/src/main/java/ch/elca/el4j/core/config/RefreshPropertyOverrideConfigurer.java $
41   *
42   * @deprecated This former hack is no longer required. It is solved in
43   *             <code>ModuleApplicationContext</code> and
44   *             <code>ModuleWebApplicationContext</code>.
45   *
46   * @author Martin Zeltner (MZE)
47   */
48  @Deprecated
49  public class RefreshPropertyOverrideConfigurer extends
50  	PropertyOverrideConfigurer implements BeanNameAware {
51  
52  	/**
53  	 * Flag to mark that this instance has been created by this class or a
54  	 * subclass of it.
55  	 */
56  	private boolean m_selfInstantiated = false;
57  	
58  	/**
59  	 * Is the name of this bean.
60  	 */
61  	private String m_beanName;
62  	
63  	/**
64  	 * {@inheritDoc}
65  	 *
66  	 * Creates a fresh instance of this class and invokes this method of the
67  	 * new instance.
68  	 */
69  	public void postProcessBeanFactory(
70  		ConfigurableListableBeanFactory beanFactory) throws BeansException {
71  		if (isSelfInstantiated()) {
72  			super.postProcessBeanFactory(beanFactory);
73  		} else {
74  			String beanName = getBeanName();
75  			if (!beanFactory.containsBean(beanName)) {
76  				CoreNotificationHelper.notifyMisconfiguration(
77  					"Refresh property override configurer with name '"
78  						+ beanName + "' not found!");
79  			}
80  			if (beanFactory.isSingleton(beanName)) {
81  				CoreNotificationHelper.notifyMisconfiguration(
82  					"Refresh property override configurer with name '"
83  						+ beanName + "' must be prototype!");
84  			}
85  			RefreshPropertyOverrideConfigurer configurer
86  				= (RefreshPropertyOverrideConfigurer) beanFactory.getBean(
87  					beanName);
88  			configurer.setSelfInstantiated(true);
89  			configurer.postProcessBeanFactory(beanFactory);
90  		}
91  	}
92  
93  	/**
94  	 * @return Returns the selfInstantiated.
95  	 */
96  	protected final boolean isSelfInstantiated() {
97  		return m_selfInstantiated;
98  	}
99  
100 	/**
101 	 * @param selfInstantiated The selfInstantiated to set.
102 	 */
103 	protected final void setSelfInstantiated(boolean selfInstantiated) {
104 		m_selfInstantiated = selfInstantiated;
105 	}
106 
107 	/**
108 	 * {@inheritDoc}
109 	 */
110 	public final void setBeanName(String beanName) {
111 		m_beanName = beanName;
112 	}
113 
114 	/**
115 	 * @return Returns the beanName.
116 	 */
117 	public final String getBeanName() {
118 		return m_beanName;
119 	}
120 }