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: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60:
61:
65: public class BeanContextSupport extends BeanContextChildSupport
66: implements BeanContext, Serializable, PropertyChangeListener,
67: VetoableChangeListener
68: {
69: private static final long serialVersionUID = -4879613978649577204L;
70:
71:
72:
73: private void readObject (ObjectInputStream s)
74: throws ClassNotFoundException, IOException, NotImplementedException
75: {
76: throw new Error ("Not implemented");
77: }
78:
79:
80:
81: private void writeObject (ObjectOutputStream s)
82: throws ClassNotFoundException, IOException, NotImplementedException
83: {
84: throw new Error ("Not implemented");
85: }
86:
87: protected class BCSChild implements Serializable
88: {
89: private static final long serialVersionUID = -5815286101609939109L;
90:
91: private Object targetChild;
92: private Object peer;
93:
94: BCSChild(Object targetChild, Object peer)
95: {
96: this.targetChild = targetChild;
97: this.peer = peer;
98: }
99: }
100:
101: protected static final class BCSIterator implements Iterator
102: {
103: private Iterator child;
104:
105: BCSIterator(Iterator child)
106: {
107: this.child = child;
108: }
109:
110: public boolean hasNext ()
111: {
112: return child.hasNext();
113: }
114:
115: public Object next ()
116: {
117: return child.next();
118: }
119:
120: public void remove ()
121: {
122:
123: }
124: }
125:
126: protected transient ArrayList bcmListeners;
127:
128: protected transient HashMap children;
129:
130: protected transient boolean designTime;
131:
132: protected transient Locale locale;
133:
134: protected transient boolean okToUseGui;
135:
136:
139: public BeanContextSupport ()
140: {
141: this (null, null, true, true);
142: }
143:
144:
147: public BeanContextSupport (BeanContext peer)
148: {
149: this (peer, null, true, true);
150: }
151:
152:
155: public BeanContextSupport (BeanContext peer, Locale lcle)
156: {
157: this (peer, lcle, true, true);
158: }
159:
160:
163: public BeanContextSupport (BeanContext peer, Locale lcle, boolean dtime)
164: {
165: this (peer, lcle, dtime, true);
166: }
167:
168:
171: public BeanContextSupport (BeanContext peer, Locale lcle, boolean dtime,
172: boolean visible)
173: {
174: super(peer);
175:
176: locale = lcle == null ? Locale.getDefault() : lcle;
177: designTime = dtime;
178: okToUseGui = visible;
179:
180: initialize ();
181: }
182:
183: public boolean add (Object targetChild)
184: {
185: if (targetChild == null)
186: throw new IllegalArgumentException();
187:
188: BCSChild child;
189: synchronized (children)
190: {
191: if (children.containsKey(targetChild)
192: || ! validatePendingAdd(targetChild))
193: return false;
194: child = createBCSChild(targetChild, beanContextChildPeer);
195: children.put(targetChild, child);
196: }
197: synchronized (targetChild)
198: {
199: childJustAddedHook(targetChild, child);
200: }
201: fireChildrenAdded(new BeanContextMembershipEvent(this,
202: new Object[] { targetChild }));
203: return true;
204: }
205:
206: public boolean addAll (Collection c)
207: {
208:
209: throw new UnsupportedOperationException();
210: }
211:
212: public void addBeanContextMembershipListener
213: (BeanContextMembershipListener listener)
214: {
215: synchronized (bcmListeners)
216: {
217: if (! bcmListeners.contains(listener))
218: bcmListeners.add(listener);
219: }
220: }
221:
222: public boolean avoidingGui ()
223: throws NotImplementedException
224: {
225: throw new Error ("Not implemented");
226: }
227:
228: protected Iterator bcsChildren ()
229: {
230: synchronized (children)
231: {
232: return new BCSIterator(children.values().iterator());
233: }
234: }
235:
236: protected void bcsPreDeserializationHook (ObjectInputStream ois)
237: throws ClassNotFoundException, IOException, NotImplementedException
238: {
239: throw new Error ("Not implemented");
240: }
241:
242: protected void bcsPreSerializationHook (ObjectOutputStream oos)
243: throws IOException, NotImplementedException
244: {
245: throw new Error ("Not implemented");
246: }
247:
248: protected void childDeserializedHook (Object child, BeanContextSupport.BCSChild bcsc)
249: throws NotImplementedException
250: {
251: throw new Error ("Not implemented");
252: }
253:
254: protected void childJustAddedHook (Object child, BeanContextSupport.BCSChild bcsc)
255: {
256:
257: }
258:
259: protected void childJustRemovedHook (Object child, BeanContextSupport.BCSChild bcsc)
260: {
261:
262: }
263:
264: protected static final boolean classEquals (Class first, Class second)
265: {
266:
267: return (first == second || first.getName().equals(second.getName()));
268: }
269:
270: public void clear ()
271: {
272:
273:
274: throw new UnsupportedOperationException();
275: }
276:
277: public boolean contains (Object o)
278: {
279: synchronized (children)
280: {
281: return children.containsKey(o);
282: }
283: }
284:
285: public boolean containsAll (Collection c)
286: {
287: synchronized (children)
288: {
289: Iterator it = c.iterator();
290: while (it.hasNext())
291: if (! children.containsKey(it.next()))
292: return false;
293: }
294: return true;
295: }
296:
297: public boolean containsKey (Object o)
298: {
299: synchronized (children)
300: {
301: return children.containsKey(o);
302: }
303: }
304:
305: protected final Object[] copyChildren ()
306: {
307: synchronized (children)
308: {
309: return children.keySet().toArray();
310: }
311: }
312:
313: protected BeanContextSupport.BCSChild createBCSChild (Object targetChild, Object peer)
314: {
315: return new BCSChild(targetChild, peer);
316: }
317:
318: protected final void deserialize (ObjectInputStream ois, Collection coll)
319: throws ClassNotFoundException, IOException, NotImplementedException
320: {
321: throw new Error ("Not implemented");
322: }
323:
324: public void dontUseGui ()
325: throws NotImplementedException
326: {
327: throw new Error ("Not implemented");
328: }
329:
330: protected final void fireChildrenAdded (BeanContextMembershipEvent bcme)
331: {
332: synchronized (bcmListeners)
333: {
334: Iterator it = bcmListeners.iterator();
335: while (it.hasNext())
336: {
337: BeanContextMembershipListener l
338: = (BeanContextMembershipListener) it.next();
339: l.childrenAdded(bcme);
340: }
341: }
342: }
343:
344: protected final void fireChildrenRemoved (BeanContextMembershipEvent bcme)
345: {
346: synchronized (bcmListeners)
347: {
348: Iterator it = bcmListeners.iterator();
349: while (it.hasNext())
350: {
351: BeanContextMembershipListener l
352: = (BeanContextMembershipListener) it.next();
353: l.childrenRemoved(bcme);
354: }
355: }
356: }
357:
358: public BeanContext getBeanContextPeer ()
359: throws NotImplementedException
360: {
361: throw new Error ("Not implemented");
362: }
363:
364: protected static final BeanContextChild getChildBeanContextChild (Object child)
365: throws NotImplementedException
366: {
367: throw new Error ("Not implemented");
368: }
369:
370: protected static final BeanContextMembershipListener getChildBeanContextMembershipListener (Object child)
371: throws NotImplementedException
372: {
373: throw new Error ("Not implemented");
374: }
375:
376: protected static final PropertyChangeListener getChildPropertyChangeListener (Object child)
377: throws NotImplementedException
378: {
379: throw new Error ("Not implemented");
380: }
381:
382: protected static final Serializable getChildSerializable (Object child)
383: throws NotImplementedException
384: {
385: throw new Error ("Not implemented");
386: }
387:
388: protected static final VetoableChangeListener getChildVetoableChangeListener (Object child)
389: throws NotImplementedException
390: {
391: throw new Error ("Not implemented");
392: }
393:
394: protected static final Visibility getChildVisibility (Object child)
395: throws NotImplementedException
396: {
397: throw new Error ("Not implemented");
398: }
399:
400: public Locale getLocale ()
401: {
402: return locale;
403: }
404:
405: public URL getResource (String name, BeanContextChild bcc)
406: {
407: if (! contains(bcc))
408: throw new IllegalArgumentException("argument not a child");
409: ClassLoader loader = bcc.getClass().getClassLoader();
410: return (loader == null ? ClassLoader.getSystemResource(name)
411: : loader.getResource(name));
412: }
413:
414: public InputStream getResourceAsStream (String name, BeanContextChild bcc)
415: {
416: if (! contains(bcc))
417: throw new IllegalArgumentException("argument not a child");
418: ClassLoader loader = bcc.getClass().getClassLoader();
419: return (loader == null ? ClassLoader.getSystemResourceAsStream(name)
420: : loader.getResourceAsStream(name));
421: }
422:
423: protected void initialize ()
424: {
425: bcmListeners = new ArrayList();
426: children = new HashMap();
427: }
428:
429: public Object instantiateChild (String beanName)
430: throws IOException, ClassNotFoundException, NotImplementedException
431: {
432: throw new Error ("Not implemented");
433: }
434:
435: public boolean isDesignTime ()
436: {
437: return designTime;
438: }
439:
440: public boolean isEmpty ()
441: {
442: synchronized (children)
443: {
444: return children.isEmpty();
445: }
446: }
447:
448: public boolean isSerializing ()
449: throws NotImplementedException
450: {
451: throw new Error ("Not implemented");
452: }
453:
454: public Iterator iterator ()
455: {
456: synchronized (children)
457: {
458: return children.keySet().iterator();
459: }
460: }
461:
462: public boolean needsGui ()
463: throws NotImplementedException
464: {
465: throw new Error ("Not implemented");
466: }
467:
468: public void okToUseGui ()
469: throws NotImplementedException
470: {
471: throw new Error ("Not implemented");
472: }
473:
474: public void propertyChange (PropertyChangeEvent pce)
475: throws NotImplementedException
476: {
477: throw new Error ("Not implemented");
478: }
479:
480: public final void readChildren (ObjectInputStream ois)
481: throws IOException, ClassNotFoundException, NotImplementedException
482: {
483: throw new Error ("Not implemented");
484: }
485:
486: public boolean remove (Object targetChild)
487: {
488: return remove(targetChild, true);
489: }
490:
491: protected boolean remove (Object targetChild, boolean callChildSetBC)
492: throws NotImplementedException
493: {
494: if (targetChild == null)
495: throw new IllegalArgumentException();
496:
497: throw new Error ("Not implemented");
498: }
499:
500: public boolean removeAll (Collection c)
501: {
502:
503: throw new UnsupportedOperationException();
504: }
505:
506: public void removeBeanContextMembershipListener (BeanContextMembershipListener bcml)
507: {
508: synchronized (bcmListeners)
509: {
510: bcmListeners.remove(bcml);
511: }
512: }
513:
514: public boolean retainAll (Collection c)
515: {
516:
517: throw new UnsupportedOperationException();
518: }
519:
520: protected final void serialize (ObjectOutputStream oos, Collection coll)
521: throws IOException, NotImplementedException
522: {
523: throw new Error ("Not implemented");
524: }
525:
526: public void setDesignTime (boolean dtime)
527: {
528: boolean save = designTime;
529: designTime = dtime;
530: firePropertyChange(DesignMode.PROPERTYNAME, Boolean.valueOf(save),
531: Boolean.valueOf(dtime));
532: }
533:
534: public void setLocale (Locale newLocale)
535: throws PropertyVetoException
536: {
537: if (newLocale == null || locale == newLocale)
538: return;
539: fireVetoableChange("locale", locale, newLocale);
540: Locale oldLocale = locale;
541: locale = newLocale;
542: firePropertyChange("locale", oldLocale, newLocale);
543: }
544:
545: public int size ()
546: {
547: synchronized (children)
548: {
549: return children.size();
550: }
551: }
552:
553: public Object[] toArray ()
554: {
555: synchronized (children)
556: {
557: return children.keySet().toArray();
558: }
559: }
560:
561: public Object[] toArray(Object[] array)
562: throws NotImplementedException
563: {
564:
565: synchronized (children)
566: {
567: return children.keySet().toArray(array);
568: }
569: }
570:
571: protected boolean validatePendingAdd (Object targetChild)
572: {
573: return true;
574: }
575:
576: protected boolean validatePendingRemove (Object targetChild)
577: {
578: return true;
579: }
580:
581: public void vetoableChange (PropertyChangeEvent pce)
582: throws PropertyVetoException, NotImplementedException
583: {
584: throw new Error ("Not implemented");
585: }
586:
587: public final void writeChildren (ObjectOutputStream oos)
588: throws IOException, NotImplementedException
589: {
590: throw new Error ("Not implemented");
591: }
592: }