jdk/src/share/classes/java/beans/IndexedPropertyDescriptor.java
author malenkov
Tue, 22 Jun 2010 12:06:33 +0400
changeset 5947 0e6f2837eeca
parent 5506 202f599c92aa
child 6657 15dbb366c6a3
permissions -rw-r--r--
6707234: Method returned by Introspector.internalFindMethod not necessarily most specific Reviewed-by: peterz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
     2
 * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.beans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.ref.Reference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * An IndexedPropertyDescriptor describes a property that acts like an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * array and has an indexed read and/or indexed write method to access
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * specific elements of the array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * An indexed property may also provide simple non-indexed read and write
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * methods.  If these are present, they read and write arrays of the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * returned by the indexed read method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class IndexedPropertyDescriptor extends PropertyDescriptor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private Reference<Class> indexedPropertyTypeRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private Reference<Method> indexedReadMethodRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private Reference<Method> indexedWriteMethodRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private String indexedReadMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private String indexedWriteMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * This constructor constructs an IndexedPropertyDescriptor for a property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * that follows the standard Java conventions by having getFoo and setFoo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * accessor methods, for both indexed access and array access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Thus if the argument name is "fred", it will assume that there
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * is an indexed reader method "getFred", a non-indexed (array) reader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * method also called "getFred", an indexed writer method "setFred",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * and finally a non-indexed writer method "setFred".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @param propertyName The programmatic name of the property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @param beanClass The Class object for the target bean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @exception IntrospectionException if an exception occurs during
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *              introspection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public IndexedPropertyDescriptor(String propertyName, Class<?> beanClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        this(propertyName, beanClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
             Introspector.GET_PREFIX + NameGenerator.capitalize(propertyName),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
             Introspector.SET_PREFIX + NameGenerator.capitalize(propertyName),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
             Introspector.GET_PREFIX + NameGenerator.capitalize(propertyName),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
             Introspector.SET_PREFIX + NameGenerator.capitalize(propertyName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * This constructor takes the name of a simple property, and method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * names for reading and writing the property, both indexed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * and non-indexed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param propertyName The programmatic name of the property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param beanClass  The Class object for the target bean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param readMethodName The name of the method used for reading the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *           values as an array.  May be null if the property is write-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *           or must be indexed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param writeMethodName The name of the method used for writing the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *           values as an array.  May be null if the property is read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *           or must be indexed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param indexedReadMethodName The name of the method used for reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *          an indexed property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *          May be null if the property is write-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param indexedWriteMethodName The name of the method used for writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *          an indexed property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *          May be null if the property is read-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @exception IntrospectionException if an exception occurs during
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *              introspection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public IndexedPropertyDescriptor(String propertyName, Class<?> beanClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                String readMethodName, String writeMethodName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                String indexedReadMethodName, String indexedWriteMethodName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        super(propertyName, beanClass, readMethodName, writeMethodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.indexedReadMethodName = indexedReadMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if (indexedReadMethodName != null && getIndexedReadMethod() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            throw new IntrospectionException("Method not found: " + indexedReadMethodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        this.indexedWriteMethodName = indexedWriteMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (indexedWriteMethodName != null && getIndexedWriteMethod() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            throw new IntrospectionException("Method not found: " + indexedWriteMethodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        // Implemented only for type checking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        findIndexedPropertyType(getIndexedReadMethod(), getIndexedWriteMethod());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * This constructor takes the name of a simple property, and Method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * objects for reading and writing the property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
4960
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   119
     * @param propertyName The programmatic name of the property.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param readMethod The method used for reading the property values as an array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *          May be null if the property is write-only or must be indexed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param writeMethod The method used for writing the property values as an array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *          May be null if the property is read-only or must be indexed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param indexedReadMethod The method used for reading an indexed property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *          May be null if the property is write-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @param indexedWriteMethod The method used for writing an indexed property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *          May be null if the property is read-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @exception IntrospectionException if an exception occurs during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *              introspection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public IndexedPropertyDescriptor(String propertyName, Method readMethod, Method writeMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                            Method indexedReadMethod, Method indexedWriteMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        super(propertyName, readMethod, writeMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        setIndexedReadMethod0(indexedReadMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        setIndexedWriteMethod0(indexedWriteMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        // Type checking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        setIndexedPropertyType(findIndexedPropertyType(indexedReadMethod, indexedWriteMethod));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Creates <code>PropertyDescriptor</code> for the specified bean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * with the specified name and methods to read/write the property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @param bean          the type of the target bean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param base          the base name of the property (the rest of the method name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param read          the method used for reading the property value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @param write         the method used for writing the property value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @param readIndexed   the method used for reading an indexed property value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param writeIndexed  the method used for writing an indexed property value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @exception IntrospectionException if an exception occurs during introspection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    IndexedPropertyDescriptor(Class<?> bean, String base, Method read, Method write, Method readIndexed, Method writeIndexed) throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        super(bean, base, read, write);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        setIndexedReadMethod0(readIndexed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        setIndexedWriteMethod0(writeIndexed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        // Type checking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        setIndexedPropertyType(findIndexedPropertyType(readIndexed, writeIndexed));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Gets the method that should be used to read an indexed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @return The method that should be used to read an indexed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * May return null if the property isn't indexed or is write-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public synchronized Method getIndexedReadMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        Method indexedReadMethod = getIndexedReadMethod0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (indexedReadMethod == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            Class cls = getClass0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            if (cls == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                (indexedReadMethodName == null && indexedReadMethodRef == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                // the Indexed readMethod was explicitly set to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (indexedReadMethodName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                Class type = getIndexedPropertyType0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                if (type == boolean.class || type == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    indexedReadMethodName = Introspector.IS_PREFIX + getBaseName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    indexedReadMethodName = Introspector.GET_PREFIX + getBaseName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
5947
0e6f2837eeca 6707234: Method returned by Introspector.internalFindMethod not necessarily most specific
malenkov
parents: 5506
diff changeset
   192
            indexedReadMethod = Introspector.findInstanceMethod(cls, indexedReadMethodName, int.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            if (indexedReadMethod == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                // no "is" method, so look for a "get" method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                indexedReadMethodName = Introspector.GET_PREFIX + getBaseName();
5947
0e6f2837eeca 6707234: Method returned by Introspector.internalFindMethod not necessarily most specific
malenkov
parents: 5506
diff changeset
   196
                indexedReadMethod = Introspector.findInstanceMethod(cls, indexedReadMethodName, int.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            setIndexedReadMethod0(indexedReadMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return indexedReadMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Sets the method that should be used to read an indexed property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @param readMethod The new indexed read method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public synchronized void setIndexedReadMethod(Method readMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        // the indexed property type is set by the reader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        setIndexedPropertyType(findIndexedPropertyType(readMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                                                       getIndexedWriteMethod0()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        setIndexedReadMethod0(readMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    private void setIndexedReadMethod0(Method readMethod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (readMethod == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            indexedReadMethodName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            indexedReadMethodRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        setClass0(readMethod.getDeclaringClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        indexedReadMethodName = readMethod.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        this.indexedReadMethodRef = getSoftReference(readMethod);
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   227
        setTransient(readMethod.getAnnotation(Transient.class));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Gets the method that should be used to write an indexed property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @return The method that should be used to write an indexed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * May return null if the property isn't indexed or is read-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public synchronized Method getIndexedWriteMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        Method indexedWriteMethod = getIndexedWriteMethod0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (indexedWriteMethod == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            Class cls = getClass0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            if (cls == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                (indexedWriteMethodName == null && indexedWriteMethodRef == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                // the Indexed writeMethod was explicitly set to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            // We need the indexed type to ensure that we get the correct method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            // Cannot use the getIndexedPropertyType method since that could
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            // result in an infinite loop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            Class type = getIndexedPropertyType0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if (type == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                    type = findIndexedPropertyType(getIndexedReadMethod(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    setIndexedPropertyType(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                } catch (IntrospectionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    // Set iprop type to be the classic type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    Class propType = getPropertyType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    if (propType.isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                        type = propType.getComponentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            if (indexedWriteMethodName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                indexedWriteMethodName = Introspector.SET_PREFIX + getBaseName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            }
5947
0e6f2837eeca 6707234: Method returned by Introspector.internalFindMethod not necessarily most specific
malenkov
parents: 5506
diff changeset
   268
            indexedWriteMethod = Introspector.findInstanceMethod(cls, indexedWriteMethodName, int.class, type);
3241
6fd229e009e7 6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents: 466
diff changeset
   269
            if (indexedWriteMethod != null) {
6fd229e009e7 6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents: 466
diff changeset
   270
                if (!indexedWriteMethod.getReturnType().equals(void.class)) {
6fd229e009e7 6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents: 466
diff changeset
   271
                    indexedWriteMethod = null;
6fd229e009e7 6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents: 466
diff changeset
   272
                }
6fd229e009e7 6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents: 466
diff changeset
   273
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            setIndexedWriteMethod0(indexedWriteMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return indexedWriteMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Sets the method that should be used to write an indexed property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @param writeMethod The new indexed write method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    public synchronized void setIndexedWriteMethod(Method writeMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        // If the indexed property type has not been set, then set it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        Class type = findIndexedPropertyType(getIndexedReadMethod(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                                             writeMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        setIndexedPropertyType(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        setIndexedWriteMethod0(writeMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    private void setIndexedWriteMethod0(Method writeMethod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (writeMethod == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            indexedWriteMethodName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            indexedWriteMethodRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        setClass0(writeMethod.getDeclaringClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        indexedWriteMethodName = writeMethod.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        this.indexedWriteMethodRef = getSoftReference(writeMethod);
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   304
        setTransient(writeMethod.getAnnotation(Transient.class));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
4392
4a92100685fa 4638075: DOC: Doc for java.beans.PropertyDescriptor.getPropertyType() is incorrect.
malenkov
parents: 3241
diff changeset
   308
     * Returns the Java type info for the indexed property.
4a92100685fa 4638075: DOC: Doc for java.beans.PropertyDescriptor.getPropertyType() is incorrect.
malenkov
parents: 3241
diff changeset
   309
     * Note that the {@code Class} object may describe
4a92100685fa 4638075: DOC: Doc for java.beans.PropertyDescriptor.getPropertyType() is incorrect.
malenkov
parents: 3241
diff changeset
   310
     * primitive Java types such as {@code int}.
4a92100685fa 4638075: DOC: Doc for java.beans.PropertyDescriptor.getPropertyType() is incorrect.
malenkov
parents: 3241
diff changeset
   311
     * This type is returned by the indexed read method
4a92100685fa 4638075: DOC: Doc for java.beans.PropertyDescriptor.getPropertyType() is incorrect.
malenkov
parents: 3241
diff changeset
   312
     * or is used as the parameter type of the indexed write method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *
4392
4a92100685fa 4638075: DOC: Doc for java.beans.PropertyDescriptor.getPropertyType() is incorrect.
malenkov
parents: 3241
diff changeset
   314
     * @return the {@code Class} object that represents the Java type info,
4a92100685fa 4638075: DOC: Doc for java.beans.PropertyDescriptor.getPropertyType() is incorrect.
malenkov
parents: 3241
diff changeset
   315
     *         or {@code null} if the type cannot be determined
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public synchronized Class<?> getIndexedPropertyType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        Class type = getIndexedPropertyType0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (type == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                type = findIndexedPropertyType(getIndexedReadMethod(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                                               getIndexedWriteMethod());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                setIndexedPropertyType(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            } catch (IntrospectionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                // fall
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    // Private methods which set get/set the Reference objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    private void setIndexedPropertyType(Class type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        this.indexedPropertyTypeRef = getWeakReference(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    private Class getIndexedPropertyType0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        return (this.indexedPropertyTypeRef != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                ? this.indexedPropertyTypeRef.get()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    private Method getIndexedReadMethod0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return (this.indexedReadMethodRef != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                ? this.indexedReadMethodRef.get()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    private Method getIndexedWriteMethod0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return (this.indexedWriteMethodRef != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                ? this.indexedWriteMethodRef.get()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    private Class findIndexedPropertyType(Method indexedReadMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                                          Method indexedWriteMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        Class indexedPropertyType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        if (indexedReadMethod != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            Class params[] = getParameterTypes(getClass0(), indexedReadMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            if (params.length != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                throw new IntrospectionException("bad indexed read method arg count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            if (params[0] != Integer.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                throw new IntrospectionException("non int index to indexed read method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            indexedPropertyType = getReturnType(getClass0(), indexedReadMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            if (indexedPropertyType == Void.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                throw new IntrospectionException("indexed read method returns void");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (indexedWriteMethod != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            Class params[] = getParameterTypes(getClass0(), indexedWriteMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            if (params.length != 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                throw new IntrospectionException("bad indexed write method arg count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            if (params[0] != Integer.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                throw new IntrospectionException("non int index to indexed write method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if (indexedPropertyType != null && indexedPropertyType != params[1]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                throw new IntrospectionException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                                                 "type mismatch between indexed read and indexed write methods: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                                                 + getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            indexedPropertyType = params[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        Class propertyType = getPropertyType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (propertyType != null && (!propertyType.isArray() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                                     propertyType.getComponentType() != indexedPropertyType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            throw new IntrospectionException("type mismatch between indexed and non-indexed methods: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                                             + getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        return indexedPropertyType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Compares this <code>PropertyDescriptor</code> against the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * Returns true if the objects are the same. Two <code>PropertyDescriptor</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * are the same if the read, write, property types, property editor and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * flags  are equivalent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        // Note: This would be identical to PropertyDescriptor but they don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        // share the same fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if (obj != null && obj instanceof IndexedPropertyDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            IndexedPropertyDescriptor other = (IndexedPropertyDescriptor)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            Method otherIndexedReadMethod = other.getIndexedReadMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            Method otherIndexedWriteMethod = other.getIndexedWriteMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            if (!compareMethods(getIndexedReadMethod(), otherIndexedReadMethod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            if (!compareMethods(getIndexedWriteMethod(), otherIndexedWriteMethod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            if (getIndexedPropertyType() != other.getIndexedPropertyType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            return super.equals(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * Package-private constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * Merge two property descriptors.  Where they conflict, give the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * second argument (y) priority over the first argumnnt (x).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @param x  The first (lower priority) PropertyDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @param y  The second (higher priority) PropertyDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    IndexedPropertyDescriptor(PropertyDescriptor x, PropertyDescriptor y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        super(x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        if (x instanceof IndexedPropertyDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            IndexedPropertyDescriptor ix = (IndexedPropertyDescriptor)x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                Method xr = ix.getIndexedReadMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                if (xr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    setIndexedReadMethod(xr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                Method xw = ix.getIndexedWriteMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                if (xw != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    setIndexedWriteMethod(xw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            } catch (IntrospectionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                // Should not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                throw new AssertionError(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        if (y instanceof IndexedPropertyDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            IndexedPropertyDescriptor iy = (IndexedPropertyDescriptor)y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                Method yr = iy.getIndexedReadMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                if (yr != null && yr.getDeclaringClass() == getClass0()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    setIndexedReadMethod(yr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                Method yw = iy.getIndexedWriteMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                if (yw != null && yw.getDeclaringClass() == getClass0()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    setIndexedWriteMethod(yw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            } catch (IntrospectionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                // Should not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                throw new AssertionError(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Package-private dup constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * This must isolate the new object from any changes to the old object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    IndexedPropertyDescriptor(IndexedPropertyDescriptor old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        super(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        indexedReadMethodRef = old.indexedReadMethodRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        indexedWriteMethodRef = old.indexedWriteMethodRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        indexedPropertyTypeRef = old.indexedPropertyTypeRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        indexedWriteMethodName = old.indexedWriteMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        indexedReadMethodName = old.indexedReadMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * Returns a hash code value for the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * See {@link java.lang.Object#hashCode} for a complete description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @return a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        int result = super.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        result = 37 * result + ((indexedWriteMethodName == null) ? 0 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                                indexedWriteMethodName.hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        result = 37 * result + ((indexedReadMethodName == null) ? 0 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                                indexedReadMethodName.hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        result = 37 * result + ((getIndexedPropertyType() == null) ? 0 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                                getIndexedPropertyType().hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
4960
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   513
    void appendTo(StringBuilder sb) {
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   514
        super.appendTo(sb);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   515
        appendTo(sb, "indexedPropertyType", this.indexedPropertyTypeRef);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   516
        appendTo(sb, "indexedReadMethod", this.indexedReadMethodRef);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   517
        appendTo(sb, "indexedWriteMethod", this.indexedWriteMethodRef);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
}