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.PropertyPlaceholderConfigurer;
23
24 import ch.elca.el4j.services.monitoring.notification.CoreNotificationHelper;
25
26 /**
27 * HACK!!!
28 *
29 * This property placeholder configurer is used to circumvent the problem with
30 * the abstract application context. The application context instantiates the
31 * ordered bean factory post processor at the same time, so further loaded
32 * property placeholder configurers don't have any influence on later loaded
33 * property placeholder configurers. See
34 * <a href="http://opensource2.atlassian.com/projects/spring/browse/SPR-1657">
35 * Spring JIRA entry
36 * </a> for more details. This bean must be used as prototype and must have
37 * attribute <code>id</code> set.
38 *
39 * @svnLink $Revision: 4010 $;$Date: 2009-12-01 10:59:54 +0100 (Di, 01. Dez 2009) $;$Author: jonasha $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/core/src/main/java/ch/elca/el4j/core/config/RefreshPropertyPlaceholderConfigurer.java $
40 *
41 * @deprecated This former hack is no longer required. It is solved in
42 * <code>ModuleApplicationContext</code> and
43 * <code>ModuleWebApplicationContext</code>.
44 *
45 * @author Alex Mathey (AMA)
46 */
47 @Deprecated
48 public class RefreshPropertyPlaceholderConfigurer extends
49 PropertyPlaceholderConfigurer {
50
51 /**
52 * Flag to mark that this instance has been created by this class or a
53 * subclass of it.
54 */
55 private boolean m_selfInstantiated = false;
56
57 /**
58 * Is the name of this bean.
59 */
60 private String m_beanName;
61
62 /**
63 * {@inheritDoc}
64 *
65 * Creates a fresh instance of this class and invokes this method of the
66 * new instance.
67 */
68 public void postProcessBeanFactory(
69 ConfigurableListableBeanFactory beanFactory) throws BeansException {
70 if (isSelfInstantiated()) {
71 super.postProcessBeanFactory(beanFactory);
72 } else {
73 String beanName = getBeanName();
74 if (!beanFactory.containsBean(beanName)) {
75 CoreNotificationHelper.notifyMisconfiguration(
76 "Refresh property placeholder configurer with name '"
77 + beanName + "' not found!");
78 }
79 if (beanFactory.isSingleton(beanName)) {
80 CoreNotificationHelper.notifyMisconfiguration(
81 "Refresh property placeholder configurer with name '"
82 + beanName + "' must be prototype!");
83 }
84 RefreshPropertyPlaceholderConfigurer configurer
85 = (RefreshPropertyPlaceholderConfigurer) beanFactory.getBean(
86 beanName);
87 configurer.setSelfInstantiated(true);
88 configurer.postProcessBeanFactory(beanFactory);
89 }
90 }
91
92 /**
93 * @return Returns the selfInstantiated.
94 */
95 protected final boolean isSelfInstantiated() {
96 return m_selfInstantiated;
97 }
98
99 /**
100 * @param selfInstantiated The selfInstantiated to set.
101 */
102 protected final void setSelfInstantiated(boolean selfInstantiated) {
103 m_selfInstantiated = selfInstantiated;
104 }
105
106 /**
107 * {@inheritDoc}
108 */
109 public final void setBeanName(String beanName) {
110 m_beanName = beanName;
111 }
112
113 /**
114 * @return Returns the beanName.
115 */
116 public final String getBeanName() {
117 return m_beanName;
118 }
119 }