KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > factory > config > InstantiationAwareBeanPostProcessor


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.beans.factory.config;
18
19 import java.beans.PropertyDescriptor JavaDoc;
20
21 import org.springframework.beans.BeansException;
22 import org.springframework.beans.PropertyValues;
23
24 /**
25  * Subinterface of {@link BeanPostProcessor} that adds a before-instantiation callback,
26  * and a callback after instantiation but before explicit properties are set or
27  * autowiring occurs.
28  *
29  * <p>Typically used to suppress default instantiation for specific target beans,
30  * for example to create proxies with special TargetSources (pooling targets,
31  * lazily initializing targets, etc), or to implement additional injection strategies
32  * such as field injection.
33  *
34  * <p><b>NOTE:</b> This interface is a special purpose interface, mainly for
35  * internal use within the framework. It is recommended to implement the plain
36  * {@link BeanPostProcessor} interface as far as possible, or to derive from
37  * {@link InstantiationAwareBeanPostProcessorAdapter} in order to be shielded
38  * from extensions to this interface.
39  *
40  * @author Juergen Hoeller
41  * @author Rod Johnson
42  * @since 1.2
43  * @see org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator#setCustomTargetSourceCreators
44  * @see org.springframework.aop.framework.autoproxy.target.LazyInitTargetSourceCreator
45  */

46 public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
47
48     /**
49      * Apply this BeanPostProcessor <i>before the target bean gets instantiated</i>.
50      * The returned bean object may be a proxy to use instead of the target bean,
51      * effectively suppressing default instantiation of the target bean.
52      * <p>If a non-null object is returned by this method, the bean creation process
53      * will be short-circuited. The only further processing applied is the
54      * {@link #postProcessAfterInitialization} callback from the configured
55      * {@link BeanPostProcessor BeanPostProcessors}.
56      * <p>This callback will only be applied to bean definitions with a bean class.
57      * In particular, it will not be applied to beans with a "factory-method".
58      * <p>Post-processors may implement the extended
59      * {@link SmartInstantiationAwareBeanPostProcessor} interface in order
60      * to predict the type of the bean object that they are going to return here.
61      * @param beanClass the class of the bean to be instantiated
62      * @param beanName the name of the bean
63      * @return the bean object to expose instead of a default instance of the target bean,
64      * or <code>null</code> to proceed with default instantiation
65      * @throws org.springframework.beans.BeansException in case of errors
66      * @see org.springframework.beans.factory.support.AbstractBeanDefinition#hasBeanClass
67      * @see org.springframework.beans.factory.support.AbstractBeanDefinition#getFactoryMethodName
68      */

69     Object JavaDoc postProcessBeforeInstantiation(Class JavaDoc beanClass, String JavaDoc beanName) throws BeansException;
70
71     /**
72      * Perform operations after the bean has been instantiated, via a constructor or factory method,
73      * but before Spring property population (from explicit properties or autowiring) occurs.
74      * @param bean the bean instance created, but whose properties have not yet been set
75      * @param beanName the name of the bean
76      * @return <code>true</code> if properties should be set on the bean; <code>false</code>
77      * if property population should be skipped. Normal implementations should return <code>true</code>.
78      * Returning <code>false</code> will also prevent any subsequent InstantiationAwareBeanPostProcessor
79      * instances being invoked on this bean instance.
80      * @throws org.springframework.beans.BeansException in case of errors
81      */

82     boolean postProcessAfterInstantiation(Object JavaDoc bean, String JavaDoc beanName) throws BeansException;
83
84     /**
85      * Post-process the given property values before the factory applies them
86      * to the given bean. Allows for checking whether all dependencies have been
87      * satisfied, for example based on a "Required" annotation on bean property setters.
88      * <p>Also allows for replacing the property values to apply, typically through
89      * creating a new MutablePropertyValues instance based on the original PropertyValues,
90      * adding or removing specific values.
91      * @param pvs the property values that the factory is about to apply (never <code>null</code>)
92      * @param pds the relevant property descriptors for the target bean (with ignored
93      * dependency types - which the factory handles specifically - already filtered out)
94      * @param bean the bean instance created, but whose properties have not yet been set
95      * @param beanName the name of the bean
96      * @return the actual property values to apply to to the given bean
97      * (can be the passed-in PropertyValues instance), or <code>null</code>
98      * to skip property population
99      * @throws org.springframework.beans.BeansException in case of errors
100      * @see org.springframework.beans.MutablePropertyValues
101      */

102     PropertyValues postProcessPropertyValues(
103             PropertyValues pvs, PropertyDescriptor JavaDoc[] pds, Object JavaDoc bean, String JavaDoc beanName)
104             throws BeansException;
105
106 }
107
Popular Tags