01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.controls.runtime.packaging;
20:
21: import java.beans.EventSetDescriptor;
22: import java.beans.IntrospectionException;
23: import java.beans.MethodDescriptor;
24: import java.lang.ref.Reference;
25: import java.lang.ref.SoftReference;
26: import java.lang.reflect.Method;
27:
28: /**
29: * The ControlEventSetDescriptor is a result of an infortunate evoluntary flaw in the
30: * java.beans.EventSetDescriptor class. The getListeners functionality for event sets was
31: * added after the initial implementation, and unfortunately, there is no constructor that
32: * let you specify <b>both</b> the MethodDescriptors for events <b>and</b> the getListener
33: * method. To compensate for this, we must subclass and provide our own getGetListenerMethod
34: * implementation.
35: */
36: public class ControlEventSetDescriptor extends EventSetDescriptor {
37: /**
38: * This constructor adds the getListenerMethod argument that is missing from the JDK!
39: */
40: public ControlEventSetDescriptor(String eventSetName,
41: Class<?> listenerType,
42: MethodDescriptor[] listenerMethodDescriptors,
43: Method addListenerMethod, Method removeListenerMethod,
44: Method getListenerMethod) throws IntrospectionException {
45: super (eventSetName, listenerType, listenerMethodDescriptors,
46: addListenerMethod, removeListenerMethod);
47:
48: // Follow the same pattern as the JDK and store the method as a soft reference, so
49: // the introspector (alone) won't prevent Class garbage collection.
50: _getMethodRef = new SoftReference<Method>(getListenerMethod);
51: }
52:
53: /**
54: * Override the default implementation of getGetListenerMethod to return the method
55: * provided in the constructor.
56: */
57: public Method getGetListenerMethod() {
58: if (_getMethodRef == null)
59: return null;
60:
61: return _getMethodRef.get();
62: }
63:
64: Reference<Method> _getMethodRef;
65: }
|