1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52:
53:
57: public class BeanContextServicesSupport
58: extends BeanContextSupport
59: implements BeanContextServices
60: {
61: private static final long serialVersionUID = -8494482757288719206L;
62:
63: protected class BCSSChild
64: extends BeanContextSupport.BCSChild
65: {
66: private static final long serialVersionUID = -3263851306889194873L;
67:
68: BCSSChild(Object targetChild, Object peer)
69: {
70: super(targetChild, peer);
71: }
72: }
73:
74: protected class BCSSProxyServiceProvider
75: implements BeanContextServiceProvider,
76: BeanContextServiceRevokedListener
77: {
78: private static final long serialVersionUID = 7078212910685744490L;
79:
80: private BCSSProxyServiceProvider()
81: {
82: }
83:
84: public Iterator getCurrentServiceSelectors (BeanContextServices bcs,
85: Class serviceClass)
86: throws NotImplementedException
87: {
88: throw new Error ("Not implemented");
89: }
90:
91: public Object getService (BeanContextServices bcs,
92: Object requestor,
93: Class serviceClass,
94: Object serviceSelector)
95: throws NotImplementedException
96: {
97: throw new Error ("Not implemented");
98: }
99:
100: public void releaseService (BeanContextServices bcs,
101: Object requestor,
102: Object service)
103: throws NotImplementedException
104: {
105: throw new Error ("Not implemented");
106: }
107:
108: public void serviceRevoked (BeanContextServiceRevokedEvent bcsre)
109: throws NotImplementedException
110: {
111: throw new Error ("Not implemented");
112: }
113: }
114:
115: protected static class BCSSServiceProvider
116: implements Serializable
117: {
118: private static final long serialVersionUID = 861278251667444782L;
119:
120: protected BeanContextServiceProvider serviceProvider;
121:
122: private BCSSServiceProvider()
123: {
124: }
125:
126: protected BeanContextServiceProvider getServiceProvider()
127: {
128: return serviceProvider;
129: }
130: }
131:
132: protected transient ArrayList bcsListeners;
133:
134: protected transient BCSSProxyServiceProvider proxy;
135:
136: protected transient int serializable;
137:
138: protected transient HashMap services;
139:
140: public BeanContextServicesSupport ()
141: {
142: super();
143: }
144:
145: public BeanContextServicesSupport (BeanContextServices peer)
146: {
147: super(peer);
148: }
149:
150: public BeanContextServicesSupport(BeanContextServices peer, Locale locale)
151: {
152: super(peer, locale);
153: }
154:
155: public BeanContextServicesSupport(BeanContextServices peer, Locale locale,
156: boolean dtime)
157: {
158: super(peer, locale, dtime);
159: }
160:
161: public BeanContextServicesSupport(BeanContextServices peer, Locale locale,
162: boolean dtime, boolean visible)
163: {
164: super(peer, locale, dtime, visible);
165: }
166:
167: public void addBeanContextServicesListener
168: (BeanContextServicesListener listener)
169: {
170: synchronized (bcsListeners)
171: {
172: if (! bcsListeners.contains(listener))
173: bcsListeners.add(listener);
174: }
175: }
176:
177: public boolean addService (Class serviceClass,
178: BeanContextServiceProvider bcsp)
179: {
180: return addService(serviceClass, bcsp, true);
181: }
182:
183: protected boolean addService (Class serviceClass,
184: BeanContextServiceProvider bcsp,
185: boolean fireEvent)
186: {
187: synchronized (services)
188: {
189: if (services.containsKey(serviceClass))
190: return false;
191: services.put(serviceClass, bcsp);
192: if (bcsp instanceof Serializable)
193: ++serializable;
194: fireServiceAdded(serviceClass);
195: return true;
196: }
197: }
198:
199: protected void bcsPreDeserializationHook (ObjectInputStream ois)
200: throws ClassNotFoundException, IOException, NotImplementedException
201: {
202: throw new Error ("Not implemented");
203: }
204:
205: protected void bcsPreSerializationHook (ObjectOutputStream oos)
206: throws IOException, NotImplementedException
207: {
208: throw new Error ("Not implemented");
209: }
210:
211: protected void childJustRemovedHook (Object child,
212: BeanContextSupport.BCSChild bcsc)
213: throws NotImplementedException
214: {
215: throw new Error ("Not implemented");
216: }
217:
218: protected BeanContextSupport.BCSChild createBCSChild (Object targetChild,
219: Object peer)
220: {
221: return new BCSSChild(targetChild, peer);
222: }
223:
224: protected BeanContextServicesSupport.BCSSServiceProvider
225: createBCSSServiceProvider (Class sc, BeanContextServiceProvider bcsp)
226: throws NotImplementedException
227: {
228: throw new Error ("Not implemented");
229: }
230:
231: protected final void fireServiceAdded (BeanContextServiceAvailableEvent bcssae)
232: {
233: synchronized (bcsListeners)
234: {
235: int size = bcsListeners.size();
236: for (int i = 0; i < size; ++i)
237: {
238: BeanContextServicesListener bcsl
239: = (BeanContextServicesListener) bcsListeners.get(i);
240: bcsl.serviceAvailable(bcssae);
241: }
242: }
243: }
244:
245: protected final void fireServiceAdded (Class serviceClass)
246: {
247: fireServiceAdded(new BeanContextServiceAvailableEvent(this,
248: serviceClass));
249: }
250:
251: protected final void fireServiceRevoked(BeanContextServiceRevokedEvent event)
252: {
253: synchronized (bcsListeners)
254: {
255: int size = bcsListeners.size();
256: for (int i = 0; i < size; ++i)
257: {
258: BeanContextServicesListener bcsl
259: = (BeanContextServicesListener) bcsListeners.get(i);
260: bcsl.serviceRevoked(event);
261: }
262: }
263: }
264:
265: protected final void fireServiceRevoked (Class serviceClass,
266: boolean revokeNow)
267: {
268: fireServiceRevoked(new BeanContextServiceRevokedEvent(this, serviceClass,
269: revokeNow));
270: }
271:
272: public BeanContextServices getBeanContextServicesPeer ()
273: throws NotImplementedException
274: {
275: throw new Error ("Not implemented");
276: }
277:
278: protected static final BeanContextServicesListener
279: getChildBeanContextServicesListener (Object child)
280: throws NotImplementedException
281: {
282: throw new Error ("Not implemented");
283: }
284:
285: public Iterator getCurrentServiceClasses ()
286: {
287: synchronized (services)
288: {
289: return services.keySet().iterator();
290: }
291: }
292:
293: public Iterator getCurrentServiceSelectors (Class serviceClass)
294: {
295: synchronized (services)
296: {
297:
298: BeanContextServiceProvider bcsp
299: = (BeanContextServiceProvider) services.get(serviceClass);
300: return bcsp.getCurrentServiceSelectors(this, serviceClass);
301: }
302: }
303:
304: public Object getService (BeanContextChild child, Object requestor,
305: Class serviceClass, Object serviceSelector,
306: BeanContextServiceRevokedListener bcsrl)
307: throws TooManyListenersException, NotImplementedException
308: {
309: throw new Error ("Not implemented");
310: }
311:
312: public boolean hasService (Class serviceClass)
313: {
314: synchronized (services)
315: {
316: return services.containsKey(serviceClass);
317: }
318: }
319:
320: public void initialize ()
321: {
322: super.initialize();
323:
324: bcsListeners = new ArrayList();
325: services = new HashMap();
326: }
327:
328: protected void initializeBeanContextResources ()
329: throws NotImplementedException
330: {
331: throw new Error ("Not implemented");
332: }
333:
334: protected void releaseBeanContextResources ()
335: throws NotImplementedException
336: {
337: throw new Error ("Not implemented");
338: }
339:
340: public void releaseService (BeanContextChild child, Object requestor,
341: Object service)
342: throws NotImplementedException
343: {
344: throw new Error ("Not implemented");
345: }
346:
347: public void removeBeanContextServicesListener
348: (BeanContextServicesListener listener)
349: {
350: synchronized (bcsListeners)
351: {
352: int index = bcsListeners.indexOf(listener);
353: if (index > -1)
354: bcsListeners.remove(index);
355: }
356: }
357:
358: public void revokeService (Class serviceClass, BeanContextServiceProvider bcsp,
359: boolean revokeCurrentServicesNow)
360: throws NotImplementedException
361: {
362: throw new Error ("Not implemented");
363: }
364:
365: public void serviceAvailable (BeanContextServiceAvailableEvent bcssae)
366: {
367: synchronized (services)
368: {
369: Class klass = bcssae.getServiceClass();
370: if (services.containsKey(klass))
371: return;
372: Iterator it = bcsChildren();
373: while (it.hasNext())
374: {
375: Object obj = it.next();
376: if (obj instanceof BeanContextServices)
377: ((BeanContextServices) obj).serviceAvailable(bcssae);
378: }
379: }
380: }
381:
382: public void serviceRevoked (BeanContextServiceRevokedEvent bcssre)
383: {
384: synchronized (services)
385: {
386: Class klass = bcssre.getServiceClass();
387: if (services.containsKey(klass))
388: return;
389: Iterator it = bcsChildren();
390: while (it.hasNext())
391: {
392: Object obj = it.next();
393: if (obj instanceof BeanContextServices)
394: ((BeanContextServices) obj).serviceRevoked(bcssre);
395: }
396: }
397: }
398: }