1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.osgi.context.support;
20
21 import org.osgi.framework.BundleContext;
22 import org.springframework.beans.BeansException;
23 import org.springframework.beans.factory.config.BeanPostProcessor;
24 import org.springframework.osgi.context.BundleContextAware;
25
26
27
28
29
30
31
32
33 public class BundleContextAwareProcessor implements BeanPostProcessor {
34
35 private final BundleContext bundleContext;
36
37
38 public BundleContextAwareProcessor(BundleContext aContext) {
39 this.bundleContext = aContext;
40 }
41
42 public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
43 return bean;
44 }
45
46 public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
47 if (bean instanceof BundleContextAware) {
48 ((BundleContextAware) bean).setBundleContext(this.bundleContext);
49 }
50 return bean;
51 }
52 }