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.aop;
18  
19  import org.springframework.aop.TargetSource;
20  import org.springframework.aop.framework.adapter.AdvisorAdapterRegistry;
21  import org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry;
22  import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
23  
24  /**
25   * Intelligent exclusive bean name autoproxy creator. Will not create a new
26   * proxy for a given bean if this bean is already a proxy bean. All class
27   * members (plus getter and setter for them) do just take place in this class,
28   * because class {@link AbstractAutoProxyCreator} hides them.
29   *
30   * @svnLink $Revision: 4204 $;$Date: 2010-11-02 11:44:37 +0100 (Di, 02. Nov 2010) $;$Author: swisswheel $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/core/src/main/java/ch/elca/el4j/core/aop/IntelligentExclusiveBeanNameAutoProxyCreator.java $
31   *
32   * @deprecated The term "intelligent" is misleading, because proxying errors
33   * can be produced. Use the parent class
34   * <code>ExclusiveBeanNameAutoProxyCreator</code> instead.
35   *
36   * @author Martin Zeltner (MZE)
37   */
38  @Deprecated
39  public class IntelligentExclusiveBeanNameAutoProxyCreator
40  	extends ExclusiveBeanNameAutoProxyCreator {
41  	/**
42  	 * COPYIED FROM SUPERCLASS!
43  	 *
44  	 * Names of common interceptors. We must use bean name rather than object
45  	 * references to handle prototype advisors/interceptors.
46  	 * Default is the empty array: no common interceptors.
47  	 */
48  	private String[] m_interceptorNames = new String[0];
49  	
50  	/**
51  	 * COPYIED FROM SUPERCLASS!
52  	 *
53  	 * Default is global AdvisorAdapterRegistry.
54  	 * */
55  	private AdvisorAdapterRegistry m_advisorAdapterRegistry
56  		= GlobalAdvisorAdapterRegistry.getInstance();
57  
58  	/**
59  	 * @see #setApplyCommonInterceptorsFirst(boolean)
60  	 */
61  	private boolean m_applyCommonInterceptorsFirst = true;
62  
63  	/**
64  	 * Will not create a new proxy for a given bean if this bean is already
65  	 * a proxy bean.
66  	 *
67  	 * {@inheritDoc}
68  	 */
69  	@Override
70  	protected Object createProxy(Class beanClass, String beanName,
71  		Object[] specificInterceptors, TargetSource targetSource) {
72  		
73  		Object proxy = ProxyEnricher.enrichProxy(beanClass, beanName,
74  			specificInterceptors, targetSource, getInterceptorNames(),
75  			getBeanFactory(), getAdvisorAdapterRegistry(),
76  			isApplyCommonInterceptorsFirst());
77  		
78  		// If no proxy could be enriched create a new one.
79  		if (proxy == null) {
80  			proxy = super.createProxy(beanClass, beanName,
81  				specificInterceptors, targetSource);
82  		}
83  		return proxy;
84  	}
85  
86  	/**
87  	 * @return Returns the interceptorNames.
88  	 */
89  	protected String[] getInterceptorNames() {
90  		return m_interceptorNames;
91  	}
92  
93  	/**
94  	 * Added to have access to the interceptor names.
95  	 *
96  	 * {@inheritDoc}
97  	 */
98  	@Override
99  	public void setInterceptorNames(String[] interceptorNames) {
100 		m_interceptorNames = interceptorNames;
101 		super.setInterceptorNames(interceptorNames);
102 	}
103 
104 	/**
105 	 * @return Returns the advisorAdapterRegistry.
106 	 */
107 	protected AdvisorAdapterRegistry getAdvisorAdapterRegistry() {
108 		return m_advisorAdapterRegistry;
109 	}
110 
111 	/**
112 	 * Added to have access to the interceptor names.
113 	 *
114 	 * {@inheritDoc}
115 	 */
116 	@Override
117 	public void setAdvisorAdapterRegistry(
118 		AdvisorAdapterRegistry advisorAdapterRegistry) {
119 		m_advisorAdapterRegistry = advisorAdapterRegistry;
120 		super.setAdvisorAdapterRegistry(advisorAdapterRegistry);
121 	}
122 	
123 	/**
124 	 * @return Returns the applyCommonInterceptorsFirst.
125 	 */
126 	protected boolean isApplyCommonInterceptorsFirst() {
127 		return m_applyCommonInterceptorsFirst;
128 	}
129 
130 	/**
131 	 * COPYIED FROM SUPERCLASS!
132 	 *
133 	 * Set whether the common interceptors should be applied before
134 	 * bean-specific ones. Default is "true"; else, bean-specific interceptors
135 	 * will get applied first.
136 	 *
137 	 * @param applyCommonInterceptorsFirst See method description.
138 	 */
139 	public void setApplyCommonInterceptorsFirst(
140 		boolean applyCommonInterceptorsFirst) {
141 		m_applyCommonInterceptorsFirst = applyCommonInterceptorsFirst;
142 	}
143 }