001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.beans.factory.config; 018 019import java.lang.reflect.Constructor; 020 021import org.springframework.beans.BeansException; 022 023/** 024 * Extension of the {@link InstantiationAwareBeanPostProcessor} interface, 025 * adding a callback for predicting the eventual type of a processed bean. 026 * 027 * <p><b>NOTE:</b> This interface is a special purpose interface, mainly for 028 * internal use within the framework. In general, application-provided 029 * post-processors should simply implement the plain {@link BeanPostProcessor} 030 * interface or derive from the {@link InstantiationAwareBeanPostProcessorAdapter} 031 * class. New methods might be added to this interface even in point releases. 032 * 033 * @author Juergen Hoeller 034 * @since 2.0.3 035 * @see InstantiationAwareBeanPostProcessorAdapter 036 */ 037public interface SmartInstantiationAwareBeanPostProcessor extends InstantiationAwareBeanPostProcessor { 038 039 /** 040 * Predict the type of the bean to be eventually returned from this 041 * processor's {@link #postProcessBeforeInstantiation} callback. 042 * @param beanClass the raw class of the bean 043 * @param beanName the name of the bean 044 * @return the type of the bean, or {@code null} if not predictable 045 * @throws org.springframework.beans.BeansException in case of errors 046 */ 047 Class<?> predictBeanType(Class<?> beanClass, String beanName) throws BeansException; 048 049 /** 050 * Determine the candidate constructors to use for the given bean. 051 * @param beanClass the raw class of the bean (never {@code null}) 052 * @param beanName the name of the bean 053 * @return the candidate constructors, or {@code null} if none specified 054 * @throws org.springframework.beans.BeansException in case of errors 055 */ 056 Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName) throws BeansException; 057 058 /** 059 * Obtain a reference for early access to the specified bean, 060 * typically for the purpose of resolving a circular reference. 061 * <p>This callback gives post-processors a chance to expose a wrapper 062 * early - that is, before the target bean instance is fully initialized. 063 * The exposed object should be equivalent to the what 064 * {@link #postProcessBeforeInitialization} / {@link #postProcessAfterInitialization} 065 * would expose otherwise. Note that the object returned by this method will 066 * be used as bean reference unless the post-processor returns a different 067 * wrapper from said post-process callbacks. In other words: Those post-process 068 * callbacks may either eventually expose the same reference or alternatively 069 * return the raw bean instance from those subsequent callbacks (if the wrapper 070 * for the affected bean has been built for a call to this method already, 071 * it will be exposes as final bean reference by default). 072 * @param bean the raw bean instance 073 * @param beanName the name of the bean 074 * @return the object to expose as bean reference 075 * (typically with the passed-in bean instance as default) 076 * @throws org.springframework.beans.BeansException in case of errors 077 */ 078 Object getEarlyBeanReference(Object bean, String beanName) throws BeansException; 079 080}