org.springframework.beans.factory.support
Class DisposableBeanAdapter

java.lang.Object
  extended by org.springframework.beans.factory.support.DisposableBeanAdapter
All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable, DisposableBean

 class DisposableBeanAdapter
extends java.lang.Object
implements DisposableBean, java.lang.Runnable, java.io.Serializable

Adapter that implements the DisposableBean and Runnable interfaces performing various destruction steps on a given bean instance:

Since:
2.0
Author:
Juergen Hoeller, Costin Leau
See Also:
AbstractBeanFactory, DisposableBean, DestructionAwareBeanPostProcessor, AbstractBeanDefinition.getDestroyMethodName()

Field Summary
private  java.security.AccessControlContext acc
           
private  java.lang.Object bean
           
private  java.lang.String beanName
           
private  java.util.List<DestructionAwareBeanPostProcessor> beanPostProcessors
           
private  java.lang.reflect.Method destroyMethod
           
private  java.lang.String destroyMethodName
           
private  boolean invokeDisposableBean
           
private static Log logger
           
private  boolean nonPublicAccessAllowed
           
 
Constructor Summary
private DisposableBeanAdapter(java.lang.Object bean, java.lang.String beanName, boolean invokeDisposableBean, boolean nonPublicAccessAllowed, java.lang.String destroyMethodName, java.util.List<DestructionAwareBeanPostProcessor> postProcessors)
          Create a new DisposableBeanAdapter for the given bean.
  DisposableBeanAdapter(java.lang.Object bean, java.lang.String beanName, RootBeanDefinition beanDefinition, java.util.List<BeanPostProcessor> postProcessors, java.security.AccessControlContext acc)
          Create a new DisposableBeanAdapter for the given bean.
 
Method Summary
 void destroy()
          Invoked by a BeanFactory on destruction of a singleton.
private  java.lang.reflect.Method determineDestroyMethod()
           
private  java.util.List<DestructionAwareBeanPostProcessor> filterPostProcessors(java.util.List<BeanPostProcessor> postProcessors)
          Search for all DestructionAwareBeanPostProcessors in the List.
private  java.lang.reflect.Method findDestroyMethod()
           
private  void invokeCustomDestroyMethod(java.lang.reflect.Method destroyMethod)
          Invoke the specified custom destroy method on the given bean.
 void run()
           
protected  java.lang.Object writeReplace()
          Serializes a copy of the state of this class, filtering out non-serializable BeanPostProcessors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final Log logger

bean

private final java.lang.Object bean

beanName

private final java.lang.String beanName

invokeDisposableBean

private final boolean invokeDisposableBean

nonPublicAccessAllowed

private final boolean nonPublicAccessAllowed

destroyMethodName

private java.lang.String destroyMethodName

destroyMethod

private transient java.lang.reflect.Method destroyMethod

beanPostProcessors

private java.util.List<DestructionAwareBeanPostProcessor> beanPostProcessors

acc

private final java.security.AccessControlContext acc
Constructor Detail

DisposableBeanAdapter

public DisposableBeanAdapter(java.lang.Object bean,
                             java.lang.String beanName,
                             RootBeanDefinition beanDefinition,
                             java.util.List<BeanPostProcessor> postProcessors,
                             java.security.AccessControlContext acc)
Create a new DisposableBeanAdapter for the given bean.

Parameters:
bean - the bean instance (never null)
beanName - the name of the bean
beanDefinition - the merged bean definition
postProcessors - the List of BeanPostProcessors (potentially DestructionAwareBeanPostProcessor), if any

DisposableBeanAdapter

private DisposableBeanAdapter(java.lang.Object bean,
                              java.lang.String beanName,
                              boolean invokeDisposableBean,
                              boolean nonPublicAccessAllowed,
                              java.lang.String destroyMethodName,
                              java.util.List<DestructionAwareBeanPostProcessor> postProcessors)
Create a new DisposableBeanAdapter for the given bean.

Method Detail

filterPostProcessors

private java.util.List<DestructionAwareBeanPostProcessor> filterPostProcessors(java.util.List<BeanPostProcessor> postProcessors)
Search for all DestructionAwareBeanPostProcessors in the List.

Parameters:
postProcessors - the List to search
Returns:
the filtered List of DestructionAwareBeanPostProcessors

run

public void run()
Specified by:
run in interface java.lang.Runnable

destroy

public void destroy()
Description copied from interface: DisposableBean
Invoked by a BeanFactory on destruction of a singleton.

Specified by:
destroy in interface DisposableBean

determineDestroyMethod

private java.lang.reflect.Method determineDestroyMethod()

findDestroyMethod

private java.lang.reflect.Method findDestroyMethod()

invokeCustomDestroyMethod

private void invokeCustomDestroyMethod(java.lang.reflect.Method destroyMethod)
Invoke the specified custom destroy method on the given bean.

This implementation invokes a no-arg method if found, else checking for a method with a single boolean argument (passing in "true", assuming a "force" parameter), else logging an error.


writeReplace

protected java.lang.Object writeReplace()
Serializes a copy of the state of this class, filtering out non-serializable BeanPostProcessors.