1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.james.container.spring.lifecycle;
20
21 import org.springframework.beans.BeansException;
22 import org.springframework.beans.factory.BeanFactory;
23 import org.springframework.beans.factory.BeanFactoryAware;
24 import org.springframework.beans.factory.config.BeanDefinition;
25 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
26
27 import java.util.Collection;
28
29
30
31
32 public abstract class AbstractPropagator implements BeanFactoryAware {
33
34 private Collection excludeBeans;
35 private BeanFactory beanFactory;
36
37
38
39
40
41
42 public final BeanFactory getBeanFactory() {
43 return beanFactory;
44 }
45
46 public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
47 this.beanFactory = beanFactory;
48 }
49
50 public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
51 return bean;
52 }
53
54 protected BeanDefinition getBeanDefinition(String beanName) {
55 if (beanFactory instanceof ConfigurableListableBeanFactory) {
56 ConfigurableListableBeanFactory configurableListableBeanFactory = (ConfigurableListableBeanFactory) beanFactory;
57 return configurableListableBeanFactory.getBeanDefinition(beanName);
58 }
59 return null;
60 }
61
62 public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
63 if (excludeBeans == null || !excludeBeans.contains(beanName)) {
64 BeanDefinition beanDefinition = getBeanDefinition(beanName);
65 invokeLifecycleWorker(beanName, bean, beanDefinition);
66 }
67 return bean;
68 }
69
70 public void setExcludeBeans(Collection excludeBeans) {
71 this.excludeBeans=excludeBeans;
72 }
73
74 protected abstract Class getLifecycleInterface();
75
76 protected abstract void invokeLifecycleWorker(String beanName, Object bean, BeanDefinition beanDefinition);
77
78 }