KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > runtime > packaging > ControlEventSetDescriptor


1 package org.apache.beehive.controls.runtime.packaging;
2
3 import java.beans.EventSetDescriptor JavaDoc;
4 import java.beans.IntrospectionException JavaDoc;
5 import java.beans.MethodDescriptor JavaDoc;
6 import java.lang.ref.Reference JavaDoc;
7 import java.lang.ref.SoftReference JavaDoc;
8 import java.lang.reflect.Method JavaDoc;
9
10 /**
11  * The ControlEventSetDescriptor is a result of an infortunate evoluntary flaw in the
12  * java.beans.EventSetDescriptor class. The getListeners functionality for event sets was
13  * added after the initial implementation, and unfortunately, there is no constructor that
14  * let you specify <b>both</b> the MethodDescriptors for events <b>and</b> the getListener
15  * method. To compensate for this, we must subclass and provide our own getGetListenerMethod
16  * implementation.
17  */

18 public class ControlEventSetDescriptor extends EventSetDescriptor JavaDoc
19 {
20     /**
21      * This constructor adds the getListenerMethod argument that is missing from the JDK!
22      */

23     public ControlEventSetDescriptor(String JavaDoc eventSetName, Class JavaDoc<?> listenerType,
24                                      MethodDescriptor JavaDoc[] listenerMethodDescriptors,
25                                      Method JavaDoc addListenerMethod, Method JavaDoc removeListenerMethod,
26                                      Method JavaDoc getListenerMethod)
27            throws IntrospectionException JavaDoc
28     {
29         super(eventSetName, listenerType, listenerMethodDescriptors,
30               addListenerMethod, removeListenerMethod);
31
32         // Follow the same pattern as the JDK and store the method as a soft reference, so
33
// the introspector (alone) won't prevent Class garbage collection.
34
_getMethodRef = new SoftReference JavaDoc<Method JavaDoc>(getListenerMethod);
35     }
36
37     /**
38      * Override the default implementation of getGetListenerMethod to return the method
39      * provided in the constructor.
40      */

41     public Method JavaDoc getGetListenerMethod()
42     {
43         if (_getMethodRef == null)
44             return null;
45
46         return _getMethodRef.get();
47     }
48
49     Reference JavaDoc<Method JavaDoc> _getMethodRef;
50 }
51
Popular Tags