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) 2005 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.contextpassing;
18  
19  import org.springframework.beans.factory.BeanNameAware;
20  import org.springframework.beans.factory.InitializingBean;
21  
22  import ch.elca.el4j.services.monitoring.notification.CoreNotificationHelper;
23  import ch.elca.el4j.util.codingsupport.Reject;
24  
25  /**
26   * Every bean requiring implicit context passing needs to have a context
27   * passer bean that extends this class. The passer needs a reference to the
28   * <code>ImplicitContextPassingRegistry</code> where it is should be registered.
29   *
30   * @svnLink $Revision: 3873 $;$Date: 2009-08-04 13:59:45 +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/contextpassing/AbstractImplicitContextPasser.java $
31   *
32   * @author Andreas Pfenninger (APR)
33   */
34  public abstract class AbstractImplicitContextPasser implements
35  		InitializingBean, BeanNameAware, ImplicitContextPasser {
36  	/**
37  	 * Indicates if this class is initalized.
38  	 */
39  	private boolean m_beanIsInitialized = false;
40  
41  	/**
42  	 * Name of bean.
43  	 */
44  	private String m_beanName = null;
45  
46  	/**
47  	 * {@inheritDoc}
48  	 */
49  	public void afterPropertiesSet() throws Exception {
50  		if (!m_beanIsInitialized) {
51  			CoreNotificationHelper.notifyLackingEssentialProperty(
52  					"implicitContextPassingRegistry", this);
53  		}
54  	}
55  
56  	/**
57  	 * Sets the implicit context passing registry and registers this context
58  	 * passer.
59  	 *
60  	 * @param registry
61  	 *            The implicit context passing registry.
62  	 */
63  	public void setImplicitContextPassingRegistry(
64  			ImplicitContextPassingRegistry registry) {
65  		Reject.ifNull(registry,
66  				"Implicit context passing registry must not be null.");
67  		registry.registerImplicitContextPasser(this);
68  		m_beanIsInitialized = true;
69  	}
70  
71  	/**
72  	 * {@inheritDoc}
73  	 */
74  	public void setBeanName(String beanName) {
75  		m_beanName = beanName;
76  	}
77  
78  	/**
79  	 * @return Returns the beanName.
80  	 */
81  	public String getBeanName() {
82  		return m_beanName;
83  	}
84  }