1 /*
2 * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3 * the spring framework, http://el4j.sf.net
4 * Copyright (C) 2008 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.context.annotations;
18
19 import org.springframework.beans.factory.config.BeanDefinition;
20 import org.springframework.beans.factory.support.AbstractBeanDefinition;
21 import org.springframework.context.annotation.AnnotationScopeMetadataResolver;
22 import org.springframework.context.annotation.Lazy;
23 import org.springframework.context.annotation.ScopeMetadata;
24
25
26 /**
27 * This {@link AnnotationScopeMetadataResolver} searches for {@link LazyInit} annotations on the class and modifies
28 * the bean definition according to that. This is a bit hacky because lazy initialization actually has nothing to do
29 * with the scope, but no better extension point could be found in Spring 2.5.5.
30 *
31 * @deprecated As of EL4J version 2.0 (and the update to Spring 3) this AnnitationScopeMetadataResolver should
32 * be no longer used because the corresponding annotation {@link LazyInit} has deprecated.
33 * Use the newly added annotation {@link Lazy} of Spring 3 instead of the deprecated LazyInit annotation.
34 *
35 * @svnLink $Revision: 4100 $;$Date: 2010-01-20 13:11:23 +0100 (Mi, 20. Jan 2010) $;$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/context/annotations/LazyInitAwareScopeMetadataResolver.java $
36 *
37 * @author Stefan Wismer (SWI)
38 * @author Jonas Hauenstein (JHN)
39 *
40 */
41 @Deprecated public class LazyInitAwareScopeMetadataResolver extends AnnotationScopeMetadataResolver {
42
43 /** {@inheritDoc} */
44 public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
45 ScopeMetadata result = super.resolveScopeMetadata(definition);
46 if (definition instanceof AbstractBeanDefinition) {
47 AbstractBeanDefinition beanDef = (AbstractBeanDefinition) definition;
48
49 try {
50 beanDef.setLazyInit(Class.forName(beanDef.getBeanClassName()).getAnnotation(LazyInit.class) != null);
51 } catch (ClassNotFoundException e) {
52 // ignore class
53 }
54 }
55 return result;
56 }
57
58 }