jdk/src/share/classes/java/beans/EventSetDescriptor.java
author darcy
Tue, 03 Jun 2014 09:22:59 -0700
changeset 25123 1f70b30da563
parent 14887 226dd1cda199
child 25130 adfaa02ea516
permissions -rw-r--r--
8042860: Fix raw and unchecked warnings in java.beans Reviewed-by: malenkov, alanb, mduigou
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
25123
1f70b30da563 8042860: Fix raw and unchecked warnings in java.beans
darcy
parents: 14887
diff changeset
     2
 * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.beans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.ref.Reference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.Method;
5947
0e6f2837eeca 6707234: Method returned by Introspector.internalFindMethod not necessarily most specific
malenkov
parents: 5506
diff changeset
    30
import java.lang.reflect.Modifier;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * An EventSetDescriptor describes a group of events that a given Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * bean fires.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * The given group of events are all delivered as method calls on a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * event listener interface, and an event listener object can be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * via a call on a registration method supplied by the event source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class EventSetDescriptor extends FeatureDescriptor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private MethodDescriptor[] listenerMethodDescriptors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private MethodDescriptor addMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private MethodDescriptor removeMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private MethodDescriptor getMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private Reference<Method[]> listenerMethodsRef;
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
    48
    private Reference<? extends Class<?>> listenerTypeRef;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private boolean unicast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private boolean inDefaultEventSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Creates an <TT>EventSetDescriptor</TT> assuming that you are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * following the most simple standard design pattern where a named
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * event &quot;fred&quot; is (1) delivered as a call on the single method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * interface FredListener, (2) has a single argument of type FredEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * and (3) where the FredListener may be registered with a call on an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * addFredListener method of the source component and removed with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * call on a removeFredListener method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @param sourceClass  The class firing the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * @param eventSetName  The programmatic name of the event.  E.g. &quot;fred&quot;.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *          Note that this should normally start with a lower-case character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @param listenerType  The target interface that events
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *          will get delivered to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @param listenerMethodName  The method that will get called when the event gets
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *          delivered to its target listener interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @exception IntrospectionException if an exception occurs during
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *              introspection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public EventSetDescriptor(Class<?> sourceClass, String eventSetName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                Class<?> listenerType, String listenerMethodName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        this(sourceClass, eventSetName, listenerType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
             new String[] { listenerMethodName },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
             Introspector.ADD_PREFIX + getListenerClassName(listenerType),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
             Introspector.REMOVE_PREFIX + getListenerClassName(listenerType),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
             Introspector.GET_PREFIX + getListenerClassName(listenerType) + "s");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        String eventName = NameGenerator.capitalize(eventSetName) + "Event";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        Method[] listenerMethods = getListenerMethods();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (listenerMethods.length > 0) {
25123
1f70b30da563 8042860: Fix raw and unchecked warnings in java.beans
darcy
parents: 14887
diff changeset
    84
            Class<?>[] args = getParameterTypes(getClass0(), listenerMethods[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            // Check for EventSet compliance. Special case for vetoableChange. See 4529996
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            if (!"vetoableChange".equals(eventSetName) && !args[0].getName().endsWith(eventName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                throw new IntrospectionException("Method \"" + listenerMethodName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                                 "\" should have argument \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                                 eventName + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
    94
    private static String getListenerClassName(Class<?> cls) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        String className = cls.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        return className.substring(className.lastIndexOf('.') + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Creates an <TT>EventSetDescriptor</TT> from scratch using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * string names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param sourceClass  The class firing the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param eventSetName The programmatic name of the event set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *          Note that this should normally start with a lower-case character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param listenerType  The Class of the target interface that events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *          will get delivered to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param listenerMethodNames The names of the methods that will get called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *          when the event gets delivered to its target listener interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param addListenerMethodName  The name of the method on the event source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *          that can be used to register an event listener object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @param removeListenerMethodName  The name of the method on the event source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *          that can be used to de-register an event listener object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @exception IntrospectionException if an exception occurs during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *              introspection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public EventSetDescriptor(Class<?> sourceClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                String eventSetName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                Class<?> listenerType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                String listenerMethodNames[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                String addListenerMethodName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                String removeListenerMethodName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        this(sourceClass, eventSetName, listenerType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
             listenerMethodNames, addListenerMethodName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
             removeListenerMethodName, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * This constructor creates an EventSetDescriptor from scratch using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * string names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @param sourceClass  The class firing the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param eventSetName The programmatic name of the event set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *          Note that this should normally start with a lower-case character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @param listenerType  The Class of the target interface that events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *          will get delivered to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param listenerMethodNames The names of the methods that will get called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *          when the event gets delivered to its target listener interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param addListenerMethodName  The name of the method on the event source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *          that can be used to register an event listener object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param removeListenerMethodName  The name of the method on the event source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *          that can be used to de-register an event listener object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param getListenerMethodName The method on the event source that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *          can be used to access the array of event listener objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @exception IntrospectionException if an exception occurs during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *              introspection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public EventSetDescriptor(Class<?> sourceClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                String eventSetName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                Class<?> listenerType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                String listenerMethodNames[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                String addListenerMethodName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                String removeListenerMethodName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                String getListenerMethodName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (sourceClass == null || eventSetName == null || listenerType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        setName(eventSetName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        setClass0(sourceClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        setListenerType(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        Method[] listenerMethods = new Method[listenerMethodNames.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        for (int i = 0; i < listenerMethodNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            // Check for null names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            if (listenerMethodNames[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            listenerMethods[i] = getMethod(listenerType, listenerMethodNames[i], 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        setListenerMethods(listenerMethods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        setAddListenerMethod(getMethod(sourceClass, addListenerMethodName, 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        setRemoveListenerMethod(getMethod(sourceClass, removeListenerMethodName, 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        // Be more forgiving of not finding the getListener method.
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5947
diff changeset
   179
        Method method = Introspector.findMethod(sourceClass, getListenerMethodName, 0);
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5947
diff changeset
   180
        if (method != null) {
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5947
diff changeset
   181
            setGetListenerMethod(method);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   185
    private static Method getMethod(Class<?> cls, String name, int args)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        Method method = Introspector.findMethod(cls, name, args);
5947
0e6f2837eeca 6707234: Method returned by Introspector.internalFindMethod not necessarily most specific
malenkov
parents: 5506
diff changeset
   191
        if ((method == null) || Modifier.isStatic(method.getModifiers())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            throw new IntrospectionException("Method not found: " + name +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                             " on class " + cls.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Creates an <TT>EventSetDescriptor</TT> from scratch using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * <TT>java.lang.reflect.Method</TT> and <TT>java.lang.Class</TT> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param eventSetName The programmatic name of the event set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param listenerType The Class for the listener interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param listenerMethods  An array of Method objects describing each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *          of the event handling methods in the target listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @param addListenerMethod  The method on the event source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *          that can be used to register an event listener object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @param removeListenerMethod  The method on the event source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *          that can be used to de-register an event listener object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @exception IntrospectionException if an exception occurs during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *              introspection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public EventSetDescriptor(String eventSetName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                Class<?> listenerType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                Method listenerMethods[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                Method addListenerMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                Method removeListenerMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        this(eventSetName, listenerType, listenerMethods,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
             addListenerMethod, removeListenerMethod, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * This constructor creates an EventSetDescriptor from scratch using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * java.lang.reflect.Method and java.lang.Class objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @param eventSetName The programmatic name of the event set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param listenerType The Class for the listener interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @param listenerMethods  An array of Method objects describing each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *          of the event handling methods in the target listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @param addListenerMethod  The method on the event source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *          that can be used to register an event listener object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param removeListenerMethod  The method on the event source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *          that can be used to de-register an event listener object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param getListenerMethod The method on the event source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *          that can be used to access the array of event listener objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @exception IntrospectionException if an exception occurs during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *              introspection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public EventSetDescriptor(String eventSetName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                Class<?> listenerType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                Method listenerMethods[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                Method addListenerMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                Method removeListenerMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                Method getListenerMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        setName(eventSetName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        setListenerMethods(listenerMethods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        setAddListenerMethod(addListenerMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        setRemoveListenerMethod( removeListenerMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        setGetListenerMethod(getListenerMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        setListenerType(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Creates an <TT>EventSetDescriptor</TT> from scratch using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * <TT>java.lang.reflect.MethodDescriptor</TT> and <TT>java.lang.Class</TT>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *  objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param eventSetName The programmatic name of the event set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @param listenerType The Class for the listener interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @param listenerMethodDescriptors  An array of MethodDescriptor objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *           describing each of the event handling methods in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *           target listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param addListenerMethod  The method on the event source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *          that can be used to register an event listener object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param removeListenerMethod  The method on the event source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *          that can be used to de-register an event listener object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @exception IntrospectionException if an exception occurs during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *              introspection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public EventSetDescriptor(String eventSetName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                Class<?> listenerType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                MethodDescriptor listenerMethodDescriptors[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                Method addListenerMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                Method removeListenerMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        setName(eventSetName);
14887
226dd1cda199 8005065: [findbugs] reference to mutable array in JavaBeans
malenkov
parents: 11120
diff changeset
   280
        this.listenerMethodDescriptors = (listenerMethodDescriptors != null)
226dd1cda199 8005065: [findbugs] reference to mutable array in JavaBeans
malenkov
parents: 11120
diff changeset
   281
                ? listenerMethodDescriptors.clone()
226dd1cda199 8005065: [findbugs] reference to mutable array in JavaBeans
malenkov
parents: 11120
diff changeset
   282
                : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        setAddListenerMethod(addListenerMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        setRemoveListenerMethod(removeListenerMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        setListenerType(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * Gets the <TT>Class</TT> object for the target interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @return The Class object for the target interface that will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * get invoked when the event is fired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public Class<?> getListenerType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        return (this.listenerTypeRef != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                ? this.listenerTypeRef.get()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   300
    private void setListenerType(Class<?> cls) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        this.listenerTypeRef = getWeakReference(cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * Gets the methods of the target listener interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @return An array of <TT>Method</TT> objects for the target methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * within the target listener interface that will get called when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * events are fired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public synchronized Method[] getListenerMethods() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        Method[] methods = getListenerMethods0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        if (methods == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            if (listenerMethodDescriptors != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                methods = new Method[listenerMethodDescriptors.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                for (int i = 0; i < methods.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    methods[i] = listenerMethodDescriptors[i].getMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            setListenerMethods(methods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return methods;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    private void setListenerMethods(Method[] methods) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if (methods == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (listenerMethodDescriptors == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            listenerMethodDescriptors = new MethodDescriptor[methods.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            for (int i = 0; i < methods.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                listenerMethodDescriptors[i] = new MethodDescriptor(methods[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        this.listenerMethodsRef = getSoftReference(methods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    private Method[] getListenerMethods0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return (this.listenerMethodsRef != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                ? this.listenerMethodsRef.get()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * Gets the <code>MethodDescriptor</code>s of the target listener interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @return An array of <code>MethodDescriptor</code> objects for the target methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * within the target listener interface that will get called when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * events are fired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public synchronized MethodDescriptor[] getListenerMethodDescriptors() {
14887
226dd1cda199 8005065: [findbugs] reference to mutable array in JavaBeans
malenkov
parents: 11120
diff changeset
   352
        return (this.listenerMethodDescriptors != null)
226dd1cda199 8005065: [findbugs] reference to mutable array in JavaBeans
malenkov
parents: 11120
diff changeset
   353
                ? this.listenerMethodDescriptors.clone()
226dd1cda199 8005065: [findbugs] reference to mutable array in JavaBeans
malenkov
parents: 11120
diff changeset
   354
                : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Gets the method used to add event listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @return The method used to register a listener at the event source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public synchronized Method getAddListenerMethod() {
4960
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   363
        return getMethod(this.addMethodDescriptor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    private synchronized void setAddListenerMethod(Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        if (getClass0() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            setClass0(method.getDeclaringClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        addMethodDescriptor = new MethodDescriptor(method);
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   374
        setTransient(method.getAnnotation(Transient.class));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Gets the method used to remove event listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @return The method used to remove a listener at the event source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    public synchronized Method getRemoveListenerMethod() {
4960
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   383
        return getMethod(this.removeMethodDescriptor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    private synchronized void setRemoveListenerMethod(Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (getClass0() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            setClass0(method.getDeclaringClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        removeMethodDescriptor = new MethodDescriptor(method);
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   394
        setTransient(method.getAnnotation(Transient.class));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Gets the method used to access the registered event listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @return The method used to access the array of listeners at the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *         source or null if it doesn't exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public synchronized Method getGetListenerMethod() {
4960
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   405
        return getMethod(this.getMethodDescriptor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    private synchronized void setGetListenerMethod(Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if (getClass0() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            setClass0(method.getDeclaringClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        getMethodDescriptor = new MethodDescriptor(method);
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   416
        setTransient(method.getAnnotation(Transient.class));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * Mark an event set as unicast (or not).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @param unicast  True if the event set is unicast.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public void setUnicast(boolean unicast) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        this.unicast = unicast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Normally event sources are multicast.  However there are some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * exceptions that are strictly unicast.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @return  <TT>true</TT> if the event set is unicast.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *          Defaults to <TT>false</TT>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    public boolean isUnicast() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        return unicast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * Marks an event set as being in the &quot;default&quot; set (or not).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * By default this is <TT>true</TT>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @param inDefaultEventSet <code>true</code> if the event set is in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *                          the &quot;default&quot; set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *                          <code>false</code> if not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    public void setInDefaultEventSet(boolean inDefaultEventSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        this.inDefaultEventSet = inDefaultEventSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * Reports if an event set is in the &quot;default&quot; set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @return  <TT>true</TT> if the event set is in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *          the &quot;default&quot; set.  Defaults to <TT>true</TT>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    public boolean isInDefaultEventSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        return inDefaultEventSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * Package-private constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * Merge two event set descriptors.  Where they conflict, give the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * second argument (y) priority over the first argument (x).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @param x  The first (lower priority) EventSetDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @param y  The second (higher priority) EventSetDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    EventSetDescriptor(EventSetDescriptor x, EventSetDescriptor y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        super(x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        listenerMethodDescriptors = x.listenerMethodDescriptors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        if (y.listenerMethodDescriptors != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            listenerMethodDescriptors = y.listenerMethodDescriptors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        listenerTypeRef = x.listenerTypeRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (y.listenerTypeRef != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            listenerTypeRef = y.listenerTypeRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        addMethodDescriptor = x.addMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        if (y.addMethodDescriptor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            addMethodDescriptor = y.addMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        removeMethodDescriptor = x.removeMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        if (y.removeMethodDescriptor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            removeMethodDescriptor = y.removeMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        getMethodDescriptor = x.getMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (y.getMethodDescriptor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            getMethodDescriptor = y.getMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        unicast = y.unicast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        if (!x.inDefaultEventSet || !y.inDefaultEventSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            inDefaultEventSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * Package-private dup constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * This must isolate the new object from any changes to the old object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    EventSetDescriptor(EventSetDescriptor old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        super(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        if (old.listenerMethodDescriptors != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            int len = old.listenerMethodDescriptors.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            listenerMethodDescriptors = new MethodDescriptor[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                listenerMethodDescriptors[i] = new MethodDescriptor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                                        old.listenerMethodDescriptors[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        listenerTypeRef = old.listenerTypeRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        addMethodDescriptor = old.addMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        removeMethodDescriptor = old.removeMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        getMethodDescriptor = old.getMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        unicast = old.unicast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        inDefaultEventSet = old.inDefaultEventSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
4960
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   525
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   526
    void appendTo(StringBuilder sb) {
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   527
        appendTo(sb, "unicast", this.unicast);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   528
        appendTo(sb, "inDefaultEventSet", this.inDefaultEventSet);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   529
        appendTo(sb, "listenerType", this.listenerTypeRef);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   530
        appendTo(sb, "getListenerMethod", getMethod(this.getMethodDescriptor));
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   531
        appendTo(sb, "addListenerMethod", getMethod(this.addMethodDescriptor));
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   532
        appendTo(sb, "removeListenerMethod", getMethod(this.removeMethodDescriptor));
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   533
    }
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   534
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   535
    private static Method getMethod(MethodDescriptor descriptor) {
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   536
        return (descriptor != null)
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   537
                ? descriptor.getMethod()
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   538
                : null;
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   539
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
}