src/java.desktop/share/classes/java/beans/Introspector.java
author mchung
Tue, 06 Nov 2018 10:01:16 -0800
changeset 52427 3c6aa484536c
parent 52248 2e330da7cbf4
child 54862 3464146f4a1c
permissions -rw-r--r--
8211122: Reduce the number of internal classes made accessible to jdk.unsupported Reviewed-by: alanb, dfuchs, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
     2
 * Copyright (c) 1996, 2018, 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: 4851
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: 4851
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: 4851
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4851
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4851
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.beans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
13356
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
    27
import com.sun.beans.TypeResolver;
4382
c0759b1ccb56 5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents: 3476
diff changeset
    28
import com.sun.beans.WeakCache;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.beans.finder.ClassFinder;
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
    30
import com.sun.beans.introspect.ClassInfo;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
    31
import com.sun.beans.introspect.EventSetInfo;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
    32
import com.sun.beans.introspect.PropertyInfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
7249
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
    34
import java.awt.Component;
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
    35
4851
4f7de5eeeac7 6921057: REGRESSION: persistence delegate issue on Windows and Linux against 5.u23b03/6u17b11
malenkov
parents: 4393
diff changeset
    36
import java.lang.ref.Reference;
4f7de5eeeac7 6921057: REGRESSION: persistence delegate issue on Windows and Linux against 5.u23b03/6u17b11
malenkov
parents: 4393
diff changeset
    37
import java.lang.ref.SoftReference;
30906
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
    38
import java.lang.reflect.Constructor;
42208
7c1017f0ade5 8155874: Fix java.desktop deprecation warnings about Class.newInstance
prr
parents: 35667
diff changeset
    39
import java.lang.reflect.InvocationTargetException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.lang.reflect.Method;
13356
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
    41
import java.lang.reflect.Type;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.Iterator;
7249
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
    47
import java.util.EventObject;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.TreeMap;
3239
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents: 2
diff changeset
    50
52427
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 52248
diff changeset
    51
import jdk.internal.access.JavaBeansAccess;
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 52248
diff changeset
    52
import jdk.internal.access.SharedSecrets;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.reflect.misc.ReflectUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * The Introspector class provides a standard way for tools to learn about
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * the properties, events, and methods supported by a target Java Bean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * For each of those three kinds of information, the Introspector will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * separately analyze the bean's class and superclasses looking for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * either explicit or implicit information and use that information to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * build a BeanInfo object that comprehensively describes the target bean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * For each class "Foo", explicit information may be available if there exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * a corresponding "FooBeanInfo" class that provides a non-null value when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * queried for the information.   We first look for the BeanInfo class by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * taking the full package-qualified name of the target bean class and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * appending "BeanInfo" to form a new class name.  If this fails, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * we take the final classname component of this name, and look for that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * class in each of the packages specified in the BeanInfo package search
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * Thus for a class such as "sun.xyz.OurButton" we would first look for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * BeanInfo class called "sun.xyz.OurButtonBeanInfo" and if that failed we'd
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * look in each package in the BeanInfo search path for an OurButtonBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * class.  With the default search path, this would mean looking for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * "sun.beans.infos.OurButtonBeanInfo".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * If a class provides explicit BeanInfo about itself then we add that to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * the BeanInfo information we obtained from analyzing any derived classes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * but we regard the explicit information as being definitive for the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * class and its base classes, and do not proceed any further up the superclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * If we don't find explicit BeanInfo on a class, we use low-level
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * reflection to study the methods of the class and apply standard design
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * patterns to identify property accessors, event sources, or public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * methods.  We then proceed to analyze the class's superclass and add
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * in the information from it (and possibly on up the superclass chain).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * For more information about introspection and design patterns, please
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * consult the
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 19213
diff changeset
    93
 *  <a href="http://www.oracle.com/technetwork/java/javase/documentation/spec-136004.html">JavaBeans&trade; specification</a>.
25130
adfaa02ea516 8044855: Add missing @since tag under java.beans.*
henryjen
parents: 25123
diff changeset
    94
 *
adfaa02ea516 8044855: Add missing @since tag under java.beans.*
henryjen
parents: 25123
diff changeset
    95
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
public class Introspector {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // Flags that can be used to control getBeanInfo:
19213
c360667a0da2 8022406: Fix doclint issues in java.beans
darcy
parents: 18757
diff changeset
   101
    /**
c360667a0da2 8022406: Fix doclint issues in java.beans
darcy
parents: 18757
diff changeset
   102
     * Flag to indicate to use of all beaninfo.
25130
adfaa02ea516 8044855: Add missing @since tag under java.beans.*
henryjen
parents: 25123
diff changeset
   103
     * @since 1.2
19213
c360667a0da2 8022406: Fix doclint issues in java.beans
darcy
parents: 18757
diff changeset
   104
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30906
diff changeset
   105
    public static final int USE_ALL_BEANINFO           = 1;
19213
c360667a0da2 8022406: Fix doclint issues in java.beans
darcy
parents: 18757
diff changeset
   106
    /**
c360667a0da2 8022406: Fix doclint issues in java.beans
darcy
parents: 18757
diff changeset
   107
     * Flag to indicate to ignore immediate beaninfo.
25130
adfaa02ea516 8044855: Add missing @since tag under java.beans.*
henryjen
parents: 25123
diff changeset
   108
     * @since 1.2
19213
c360667a0da2 8022406: Fix doclint issues in java.beans
darcy
parents: 18757
diff changeset
   109
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30906
diff changeset
   110
    public static final int IGNORE_IMMEDIATE_BEANINFO  = 2;
19213
c360667a0da2 8022406: Fix doclint issues in java.beans
darcy
parents: 18757
diff changeset
   111
    /**
c360667a0da2 8022406: Fix doclint issues in java.beans
darcy
parents: 18757
diff changeset
   112
     * Flag to indicate to ignore all beaninfo.
25130
adfaa02ea516 8044855: Add missing @since tag under java.beans.*
henryjen
parents: 25123
diff changeset
   113
     * @since 1.2
19213
c360667a0da2 8022406: Fix doclint issues in java.beans
darcy
parents: 18757
diff changeset
   114
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30906
diff changeset
   115
    public static final int IGNORE_ALL_BEANINFO        = 3;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    // Static Caches to speed up introspection.
11086
09b1d6383d0b 7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents: 9035
diff changeset
   118
    private static final WeakCache<Class<?>, Method[]> declaredMethodCache = new WeakCache<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   120
    private Class<?> beanClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private BeanInfo explicitBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private BeanInfo superBeanInfo;
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   123
    private BeanInfo[] additionalBeanInfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private boolean propertyChangeSource = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    // These should be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private String defaultEventName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private String defaultPropertyName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private int defaultEventIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private int defaultPropertyIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   133
    // Methods maps from Method names to MethodDescriptors
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   134
    private Map<String, MethodDescriptor> methods;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    // properties maps from String names to PropertyDescriptors
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   137
    private Map<String, PropertyDescriptor> properties;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    // events maps from String names to EventSetDescriptors
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   140
    private Map<String, EventSetDescriptor> events;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30906
diff changeset
   142
    private static final EventSetDescriptor[] EMPTY_EVENTSETDESCRIPTORS = new EventSetDescriptor[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    static final String ADD_PREFIX = "add";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    static final String REMOVE_PREFIX = "remove";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    static final String GET_PREFIX = "get";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    static final String SET_PREFIX = "set";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    static final String IS_PREFIX = "is";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
23581
0ca496340112 8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents: 23308
diff changeset
   150
    // register with SharedSecrets for JMX usage
0ca496340112 8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents: 23308
diff changeset
   151
    static {
30906
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   152
        SharedSecrets.setJavaBeansAccess(new JavaBeansAccess() {
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   153
            @Override
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   154
            public Method getReadMethod(Class<?> clazz, String property) throws Exception {
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   155
                BeanInfo bi = Introspector.getBeanInfo(clazz);
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   156
                PropertyDescriptor[] pds = bi.getPropertyDescriptors();
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   157
                for (PropertyDescriptor pd: pds) {
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   158
                    if (pd.getName().equals(property)) {
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   159
                        return pd.getReadMethod();
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   160
                    }
23581
0ca496340112 8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents: 23308
diff changeset
   161
                }
30906
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   162
                return null;
23581
0ca496340112 8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents: 23308
diff changeset
   163
            }
30906
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   164
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   165
            @Override
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   166
            public String[] getConstructorPropertiesValue(Constructor<?> ctr) {
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   167
                ConstructorProperties cp = ctr.getAnnotation(ConstructorProperties.class);
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   168
                String [] ret = cp != null ? cp.value() : null;
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   169
                return ret;
1b67cbb0adce 8080663: Use sun.misc.SharedSecrets to allow access from java.management to @ConstructorProperties
jbachorik
parents: 25859
diff changeset
   170
            }
23581
0ca496340112 8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents: 23308
diff changeset
   171
        });
0ca496340112 8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents: 23308
diff changeset
   172
    }
0ca496340112 8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents: 23308
diff changeset
   173
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    //======================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    //                          Public methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    //======================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Introspect on a Java Bean and learn about all its properties, exposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * methods, and events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * If the BeanInfo class for a Java Bean has been previously Introspected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * then the BeanInfo class is retrieved from the BeanInfo cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @param beanClass  The bean class to be analyzed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @return  A BeanInfo object describing the target bean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @exception IntrospectionException if an exception occurs during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *              introspection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @see #flushCaches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @see #flushFromCaches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public static BeanInfo getBeanInfo(Class<?> beanClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        throws IntrospectionException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (!ReflectUtil.isPackageAccessible(beanClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
11086
09b1d6383d0b 7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents: 9035
diff changeset
   198
        ThreadGroupContext context = ThreadGroupContext.getContext();
5959
3ff758c11233 6963811: Deadlock-prone locking changes in Introspector
malenkov
parents: 5947
diff changeset
   199
        BeanInfo beanInfo;
11086
09b1d6383d0b 7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents: 9035
diff changeset
   200
        synchronized (declaredMethodCache) {
09b1d6383d0b 7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents: 9035
diff changeset
   201
            beanInfo = context.getBeanInfo(beanClass);
5959
3ff758c11233 6963811: Deadlock-prone locking changes in Introspector
malenkov
parents: 5947
diff changeset
   202
        }
3ff758c11233 6963811: Deadlock-prone locking changes in Introspector
malenkov
parents: 5947
diff changeset
   203
        if (beanInfo == null) {
3ff758c11233 6963811: Deadlock-prone locking changes in Introspector
malenkov
parents: 5947
diff changeset
   204
            beanInfo = new Introspector(beanClass, null, USE_ALL_BEANINFO).getBeanInfo();
11086
09b1d6383d0b 7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents: 9035
diff changeset
   205
            synchronized (declaredMethodCache) {
09b1d6383d0b 7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents: 9035
diff changeset
   206
                context.putBeanInfo(beanClass, beanInfo);
4382
c0759b1ccb56 5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents: 3476
diff changeset
   207
            }
3438
8bd2d2eeac83 6660539: Introspector shares cache of mutable BeanInfo between AppContexts.
malenkov
parents: 2
diff changeset
   208
        }
5959
3ff758c11233 6963811: Deadlock-prone locking changes in Introspector
malenkov
parents: 5947
diff changeset
   209
        return beanInfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Introspect on a Java bean and learn about all its properties, exposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * methods, and events, subject to some control flags.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * If the BeanInfo class for a Java Bean has been previously Introspected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * based on the same arguments then the BeanInfo class is retrieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * from the BeanInfo cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param beanClass  The bean class to be analyzed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @param flags  Flags to control the introspection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *     If flags == USE_ALL_BEANINFO then we use all of the BeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *          classes we can discover.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *     If flags == IGNORE_IMMEDIATE_BEANINFO then we ignore any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *           BeanInfo associated with the specified beanClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *     If flags == IGNORE_ALL_BEANINFO then we ignore all BeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *           associated with the specified beanClass or any of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *           parent classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @return  A BeanInfo object describing the target bean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @exception IntrospectionException if an exception occurs during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *              introspection.
25130
adfaa02ea516 8044855: Add missing @since tag under java.beans.*
henryjen
parents: 25123
diff changeset
   232
     * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public static BeanInfo getBeanInfo(Class<?> beanClass, int flags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                                                throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return getBeanInfo(beanClass, null, flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Introspect on a Java bean and learn all about its properties, exposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * methods, below a given "stop" point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * If the BeanInfo class for a Java Bean has been previously Introspected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * based on the same arguments, then the BeanInfo class is retrieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * from the BeanInfo cache.
19213
c360667a0da2 8022406: Fix doclint issues in java.beans
darcy
parents: 18757
diff changeset
   246
     * @return the BeanInfo for the bean
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @param beanClass The bean class to be analyzed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @param stopClass The baseclass at which to stop the analysis.  Any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *    methods/properties/events in the stopClass or in its baseclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *    will be ignored in the analysis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @exception IntrospectionException if an exception occurs during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *              introspection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public static BeanInfo getBeanInfo(Class<?> beanClass, Class<?> stopClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                                throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return getBeanInfo(beanClass, stopClass, USE_ALL_BEANINFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Introspect on a Java Bean and learn about all its properties,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * exposed methods and events, below a given {@code stopClass} point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * subject to some control {@code flags}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *  <dt>USE_ALL_BEANINFO</dt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *  <dd>Any BeanInfo that can be discovered will be used.</dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *  <dt>IGNORE_IMMEDIATE_BEANINFO</dt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *  <dd>Any BeanInfo associated with the specified {@code beanClass} will be ignored.</dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *  <dt>IGNORE_ALL_BEANINFO</dt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *  <dd>Any BeanInfo associated with the specified {@code beanClass}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *      or any of its parent classes will be ignored.</dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Any methods/properties/events in the {@code stopClass}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * or in its parent classes will be ignored in the analysis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * If the BeanInfo class for a Java Bean has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * previously introspected based on the same arguments then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * the BeanInfo class is retrieved from the BeanInfo cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param beanClass  the bean class to be analyzed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param stopClass  the parent class at which to stop the analysis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @param flags      flags to control the introspection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @return a BeanInfo object describing the target bean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @exception IntrospectionException if an exception occurs during introspection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public static BeanInfo getBeanInfo(Class<?> beanClass, Class<?> stopClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                                        int flags) throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        BeanInfo bi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (stopClass == null && flags == USE_ALL_BEANINFO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            // Same parameters to take advantage of caching.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            bi = getBeanInfo(beanClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            bi = (new Introspector(beanClass, stopClass, flags)).getBeanInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return bi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // Old behaviour: Make an independent copy of the BeanInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        //return new GenericBeanInfo(bi);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Utility method to take a string and convert it to normal Java variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * name capitalization.  This normally means converting the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * character from upper case to lower case, but in the (unusual) special
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * case when there is more than one character and both the first and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * second characters are upper case, we leave it alone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * as "URL".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @param  name The string to be decapitalized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @return  The decapitalized version of the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public static String decapitalize(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (name == null || name.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                        Character.isUpperCase(name.charAt(0))){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   324
        char[] chars = name.toCharArray();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        chars[0] = Character.toLowerCase(chars[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return new String(chars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * Gets the list of package names that will be used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *          finding BeanInfo classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @return  The array of package names that will be searched in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *          order to find BeanInfo classes. The default value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *          for this array is implementation-dependent; e.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *          Sun implementation initially sets to {"sun.beans.infos"}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
3239
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents: 2
diff changeset
   339
    public static String[] getBeanInfoSearchPath() {
11086
09b1d6383d0b 7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents: 9035
diff changeset
   340
        return ThreadGroupContext.getContext().getBeanInfoFinder().getPackages();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * Change the list of package names that will be used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *          finding BeanInfo classes.  The behaviour of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *          this method is undefined if parameter path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *          is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32874
diff changeset
   349
     * <p>First, if there is a security manager, its {@code checkPropertiesAccess}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * method is called. This could result in a SecurityException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @param path  Array of package names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @exception  SecurityException  if a security manager exists and its
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32874
diff changeset
   354
     *             {@code checkPropertiesAccess} method doesn't allow setting
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *              of system properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @see SecurityManager#checkPropertiesAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
3239
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents: 2
diff changeset
   359
    public static void setBeanInfoSearchPath(String[] path) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            sm.checkPropertiesAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
11086
09b1d6383d0b 7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents: 9035
diff changeset
   364
        ThreadGroupContext.getContext().getBeanInfoFinder().setPackages(path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Flush all of the Introspector's internal caches.  This method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * not normally required.  It is normally only needed by advanced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * tools that update existing "Class" objects in-place and need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * to make the Introspector re-analyze existing Class objects.
25130
adfaa02ea516 8044855: Add missing @since tag under java.beans.*
henryjen
parents: 25123
diff changeset
   373
     *
adfaa02ea516 8044855: Add missing @since tag under java.beans.*
henryjen
parents: 25123
diff changeset
   374
     * @since 1.2
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
    public static void flushCaches() {
11086
09b1d6383d0b 7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents: 9035
diff changeset
   378
        synchronized (declaredMethodCache) {
09b1d6383d0b 7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents: 9035
diff changeset
   379
            ThreadGroupContext.getContext().clearBeanInfoCache();
4382
c0759b1ccb56 5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents: 3476
diff changeset
   380
            declaredMethodCache.clear();
3438
8bd2d2eeac83 6660539: Introspector shares cache of mutable BeanInfo between AppContexts.
malenkov
parents: 2
diff changeset
   381
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * Flush the Introspector's internal cached information for a given class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * This method is not normally required.  It is normally only needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * by advanced tools that update existing "Class" objects in-place
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * and need to make the Introspector re-analyze an existing Class object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Note that only the direct state associated with the target Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * object is flushed.  We do not flush state for other Class objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * with the same name, nor do we flush state for any related Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * objects (such as subclasses), even though their state may include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * information indirectly obtained from the target Class object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @param clz  Class object to be flushed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @throws NullPointerException If the Class object is null.
25130
adfaa02ea516 8044855: Add missing @since tag under java.beans.*
henryjen
parents: 25123
diff changeset
   398
     * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    public static void flushFromCaches(Class<?> clz) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (clz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
11086
09b1d6383d0b 7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents: 9035
diff changeset
   404
        synchronized (declaredMethodCache) {
09b1d6383d0b 7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents: 9035
diff changeset
   405
            ThreadGroupContext.getContext().removeBeanInfo(clz);
4382
c0759b1ccb56 5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents: 3476
diff changeset
   406
            declaredMethodCache.put(clz, null);
3438
8bd2d2eeac83 6660539: Introspector shares cache of mutable BeanInfo between AppContexts.
malenkov
parents: 2
diff changeset
   407
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    //======================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    //                  Private implementation methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    //======================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   414
    private Introspector(Class<?> beanClass, Class<?> stopClass, int flags)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                                            throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        this.beanClass = beanClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        // Check stopClass is a superClass of startClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        if (stopClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            boolean isSuper = false;
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   421
            for (Class<?> c = beanClass.getSuperclass(); c != null; c = c.getSuperclass()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                if (c == stopClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    isSuper = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            if (!isSuper) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                throw new IntrospectionException(stopClass.getName() + " not superclass of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                                        beanClass.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        if (flags == USE_ALL_BEANINFO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            explicitBeanInfo = findExplicitBeanInfo(beanClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   436
        Class<?> superClass = beanClass.getSuperclass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        if (superClass != stopClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            int newFlags = flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            if (newFlags == IGNORE_IMMEDIATE_BEANINFO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                newFlags = USE_ALL_BEANINFO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            superBeanInfo = getBeanInfo(superClass, stopClass, newFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        if (explicitBeanInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            additionalBeanInfo = explicitBeanInfo.getAdditionalBeanInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        if (additionalBeanInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            additionalBeanInfo = new BeanInfo[0];
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * Constructs a GenericBeanInfo class from the state of the Introspector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    private BeanInfo getBeanInfo() throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        // the evaluation order here is import, as we evaluate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        // event sets and locate PropertyChangeListeners before we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        // look for properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        BeanDescriptor bd = getTargetBeanDescriptor();
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   461
        MethodDescriptor[] mds = getTargetMethodInfo();
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   462
        EventSetDescriptor[] esds = getTargetEventInfo();
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   463
        PropertyDescriptor[] pds = getTargetPropertyInfo();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        int defaultEvent = getTargetDefaultEventIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        int defaultProperty = getTargetDefaultPropertyIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        return new GenericBeanInfo(bd, esds, defaultEvent, pds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                        defaultProperty, mds, explicitBeanInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * Looks for an explicit BeanInfo class that corresponds to the Class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * First it looks in the existing package that the Class is defined in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * then it checks to see if the class is its own BeanInfo. Finally,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * the BeanInfo search path is prepended to the class and searched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *
3239
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents: 2
diff changeset
   479
     * @param beanClass  the class type of the bean
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @return Instance of an explicit BeanInfo class or null if one isn't found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   482
    private static BeanInfo findExplicitBeanInfo(Class<?> beanClass) {
11086
09b1d6383d0b 7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents: 9035
diff changeset
   483
        return ThreadGroupContext.getContext().getBeanInfoFinder().find(beanClass);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @return An array of PropertyDescriptors describing the editable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * properties supported by the target bean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    private PropertyDescriptor[] getTargetPropertyInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        // Check if the bean has its own BeanInfo that will provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        // explicit information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        PropertyDescriptor[] explicitProperties = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        if (explicitBeanInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            explicitProperties = getPropertyDescriptors(this.explicitBeanInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        if (explicitProperties == null && superBeanInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            // We have no explicit BeanInfo properties.  Check with our parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            addPropertyDescriptors(getPropertyDescriptors(this.superBeanInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        for (int i = 0; i < additionalBeanInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            addPropertyDescriptors(additionalBeanInfo[i].getPropertyDescriptors());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        if (explicitProperties != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            // Add the explicit BeanInfo data to our results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            addPropertyDescriptors(explicitProperties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            // Apply some reflection to the current class.
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   515
            for (Map.Entry<String,PropertyInfo> entry : ClassInfo.get(this.beanClass).getProperties().entrySet()) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   516
                addPropertyDescriptor(null != entry.getValue().getIndexed()
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   517
                        ? new IndexedPropertyDescriptor(entry, this.propertyChangeSource)
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   518
                        : new PropertyDescriptor(entry, this.propertyChangeSource));
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   519
            }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   520
            JavaBean annotation = this.beanClass.getAnnotation(JavaBean.class);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   521
            if ((annotation != null) && !annotation.defaultProperty().isEmpty()) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   522
                this.defaultPropertyName = annotation.defaultProperty();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        processPropertyDescriptors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        // Allocate and populate the result array.
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   528
        PropertyDescriptor[] result =
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   529
                properties.values().toArray(new PropertyDescriptor[properties.size()]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        // Set the default index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        if (defaultPropertyName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            for (int i = 0; i < result.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                if (defaultPropertyName.equals(result[i].getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    defaultPropertyIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   542
    private HashMap<String, List<PropertyDescriptor>> pdStore = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * Adds the property descriptor to the list store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    private void addPropertyDescriptor(PropertyDescriptor pd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        String propName = pd.getName();
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   549
        List<PropertyDescriptor> list = pdStore.get(propName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        if (list == null) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   551
            list = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            pdStore.put(propName, list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        if (this.beanClass != pd.getClass0()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            // replace existing property descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            // only if we have types to resolve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            // in the context of this.beanClass
13773
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   558
            Method read = pd.getReadMethod();
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   559
            Method write = pd.getWriteMethod();
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   560
            boolean cls = true;
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   561
            if (read != null) cls = cls && read.getGenericReturnType() instanceof Class;
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   562
            if (write != null) cls = cls && write.getGenericParameterTypes()[0] instanceof Class;
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   563
            if (pd instanceof IndexedPropertyDescriptor) {
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   564
                IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   565
                Method readI = ipd.getIndexedReadMethod();
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   566
                Method writeI = ipd.getIndexedWriteMethod();
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   567
                if (readI != null) cls = cls && readI.getGenericReturnType() instanceof Class;
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   568
                if (writeI != null) cls = cls && writeI.getGenericParameterTypes()[1] instanceof Class;
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   569
                if (!cls) {
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   570
                    pd = new IndexedPropertyDescriptor(ipd);
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   571
                    pd.updateGenericsFor(this.beanClass);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                }
13773
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   573
            }
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   574
            else if (!cls) {
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   575
                pd = new PropertyDescriptor(pd);
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13654
diff changeset
   576
                pd.updateGenericsFor(this.beanClass);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        list.add(pd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    private void addPropertyDescriptors(PropertyDescriptor[] descriptors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        if (descriptors != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            for (PropertyDescriptor descriptor : descriptors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                addPropertyDescriptor(descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    private PropertyDescriptor[] getPropertyDescriptors(BeanInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        int index = info.getDefaultPropertyIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        if ((0 <= index) && (index < descriptors.length)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            this.defaultPropertyName = descriptors[index].getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        return descriptors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * Populates the property descriptor table by merging the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * lists of Property descriptors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    private void processPropertyDescriptors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        if (properties == null) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   605
            properties = new TreeMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   608
        List<PropertyDescriptor> list;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        PropertyDescriptor pd, gpd, spd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        IndexedPropertyDescriptor ipd, igpd, ispd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   613
        Iterator<List<PropertyDescriptor>> it = pdStore.values().iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        while (it.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            pd = null; gpd = null; spd = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            ipd = null; igpd = null; ispd = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   618
            list = it.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            // First pass. Find the latest getter method. Merge properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            // of previous getter methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            for (int i = 0; i < list.size(); i++) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   623
                pd = list.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                if (pd instanceof IndexedPropertyDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                    ipd = (IndexedPropertyDescriptor)pd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                    if (ipd.getIndexedReadMethod() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                        if (igpd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                            igpd = new IndexedPropertyDescriptor(igpd, ipd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                            igpd = ipd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                    if (pd.getReadMethod() != null) {
18757
5ab9e48648e5 6707231: Wrong read Method returned for boolen properties
malenkov
parents: 16837
diff changeset
   635
                        String pdName = pd.getReadMethod().getName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                        if (gpd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                            // Don't replace the existing read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                            // method if it starts with "is"
18757
5ab9e48648e5 6707231: Wrong read Method returned for boolen properties
malenkov
parents: 16837
diff changeset
   639
                            String gpdName = gpd.getReadMethod().getName();
5ab9e48648e5 6707231: Wrong read Method returned for boolen properties
malenkov
parents: 16837
diff changeset
   640
                            if (gpdName.equals(pdName) || !gpdName.startsWith(IS_PREFIX)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                                gpd = new PropertyDescriptor(gpd, pd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                            gpd = pd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            // Second pass. Find the latest setter method which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            // has the same type as the getter method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            for (int i = 0; i < list.size(); i++) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   653
                pd = list.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                if (pd instanceof IndexedPropertyDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                    ipd = (IndexedPropertyDescriptor)pd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                    if (ipd.getIndexedWriteMethod() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                        if (igpd != null) {
21593
4284575a978e 8027648: Type of overridden property is resolved incorrectly
malenkov
parents: 20455
diff changeset
   658
                            if (isAssignable(igpd.getIndexedPropertyType(), ipd.getIndexedPropertyType())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                                if (ispd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                                    ispd = new IndexedPropertyDescriptor(ispd, ipd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                                    ispd = ipd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                            if (ispd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                                ispd = new IndexedPropertyDescriptor(ispd, ipd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                                ispd = ipd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                    if (pd.getWriteMethod() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                        if (gpd != null) {
21593
4284575a978e 8027648: Type of overridden property is resolved incorrectly
malenkov
parents: 20455
diff changeset
   676
                            if (isAssignable(gpd.getPropertyType(), pd.getPropertyType())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                                if (spd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                                    spd = new PropertyDescriptor(spd, pd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                                    spd = pd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                            if (spd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                                spd = new PropertyDescriptor(spd, pd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                                spd = pd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            // At this stage we should have either PDs or IPDs for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            // representative getters and setters. The order at which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            // property descriptors are determined represent the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            // precedence of the property ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            pd = null; ipd = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            if (igpd != null && ispd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                // Complete indexed properties set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                // Merge any classic property descriptors
23308
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   703
                if ((gpd == spd) || (gpd == null)) {
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   704
                    pd = spd;
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   705
                } else if (spd == null) {
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   706
                    pd = gpd;
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   707
                } else if (spd instanceof IndexedPropertyDescriptor) {
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   708
                    pd = mergePropertyWithIndexedProperty(gpd, (IndexedPropertyDescriptor) spd);
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   709
                } else if (gpd instanceof IndexedPropertyDescriptor) {
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   710
                    pd = mergePropertyWithIndexedProperty(spd, (IndexedPropertyDescriptor) gpd);
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   711
                } else {
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   712
                    pd = mergePropertyDescriptor(gpd, spd);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                if (igpd == ispd) {
23308
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   715
                    ipd = igpd;
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   716
                } else {
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   717
                    ipd = mergePropertyDescriptor(igpd, ispd);
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   718
                }
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   719
                if (pd == null) {
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   720
                    pd = ipd;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                } else {
23308
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   722
                    Class<?> propType = pd.getPropertyType();
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   723
                    Class<?> ipropType = ipd.getIndexedPropertyType();
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   724
                    if (propType.isArray() && propType.getComponentType() == ipropType) {
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   725
                        pd = pd.getClass0().isAssignableFrom(ipd.getClass0())
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   726
                                ? new IndexedPropertyDescriptor(pd, ipd)
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   727
                                : new IndexedPropertyDescriptor(ipd, pd);
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   728
                    } else if (pd.getClass0().isAssignableFrom(ipd.getClass0())) {
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   729
                        pd = pd.getClass0().isAssignableFrom(ipd.getClass0())
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   730
                                ? new PropertyDescriptor(pd, ipd)
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   731
                                : new PropertyDescriptor(ipd, pd);
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   732
                    } else {
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   733
                        pd = ipd;
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   734
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            } else if (gpd != null && spd != null) {
23296
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   737
                if (igpd != null) {
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   738
                    gpd = mergePropertyWithIndexedProperty(gpd, igpd);
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   739
                }
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   740
                if (ispd != null) {
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   741
                    spd = mergePropertyWithIndexedProperty(spd, ispd);
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   742
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                // Complete simple properties set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                if (gpd == spd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                    pd = gpd;
23296
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   746
                } else if (spd instanceof IndexedPropertyDescriptor) {
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   747
                    pd = mergePropertyWithIndexedProperty(gpd, (IndexedPropertyDescriptor) spd);
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   748
                } else if (gpd instanceof IndexedPropertyDescriptor) {
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   749
                    pd = mergePropertyWithIndexedProperty(spd, (IndexedPropertyDescriptor) gpd);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                    pd = mergePropertyDescriptor(gpd, spd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            } else if (ispd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                // indexed setter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                pd = ispd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                // Merge any classic property descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                if (spd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                    pd = mergePropertyDescriptor(ispd, spd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                if (gpd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                    pd = mergePropertyDescriptor(ispd, gpd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            } else if (igpd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                // indexed getter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                pd = igpd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                // Merge any classic property descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                if (gpd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                    pd = mergePropertyDescriptor(igpd, gpd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                if (spd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                    pd = mergePropertyDescriptor(igpd, spd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            } else if (spd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                // simple setter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                pd = spd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            } else if (gpd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                // simple getter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                pd = gpd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            // Very special case to ensure that an IndexedPropertyDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            // doesn't contain less information than the enclosed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            // PropertyDescriptor. If it does, then recreate as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            // PropertyDescriptor. See 4168833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            if (pd instanceof IndexedPropertyDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                ipd = (IndexedPropertyDescriptor)pd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                if (ipd.getIndexedReadMethod() == null && ipd.getIndexedWriteMethod() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                    pd = new PropertyDescriptor(ipd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            // Find the first property descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            // which does not have getter and setter methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            // See regression bug 4984912.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            if ( (pd == null) && (list.size() > 0) ) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   796
                pd = list.get(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            if (pd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                properties.put(pd.getName(), pd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
21593
4284575a978e 8027648: Type of overridden property is resolved incorrectly
malenkov
parents: 20455
diff changeset
   805
    private static boolean isAssignable(Class<?> current, Class<?> candidate) {
24177
cbbea768ae65 8039776: Introspector throws NullPointerException for subclasses' mismatched get/setter
malenkov
parents: 23581
diff changeset
   806
        return ((current == null) || (candidate == null)) ? current == candidate : current.isAssignableFrom(candidate);
21593
4284575a978e 8027648: Type of overridden property is resolved incorrectly
malenkov
parents: 20455
diff changeset
   807
    }
4284575a978e 8027648: Type of overridden property is resolved incorrectly
malenkov
parents: 20455
diff changeset
   808
23296
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   809
    private PropertyDescriptor mergePropertyWithIndexedProperty(PropertyDescriptor pd, IndexedPropertyDescriptor ipd) {
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   810
        Class<?> type = pd.getPropertyType();
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   811
        if (type.isArray() && (type.getComponentType() == ipd.getIndexedPropertyType())) {
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   812
            return pd.getClass0().isAssignableFrom(ipd.getClass0())
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   813
                    ? new IndexedPropertyDescriptor(pd, ipd)
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   814
                    : new IndexedPropertyDescriptor(ipd, pd);
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   815
        }
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   816
        return pd;
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   817
    }
0acf698eee6a 8034164: Introspector ignores indexed part of the property sometimes
malenkov
parents: 21593
diff changeset
   818
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * Adds the property descriptor to the indexedproperty descriptor only if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * types are the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * The most specific property descriptor will take precedence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    private PropertyDescriptor mergePropertyDescriptor(IndexedPropertyDescriptor ipd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                                                       PropertyDescriptor pd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        PropertyDescriptor result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   829
        Class<?> propType = pd.getPropertyType();
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   830
        Class<?> ipropType = ipd.getIndexedPropertyType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        if (propType.isArray() && propType.getComponentType() == ipropType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            if (pd.getClass0().isAssignableFrom(ipd.getClass0())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                result = new IndexedPropertyDescriptor(pd, ipd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                result = new IndexedPropertyDescriptor(ipd, pd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            }
23308
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   838
        } else if ((ipd.getReadMethod() == null) && (ipd.getWriteMethod() == null)) {
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   839
            if (pd.getClass0().isAssignableFrom(ipd.getClass0())) {
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   840
                result = new PropertyDescriptor(pd, ipd);
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   841
            } else {
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   842
                result = new PropertyDescriptor(ipd, pd);
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   843
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            // Cannot merge the pd because of type mismatch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            // Return the most specific pd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            if (pd.getClass0().isAssignableFrom(ipd.getClass0())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                result = ipd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                result = pd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                // Try to add methods which may have been lost in the type change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                // See 4168833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                Method write = result.getWriteMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                Method read = result.getReadMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                if (read == null && write != null) {
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
   857
                    read = findMethod(result.getClass0(),
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
   858
                                      GET_PREFIX + NameGenerator.capitalize(result.getName()), 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                    if (read != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                            result.setReadMethod(read);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                        } catch (IntrospectionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                            // no consequences for failure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                if (write == null && read != null) {
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
   868
                    write = findMethod(result.getClass0(),
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
   869
                                       SET_PREFIX + NameGenerator.capitalize(result.getName()), 1,
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   870
                                       new Class<?>[] { FeatureDescriptor.getReturnType(result.getClass0(), read) });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                    if (write != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                            result.setWriteMethod(write);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                        } catch (IntrospectionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                            // no consequences for failure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    // Handle regular pd merge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    private PropertyDescriptor mergePropertyDescriptor(PropertyDescriptor pd1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                                                       PropertyDescriptor pd2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        if (pd1.getClass0().isAssignableFrom(pd2.getClass0())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            return new PropertyDescriptor(pd1, pd2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            return new PropertyDescriptor(pd2, pd1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    // Handle regular ipd merge
23308
ce9d5a78334f 8034085: Do not prefer indexed properties
malenkov
parents: 23296
diff changeset
   895
    private IndexedPropertyDescriptor mergePropertyDescriptor(IndexedPropertyDescriptor ipd1,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                                                       IndexedPropertyDescriptor ipd2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        if (ipd1.getClass0().isAssignableFrom(ipd2.getClass0())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            return new IndexedPropertyDescriptor(ipd1, ipd2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            return new IndexedPropertyDescriptor(ipd2, ipd1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * @return An array of EventSetDescriptors describing the kinds of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * events fired by the target bean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    private EventSetDescriptor[] getTargetEventInfo() throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        if (events == null) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   910
            events = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        // Check if the bean has its own BeanInfo that will provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        // explicit information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        EventSetDescriptor[] explicitEvents = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        if (explicitBeanInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            explicitEvents = explicitBeanInfo.getEventSetDescriptors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            int ix = explicitBeanInfo.getDefaultEventIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            if (ix >= 0 && ix < explicitEvents.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                defaultEventName = explicitEvents[ix].getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        if (explicitEvents == null && superBeanInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            // We have no explicit BeanInfo events.  Check with our parent.
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   926
            EventSetDescriptor[] supers = superBeanInfo.getEventSetDescriptors();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            for (int i = 0 ; i < supers.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                addEvent(supers[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            int ix = superBeanInfo.getDefaultEventIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            if (ix >= 0 && ix < supers.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                defaultEventName = supers[ix].getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        for (int i = 0; i < additionalBeanInfo.length; i++) {
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   937
            EventSetDescriptor[] additional = additionalBeanInfo[i].getEventSetDescriptors();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            if (additional != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                for (int j = 0 ; j < additional.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                    addEvent(additional[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        if (explicitEvents != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            // Add the explicit explicitBeanInfo data to our results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            for (int i = 0 ; i < explicitEvents.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                addEvent(explicitEvents[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            // Apply some reflection to the current class.
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   953
            for (Map.Entry<String,EventSetInfo> entry : ClassInfo.get(this.beanClass).getEventSets().entrySet()) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   954
                    // generate a list of Method objects for each of the target methods:
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   955
                List<Method> methods = new ArrayList<>();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   956
                for (Method method : ClassInfo.get(entry.getValue().getListenerType()).getMethods()) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   957
                    if (isEventHandler(method)) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   958
                        methods.add(method);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                }
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   961
                addEvent(new EventSetDescriptor(
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   962
                        entry.getKey(),
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   963
                        entry.getValue(),
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   964
                        methods.toArray(new Method[methods.size()])));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            }
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   966
            JavaBean annotation = this.beanClass.getAnnotation(JavaBean.class);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   967
            if ((annotation != null) && !annotation.defaultEventSet().isEmpty()) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   968
                this.defaultEventName = annotation.defaultEventSet();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
   969
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        EventSetDescriptor[] result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        if (events.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            result = EMPTY_EVENTSETDESCRIPTORS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            // Allocate and populate the result array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            result = new EventSetDescriptor[events.size()];
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   977
            result = events.values().toArray(result);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            // Set the default index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            if (defaultEventName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                for (int i = 0; i < result.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                    if (defaultEventName.equals(result[i].getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                        defaultEventIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    private void addEvent(EventSetDescriptor esd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        String key = esd.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        if (esd.getName().equals("propertyChange")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            propertyChangeSource = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        }
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
   995
        EventSetDescriptor old = events.get(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        if (old == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            events.put(key, esd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        EventSetDescriptor composite = new EventSetDescriptor(old, esd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        events.put(key, composite);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * @return An array of MethodDescriptors describing the private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * methods supported by the target bean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    private MethodDescriptor[] getTargetMethodInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        if (methods == null) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
  1010
            methods = new HashMap<>(100);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        // Check if the bean has its own BeanInfo that will provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        // explicit information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        MethodDescriptor[] explicitMethods = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        if (explicitBeanInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            explicitMethods = explicitBeanInfo.getMethodDescriptors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        if (explicitMethods == null && superBeanInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            // We have no explicit BeanInfo methods.  Check with our parent.
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
  1022
            MethodDescriptor[] supers = superBeanInfo.getMethodDescriptors();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            for (int i = 0 ; i < supers.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                addMethod(supers[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        for (int i = 0; i < additionalBeanInfo.length; i++) {
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
  1029
            MethodDescriptor[] additional = additionalBeanInfo[i].getMethodDescriptors();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            if (additional != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                for (int j = 0 ; j < additional.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                    addMethod(additional[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        if (explicitMethods != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            // Add the explicit explicitBeanInfo data to our results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            for (int i = 0 ; i < explicitMethods.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                addMethod(explicitMethods[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            // Apply some reflection to the current class.
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
  1045
            for (Method method : ClassInfo.get(this.beanClass).getMethods()) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
  1046
                addMethod(new MethodDescriptor(method));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        // Allocate and populate the result array.
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
  1051
        MethodDescriptor[] result = new MethodDescriptor[methods.size()];
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
  1052
        result = methods.values().toArray(result);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    private void addMethod(MethodDescriptor md) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        // We have to be careful here to distinguish method by both name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        // and argument lists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        // This method gets called a *lot, so we try to be efficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        String name = md.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
  1063
        MethodDescriptor old = methods.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        if (old == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            // This is the common case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            methods.put(name, md);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        // We have a collision on method names.  This is rare.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        // Check if old and md have the same type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        String[] p1 = md.getParamNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        String[] p2 = old.getParamNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        boolean match = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        if (p1.length == p2.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            match = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            for (int i = 0; i < p1.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                if (p1[i] != p2[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                    match = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        if (match) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            MethodDescriptor composite = new MethodDescriptor(old, md);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            methods.put(name, composite);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        // We have a collision on method names with different type signatures.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        // This is very rare.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        String longKey = makeQualifiedMethodName(name, p1);
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
  1096
        old = methods.get(longKey);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        if (old == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            methods.put(longKey, md);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        MethodDescriptor composite = new MethodDescriptor(old, md);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        methods.put(longKey, composite);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * Creates a key for a method in a method cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    private static String makeQualifiedMethodName(String name, String[] params) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 24177
diff changeset
  1109
        StringBuilder sb = new StringBuilder(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        sb.append('=');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        for (int i = 0; i < params.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            sb.append(':');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            sb.append(params[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    private int getTargetDefaultEventIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        return defaultEventIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    private int getTargetDefaultPropertyIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        return defaultPropertyIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    private BeanDescriptor getTargetBeanDescriptor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        // Use explicit info, if available,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        if (explicitBeanInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            BeanDescriptor bd = explicitBeanInfo.getBeanDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            if (bd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                return (bd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        // OK, fabricate a default BeanDescriptor.
7249
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1135
        return new BeanDescriptor(this.beanClass, findCustomizerClass(this.beanClass));
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1136
    }
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1137
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1138
    private static Class<?> findCustomizerClass(Class<?> type) {
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1139
        String name = type.getName() + "Customizer";
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1140
        try {
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1141
            type = ClassFinder.findClass(name, type.getClassLoader());
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1142
            // Each customizer should inherit java.awt.Component and implement java.beans.Customizer
8760
83843c0b84f7 7021517: java.beans code comments have issues with HTML4 compliance
malenkov
parents: 7249
diff changeset
  1143
            // according to the section 9.3 of JavaBeans&trade; specification
7249
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1144
            if (Component.class.isAssignableFrom(type) && Customizer.class.isAssignableFrom(type)) {
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1145
                return type;
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1146
            }
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1147
        }
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1148
        catch (Exception exception) {
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1149
            // ignore any exceptions
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1150
        }
34380acce3b6 6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents: 6657
diff changeset
  1151
        return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    private boolean isEventHandler(Method m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        // We assume that a method is an event handler if it has a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        // argument, whose type inherit from java.util.Event.
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
  1157
        Type[] argTypes = m.getGenericParameterTypes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        if (argTypes.length != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        }
13356
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
  1161
        return isSubclass(TypeResolver.erase(TypeResolver.resolveInClass(beanClass, argTypes[0])), EventObject.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    //======================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    // Package private support methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    //======================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1168
    /**
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1169
     * Internal support for finding a target methodName with a given
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1170
     * parameter list on a given class.
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1171
     */
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
  1172
    private static Method internalFindMethod(Class<?> start, String methodName,
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
  1173
                                                 int argCount, Class<?>[] args) {
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1174
        // For overriden methods we need to find the most derived version.
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1175
        // So we start with the given class and walk up the superclass chain.
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
  1176
        for (Class<?> cl = start; cl != null; cl = cl.getSuperclass()) {
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
  1177
            for (Method method : ClassInfo.get(cl).getMethods()) {
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1178
                // make sure method signature matches.
13356
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
  1179
                if (method.getName().equals(methodName)) {
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
  1180
                    Type[] params = method.getGenericParameterTypes();
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
  1181
                    if (params.length == argCount) {
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
  1182
                        if (args != null) {
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
  1183
                            boolean different = false;
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
  1184
                            if (argCount > 0) {
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
  1185
                                for (int j = 0; j < argCount; j++) {
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
  1186
                                    if (TypeResolver.erase(TypeResolver.resolveInClass(start, params[j])) != args[j]) {
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
  1187
                                        different = true;
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
  1188
                                        continue;
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
  1189
                                    }
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
  1190
                                }
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
  1191
                                if (different) {
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1192
                                    continue;
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1193
                                }
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1194
                            }
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1195
                        }
13356
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11668
diff changeset
  1196
                        return method;
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1197
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        }
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1201
        // Now check any inherited interfaces.  This is necessary both when
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1202
        // the argument class is itself an interface, and when the argument
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1203
        // class is an abstract class.
25123
1f70b30da563 8042860: Fix raw and unchecked warnings in java.beans
darcy
parents: 24177
diff changeset
  1204
        Class<?>[] ifcs = start.getInterfaces();
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1205
        for (int i = 0 ; i < ifcs.length; i++) {
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1206
            // Note: The original implementation had both methods calling
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1207
            // the 3 arg method. This is preserved but perhaps it should
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1208
            // pass the args array instead of null.
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
  1209
            Method method = internalFindMethod(ifcs[i], methodName, argCount, null);
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1210
            if (method != null) {
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
  1211
                return method;
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1212
            }
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1213
        }
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents: 25144
diff changeset
  1214
        return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1217
    /**
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1218
     * Find a target methodName on a given class.
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1219
     */
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
  1220
    static Method findMethod(Class<?> cls, String methodName, int argCount) {
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1221
        return findMethod(cls, methodName, argCount, null);
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1222
    }
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1223
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1224
    /**
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1225
     * Find a target methodName with specific parameter list on a given class.
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1226
     * <p>
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1227
     * Used in the contructors of the EventSetDescriptor,
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1228
     * PropertyDescriptor and the IndexedPropertyDescriptor.
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1229
     * <p>
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1230
     * @param cls The Class object on which to retrieve the method.
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1231
     * @param methodName Name of the method.
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1232
     * @param argCount Number of arguments for the desired method.
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1233
     * @param args Array of argument types for the method.
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1234
     * @return the method or null if not found
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1235
     */
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
  1236
    static Method findMethod(Class<?> cls, String methodName, int argCount,
25123
1f70b30da563 8042860: Fix raw and unchecked warnings in java.beans
darcy
parents: 24177
diff changeset
  1237
                             Class<?>[] args) {
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1238
        if (methodName == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        }
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5959
diff changeset
  1241
        return internalFindMethod(cls, methodName, argCount, args);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * Return true if class a is either equivalent to class b, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * if class a is a subclass of class b, i.e. if a either "extends"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     * or "implements" b.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     * Note tht either or both "Class" objects may represent interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     */
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
  1250
    static  boolean isSubclass(Class<?> a, Class<?> b) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        // We rely on the fact that for any given java class or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        // primtitive type there is a unqiue Class object, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        // we can use object equivalence in the comparisons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        if (a == b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        if (a == null || b == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        }
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
  1260
        for (Class<?> x = a; x != null; x = x.getSuperclass()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            if (x == b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            if (b.isInterface()) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
  1265
                Class<?>[] interfaces = x.getInterfaces();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                for (int i = 0; i < interfaces.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                    if (isSubclass(interfaces[i], b)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * Try to create an instance of a named class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * First try the classloader of "sibling", then try the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * classloader then the class loader of the current Thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     */
42218
35e0972b2533 8169887: javax/swing/JEditorPane/8080972/TestJEditor.java, javax/swing/text/View/8080972/TestObjectView.java are failing
prr
parents: 42208
diff changeset
  1281
    @SuppressWarnings("deprecation")
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
  1282
    static Object instantiate(Class<?> sibling, String className)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                 throws InstantiationException, IllegalAccessException,
42208
7c1017f0ade5 8155874: Fix java.desktop deprecation warnings about Class.newInstance
prr
parents: 35667
diff changeset
  1284
                        NoSuchMethodException, InvocationTargetException,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                                                ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        // First check with sibling's classloader (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        ClassLoader cl = sibling.getClassLoader();
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9035
diff changeset
  1288
        Class<?> cls = ClassFinder.findClass(className, cl);
42218
35e0972b2533 8169887: javax/swing/JEditorPane/8080972/TestJEditor.java, javax/swing/text/View/8080972/TestObjectView.java are failing
prr
parents: 42208
diff changeset
  1289
        return cls.newInstance();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
} // end class Introspector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
//===========================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
 * Package private implementation support class for Introspector's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
 * internal use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
 * Mostly this is used as a placeholder for the descriptors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
class GenericBeanInfo extends SimpleBeanInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    private BeanDescriptor beanDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    private EventSetDescriptor[] events;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    private int defaultEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    private PropertyDescriptor[] properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    private int defaultProperty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    private MethodDescriptor[] methods;
13654
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1311
    private Reference<BeanInfo> targetBeanInfoRef;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    public GenericBeanInfo(BeanDescriptor beanDescriptor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                EventSetDescriptor[] events, int defaultEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                PropertyDescriptor[] properties, int defaultProperty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                MethodDescriptor[] methods, BeanInfo targetBeanInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        this.beanDescriptor = beanDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        this.events = events;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        this.defaultEvent = defaultEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        this.properties = properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        this.defaultProperty = defaultProperty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        this.methods = methods;
13654
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1323
        this.targetBeanInfoRef = (targetBeanInfo != null)
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1324
                ? new SoftReference<>(targetBeanInfo)
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1325
                : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     * Package-private dup constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     * This must isolate the new object from any changes to the old object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
    GenericBeanInfo(GenericBeanInfo old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        beanDescriptor = new BeanDescriptor(old.beanDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        if (old.events != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            int len = old.events.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            events = new EventSetDescriptor[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                events[i] = new EventSetDescriptor(old.events[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        defaultEvent = old.defaultEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        if (old.properties != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            int len = old.properties.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            properties = new PropertyDescriptor[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
                PropertyDescriptor oldp = old.properties[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
                if (oldp instanceof IndexedPropertyDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
                    properties[i] = new IndexedPropertyDescriptor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
                                        (IndexedPropertyDescriptor) oldp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
                    properties[i] = new PropertyDescriptor(oldp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        defaultProperty = old.defaultProperty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        if (old.methods != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
            int len = old.methods.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
            methods = new MethodDescriptor[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                methods[i] = new MethodDescriptor(old.methods[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        }
4851
4f7de5eeeac7 6921057: REGRESSION: persistence delegate issue on Windows and Linux against 5.u23b03/6u17b11
malenkov
parents: 4393
diff changeset
  1364
        this.targetBeanInfoRef = old.targetBeanInfoRef;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    public PropertyDescriptor[] getPropertyDescriptors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        return properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
    public int getDefaultPropertyIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        return defaultProperty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
    public EventSetDescriptor[] getEventSetDescriptors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        return events;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
    public int getDefaultEventIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        return defaultEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    public MethodDescriptor[] getMethodDescriptors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        return methods;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    public BeanDescriptor getBeanDescriptor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        return beanDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
    public java.awt.Image getIcon(int iconKind) {
13654
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1392
        BeanInfo targetBeanInfo = getTargetBeanInfo();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        if (targetBeanInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
            return targetBeanInfo.getIcon(iconKind);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        return super.getIcon(iconKind);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
    }
13654
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1398
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1399
    private BeanInfo getTargetBeanInfo() {
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1400
        if (this.targetBeanInfoRef == null) {
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1401
            return null;
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1402
        }
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1403
        BeanInfo targetBeanInfo = this.targetBeanInfoRef.get();
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1404
        if (targetBeanInfo == null) {
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1405
            targetBeanInfo = ThreadGroupContext.getContext().getBeanInfoFinder()
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1406
                    .find(this.beanDescriptor.getBeanClass());
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1407
            if (targetBeanInfo != null) {
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1408
                this.targetBeanInfoRef = new SoftReference<>(targetBeanInfo);
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1409
            }
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1410
        }
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1411
        return targetBeanInfo;
9a35ae08fd2b 7195106: REGRESSION : There is no way to get Icon inf, once Softreference is released
malenkov
parents: 13356
diff changeset
  1412
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
}