1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package net.sf.sail.common.beansupport;
27
28 import java.beans.DesignMode;
29 import java.beans.beancontext.BeanContext;
30 import java.beans.beancontext.BeanContextChildSupport;
31 import java.beans.beancontext.BeanContextServiceAvailableEvent;
32 import java.beans.beancontext.BeanContextServiceRevokedEvent;
33 import java.beans.beancontext.BeanContextServices;
34 import java.beans.beancontext.BeanContextServicesListener;
35
36 import net.sf.sail.core.beans.Pod;
37 import net.sf.sail.core.util.SailBeanUtils;
38
39
40
41
42 abstract public class SailBeanContextChildSupport extends
43 BeanContextChildSupport implements DesignMode {
44
45
46
47
48
49
50
51 class SailBeanContextServicesListener implements
52 BeanContextServicesListener {
53 public void serviceAvailable(BeanContextServiceAvailableEvent bcsae) {
54
55
56
57
58
59
60 BeanContextServices bcs = SailBeanUtils
61 .findServicesContextOf(SailBeanContextChildSupport.this);
62 consumeService(bcs, bcsae.getServiceClass());
63 }
64
65 public void serviceRevoked(BeanContextServiceRevokedEvent bcsre) {
66
67 }
68
69 }
70
71 SailBeanContextServicesListener sbcsl = new SailBeanContextServicesListener();
72 private boolean designTime;
73
74 @Override
75 protected void initializeBeanContextResources() {
76 BeanContext bc = getBeanContext();
77
78 if (bc instanceof BeanContextServices) {
79 BeanContextServices bcs = (BeanContextServices) bc;
80 registerDesiredServices(bcs);
81 bcs.addBeanContextServicesListener(sbcsl);
82 } else
83 throw new RuntimeException(
84 this
85 + " initialized inside BeanContext not implementing BeanContextServices");
86 }
87
88
89
90
91
92
93
94
95 abstract protected void consumeService(BeanContextServices bcs,
96 Class<Object> serviceClass);
97
98
99
100
101
102
103
104 abstract protected void registerDesiredServices(BeanContextServices bcs);
105
106 public void setDesignTime(boolean designTime) {
107 firePropertyChange(DesignMode.PROPERTYNAME, Boolean.valueOf(this.designTime), Boolean.valueOf(designTime));
108 this.designTime = designTime;
109 }
110
111 public boolean isDesignTime() {
112 return designTime;
113 }
114
115 protected boolean isInPod()
116 {
117 Object beanContext = getBeanContext();
118 return beanContext instanceof Pod;
119 }
120
121 }