KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > beans > beancontext > CustomBeanContextServicesSupport


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.beans.beancontext;
8
9 import java.beans.beancontext.BeanContext JavaDoc;
10 import java.beans.beancontext.BeanContextChild JavaDoc;
11 import java.beans.beancontext.BeanContextServiceRevokedListener JavaDoc;
12 import java.beans.beancontext.BeanContextServices JavaDoc;
13 import java.beans.beancontext.BeanContextServicesSupport JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.TooManyListenersException JavaDoc;
16
17 import org.ejtools.util.state.Storable;
18 import org.ejtools.util.state.StoreVisitor;
19
20 /**
21  * Enhancement of the {@link BeanContextServicesSupport} to provide an implementation
22  * for the <code>clear</code> method, and a recursive search for a particular service.
23  *
24  * @author Laurent Etiemble
25  * @version $Revision: 1.9 $
26  */

27 public abstract class CustomBeanContextServicesSupport extends BeanContextServicesSupport JavaDoc implements Storable
28 {
29    /**
30     * Description of the Method
31     *
32     * @param visitor Description of the Parameter
33     */

34    public void accept(StoreVisitor visitor)
35    {
36       visitor.persist(this);
37    }
38
39
40    /** Implementation of the <code>clear</code> method */
41    public void clear()
42    {
43       Iterator JavaDoc iterator;
44
45       // Recursively clear the content
46
iterator = this.iterator();
47       while (iterator.hasNext())
48       {
49          Object JavaDoc o = iterator.next();
50          if (o instanceof BeanContext JavaDoc)
51          {
52             ((BeanContext JavaDoc) o).clear();
53          }
54       }
55
56       // Remove all elements
57
iterator = this.iterator();
58       while (iterator.hasNext())
59       {
60          iterator.next();
61          iterator.remove();
62       }
63    }
64
65
66    /**
67     * Gets the BeanContext service recursivly if necessary.
68     *
69     * @param child Description of Parameter
70     * @param requestor Description of Parameter
71     * @param serviceClass Description of Parameter
72     * @param serviceSelector Description of Parameter
73     * @param bcsrl Description of Parameter
74     * @return The value
75     * @exception TooManyListenersException Description of Exception
76     * Object,BeanContextServiceRevokedListener)
77     */

78    public Object JavaDoc getService(BeanContextChild JavaDoc child, Object JavaDoc requestor, Class JavaDoc serviceClass, Object JavaDoc serviceSelector, BeanContextServiceRevokedListener JavaDoc bcsrl)
79       throws TooManyListenersException JavaDoc
80    {
81       Object JavaDoc service = super.getService(child, requestor, serviceClass, serviceSelector, bcsrl);
82
83       // If the service requested is not provided by this BeanContext, try the parent
84
if (service == null)
85       {
86          BeanContextServices JavaDoc bcs = null;
87
88          try
89          {
90             bcs = (BeanContextServices JavaDoc) this.getBeanContext();
91          }
92          catch (ClassCastException JavaDoc cce)
93          {
94             return null;
95          }
96
97          return bcs.getService(this, requestor, serviceClass, serviceSelector, bcsrl);
98       }
99
100       return service;
101    }
102 }
103
Popular Tags