jdk/src/share/classes/java/beans/EventSetDescriptor.java
author mcimadamore
Thu, 01 Dec 2011 18:34:23 +0000
changeset 11120 f8576c769572
parent 6657 15dbb366c6a3
child 14887 226dd1cda199
permissions -rw-r--r--
7116954: Misc warnings in java.beans/java.beans.context Summary: Remove generic warnings form java.beans and java.beans.context Reviewed-by: alanb, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
     2
 * Copyright (c) 1996, 2010, 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) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            Class[] args = getParameterTypes(getClass0(), listenerMethods[0]);
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);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        this.listenerMethodDescriptors = listenerMethodDescriptors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        setAddListenerMethod(addListenerMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        setRemoveListenerMethod(removeListenerMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        setListenerType(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Gets the <TT>Class</TT> object for the target interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @return The Class object for the target interface that will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * get invoked when the event is fired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public Class<?> getListenerType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return (this.listenerTypeRef != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                ? this.listenerTypeRef.get()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   298
    private void setListenerType(Class<?> cls) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        this.listenerTypeRef = getWeakReference(cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Gets the methods of the target listener interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @return An array of <TT>Method</TT> objects for the target methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * within the target listener interface that will get called when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * events are fired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public synchronized Method[] getListenerMethods() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        Method[] methods = getListenerMethods0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        if (methods == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            if (listenerMethodDescriptors != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                methods = new Method[listenerMethodDescriptors.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                for (int i = 0; i < methods.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    methods[i] = listenerMethodDescriptors[i].getMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            setListenerMethods(methods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        return methods;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    private void setListenerMethods(Method[] methods) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        if (methods == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        if (listenerMethodDescriptors == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            listenerMethodDescriptors = new MethodDescriptor[methods.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            for (int i = 0; i < methods.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                listenerMethodDescriptors[i] = new MethodDescriptor(methods[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        this.listenerMethodsRef = getSoftReference(methods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    private Method[] getListenerMethods0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return (this.listenerMethodsRef != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                ? this.listenerMethodsRef.get()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Gets the <code>MethodDescriptor</code>s of the target listener interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @return An array of <code>MethodDescriptor</code> objects for the target methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * within the target listener interface that will get called when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * events are fired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public synchronized MethodDescriptor[] getListenerMethodDescriptors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return listenerMethodDescriptors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * Gets the method used to add event listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @return The method used to register a listener at the event source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public synchronized Method getAddListenerMethod() {
4960
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   359
        return getMethod(this.addMethodDescriptor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    private synchronized void setAddListenerMethod(Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if (getClass0() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            setClass0(method.getDeclaringClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        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
   370
        setTransient(method.getAnnotation(Transient.class));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * Gets the method used to remove event listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @return The method used to remove a listener at the event source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public synchronized Method getRemoveListenerMethod() {
4960
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   379
        return getMethod(this.removeMethodDescriptor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    private synchronized void setRemoveListenerMethod(Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (getClass0() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            setClass0(method.getDeclaringClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        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
   390
        setTransient(method.getAnnotation(Transient.class));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * Gets the method used to access the registered event listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @return The method used to access the array of listeners at the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *         source or null if it doesn't exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    public synchronized Method getGetListenerMethod() {
4960
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   401
        return getMethod(this.getMethodDescriptor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    private synchronized void setGetListenerMethod(Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if (getClass0() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            setClass0(method.getDeclaringClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        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
   412
        setTransient(method.getAnnotation(Transient.class));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * Mark an event set as unicast (or not).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @param unicast  True if the event set is unicast.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public void setUnicast(boolean unicast) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        this.unicast = unicast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * Normally event sources are multicast.  However there are some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * exceptions that are strictly unicast.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @return  <TT>true</TT> if the event set is unicast.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *          Defaults to <TT>false</TT>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public boolean isUnicast() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        return unicast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * Marks an event set as being in the &quot;default&quot; set (or not).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * By default this is <TT>true</TT>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @param inDefaultEventSet <code>true</code> if the event set is in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *                          the &quot;default&quot; set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *                          <code>false</code> if not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    public void setInDefaultEventSet(boolean inDefaultEventSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        this.inDefaultEventSet = inDefaultEventSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * Reports if an event set is in the &quot;default&quot; set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @return  <TT>true</TT> if the event set is in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *          the &quot;default&quot; set.  Defaults to <TT>true</TT>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    public boolean isInDefaultEventSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        return inDefaultEventSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * Package-private constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * Merge two event set descriptors.  Where they conflict, give the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * second argument (y) priority over the first argument (x).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @param x  The first (lower priority) EventSetDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @param y  The second (higher priority) EventSetDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    EventSetDescriptor(EventSetDescriptor x, EventSetDescriptor y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        super(x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        listenerMethodDescriptors = x.listenerMethodDescriptors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        if (y.listenerMethodDescriptors != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            listenerMethodDescriptors = y.listenerMethodDescriptors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        listenerTypeRef = x.listenerTypeRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if (y.listenerTypeRef != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            listenerTypeRef = y.listenerTypeRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        addMethodDescriptor = x.addMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        if (y.addMethodDescriptor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            addMethodDescriptor = y.addMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        removeMethodDescriptor = x.removeMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if (y.removeMethodDescriptor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            removeMethodDescriptor = y.removeMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        getMethodDescriptor = x.getMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        if (y.getMethodDescriptor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            getMethodDescriptor = y.getMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        unicast = y.unicast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        if (!x.inDefaultEventSet || !y.inDefaultEventSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            inDefaultEventSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * Package-private dup constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * This must isolate the new object from any changes to the old object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    EventSetDescriptor(EventSetDescriptor old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        super(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        if (old.listenerMethodDescriptors != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            int len = old.listenerMethodDescriptors.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            listenerMethodDescriptors = new MethodDescriptor[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                listenerMethodDescriptors[i] = new MethodDescriptor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                                        old.listenerMethodDescriptors[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        listenerTypeRef = old.listenerTypeRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        addMethodDescriptor = old.addMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        removeMethodDescriptor = old.removeMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        getMethodDescriptor = old.getMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        unicast = old.unicast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        inDefaultEventSet = old.inDefaultEventSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
4960
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   521
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   522
    void appendTo(StringBuilder sb) {
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   523
        appendTo(sb, "unicast", this.unicast);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   524
        appendTo(sb, "inDefaultEventSet", this.inDefaultEventSet);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   525
        appendTo(sb, "listenerType", this.listenerTypeRef);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   526
        appendTo(sb, "getListenerMethod", getMethod(this.getMethodDescriptor));
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   527
        appendTo(sb, "addListenerMethod", getMethod(this.addMethodDescriptor));
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   528
        appendTo(sb, "removeListenerMethod", getMethod(this.removeMethodDescriptor));
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   529
    }
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   530
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   531
    private static Method getMethod(MethodDescriptor descriptor) {
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   532
        return (descriptor != null)
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   533
                ? descriptor.getMethod()
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   534
                : null;
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 466
diff changeset
   535
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
}