jdk/src/share/classes/java/beans/IndexedPropertyDescriptor.java
author darcy
Tue, 06 Aug 2013 16:01:39 -0700
changeset 19213 c360667a0da2
parent 13773 69665c88db93
child 20110 85b98c3054f6
permissions -rw-r--r--
8022406: Fix doclint issues in java.beans Reviewed-by: prr
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
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
    43
    private Reference<? extends Class<?>> indexedPropertyTypeRef;
2
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) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   178
            Class<?> cls = getClass0();
2
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
            }
13356
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11120
diff changeset
   184
            String nextMethodName = Introspector.GET_PREFIX + getBaseName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            if (indexedReadMethodName == null) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   186
                Class<?> type = getIndexedPropertyType0();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                if (type == boolean.class || type == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    indexedReadMethodName = Introspector.IS_PREFIX + getBaseName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                } else {
13356
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11120
diff changeset
   190
                    indexedReadMethodName = nextMethodName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            }
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5947
diff changeset
   193
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   194
            Class<?>[] args = { int.class };
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5947
diff changeset
   195
            indexedReadMethod = Introspector.findMethod(cls, indexedReadMethodName, 1, args);
13356
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11120
diff changeset
   196
            if ((indexedReadMethod == null) && !indexedReadMethodName.equals(nextMethodName)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                // no "is" method, so look for a "get" method.
13356
89a34c00fd8c 7187618: PropertyDescriptor Performance Slow
malenkov
parents: 11120
diff changeset
   198
                indexedReadMethodName = nextMethodName;
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5947
diff changeset
   199
                indexedReadMethod = Introspector.findMethod(cls, indexedReadMethodName, 1, args);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            setIndexedReadMethod0(indexedReadMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return indexedReadMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Sets the method that should be used to read an indexed property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param readMethod The new indexed read method.
19213
c360667a0da2 8022406: Fix doclint issues in java.beans
darcy
parents: 13773
diff changeset
   210
     * @throws IntrospectionException if an exception occurs during
c360667a0da2 8022406: Fix doclint issues in java.beans
darcy
parents: 13773
diff changeset
   211
     * introspection.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public synchronized void setIndexedReadMethod(Method readMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        // the indexed property type is set by the reader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        setIndexedPropertyType(findIndexedPropertyType(readMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                                                       getIndexedWriteMethod0()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        setIndexedReadMethod0(readMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    private void setIndexedReadMethod0(Method readMethod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (readMethod == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            indexedReadMethodName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            indexedReadMethodRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        setClass0(readMethod.getDeclaringClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        indexedReadMethodName = readMethod.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        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
   232
        setTransient(readMethod.getAnnotation(Transient.class));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Gets the method that should be used to write an indexed property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @return The method that should be used to write an indexed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * May return null if the property isn't indexed or is read-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public synchronized Method getIndexedWriteMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        Method indexedWriteMethod = getIndexedWriteMethod0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (indexedWriteMethod == null) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   246
            Class<?> cls = getClass0();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            if (cls == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                (indexedWriteMethodName == null && indexedWriteMethodRef == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                // the Indexed writeMethod was explicitly set to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            // We need the indexed type to ensure that we get the correct method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            // Cannot use the getIndexedPropertyType method since that could
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            // result in an infinite loop.
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   256
            Class<?> type = getIndexedPropertyType0();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            if (type == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    type = findIndexedPropertyType(getIndexedReadMethod(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    setIndexedPropertyType(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                } catch (IntrospectionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    // Set iprop type to be the classic type
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   263
                    Class<?> propType = getPropertyType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                    if (propType.isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                        type = propType.getComponentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            if (indexedWriteMethodName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                indexedWriteMethodName = Introspector.SET_PREFIX + getBaseName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5947
diff changeset
   273
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   274
            Class<?>[] args = (type == null) ? null : new Class<?>[] { int.class, type };
6657
15dbb366c6a3 6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents: 5947
diff changeset
   275
            indexedWriteMethod = Introspector.findMethod(cls, indexedWriteMethodName, 2, args);
3241
6fd229e009e7 6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents: 466
diff changeset
   276
            if (indexedWriteMethod != null) {
6fd229e009e7 6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents: 466
diff changeset
   277
                if (!indexedWriteMethod.getReturnType().equals(void.class)) {
6fd229e009e7 6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents: 466
diff changeset
   278
                    indexedWriteMethod = null;
6fd229e009e7 6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents: 466
diff changeset
   279
                }
6fd229e009e7 6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents: 466
diff changeset
   280
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            setIndexedWriteMethod0(indexedWriteMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        return indexedWriteMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Sets the method that should be used to write an indexed property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param writeMethod The new indexed write method.
19213
c360667a0da2 8022406: Fix doclint issues in java.beans
darcy
parents: 13773
diff changeset
   290
     * @throws IntrospectionException if an exception occurs during
c360667a0da2 8022406: Fix doclint issues in java.beans
darcy
parents: 13773
diff changeset
   291
     * introspection.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public synchronized void setIndexedWriteMethod(Method writeMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        // If the indexed property type has not been set, then set it.
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   297
        Class<?> type = findIndexedPropertyType(getIndexedReadMethod(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                                             writeMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        setIndexedPropertyType(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        setIndexedWriteMethod0(writeMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    private void setIndexedWriteMethod0(Method writeMethod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (writeMethod == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            indexedWriteMethodName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            indexedWriteMethodRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        setClass0(writeMethod.getDeclaringClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        indexedWriteMethodName = writeMethod.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        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
   313
        setTransient(writeMethod.getAnnotation(Transient.class));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
4392
4a92100685fa 4638075: DOC: Doc for java.beans.PropertyDescriptor.getPropertyType() is incorrect.
malenkov
parents: 3241
diff changeset
   317
     * 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
   318
     * Note that the {@code Class} object may describe
4a92100685fa 4638075: DOC: Doc for java.beans.PropertyDescriptor.getPropertyType() is incorrect.
malenkov
parents: 3241
diff changeset
   319
     * primitive Java types such as {@code int}.
4a92100685fa 4638075: DOC: Doc for java.beans.PropertyDescriptor.getPropertyType() is incorrect.
malenkov
parents: 3241
diff changeset
   320
     * 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
   321
     * or is used as the parameter type of the indexed write method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
4392
4a92100685fa 4638075: DOC: Doc for java.beans.PropertyDescriptor.getPropertyType() is incorrect.
malenkov
parents: 3241
diff changeset
   323
     * @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
   324
     *         or {@code null} if the type cannot be determined
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public synchronized Class<?> getIndexedPropertyType() {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   327
        Class<?> type = getIndexedPropertyType0();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (type == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                type = findIndexedPropertyType(getIndexedReadMethod(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                                               getIndexedWriteMethod());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                setIndexedPropertyType(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            } catch (IntrospectionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                // fall
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    // Private methods which set get/set the Reference objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   342
    private void setIndexedPropertyType(Class<?> type) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        this.indexedPropertyTypeRef = getWeakReference(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   346
    private Class<?> getIndexedPropertyType0() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return (this.indexedPropertyTypeRef != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                ? this.indexedPropertyTypeRef.get()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    private Method getIndexedReadMethod0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        return (this.indexedReadMethodRef != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                ? this.indexedReadMethodRef.get()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    private Method getIndexedWriteMethod0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return (this.indexedWriteMethodRef != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                ? this.indexedWriteMethodRef.get()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   364
    private Class<?> findIndexedPropertyType(Method indexedReadMethod,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                          Method indexedWriteMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        throws IntrospectionException {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   367
        Class<?> indexedPropertyType = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (indexedReadMethod != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            Class params[] = getParameterTypes(getClass0(), indexedReadMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            if (params.length != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                throw new IntrospectionException("bad indexed read method arg count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            if (params[0] != Integer.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                throw new IntrospectionException("non int index to indexed read method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            indexedPropertyType = getReturnType(getClass0(), indexedReadMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            if (indexedPropertyType == Void.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                throw new IntrospectionException("indexed read method returns void");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (indexedWriteMethod != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            Class params[] = getParameterTypes(getClass0(), indexedWriteMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            if (params.length != 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                throw new IntrospectionException("bad indexed write method arg count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            if (params[0] != Integer.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                throw new IntrospectionException("non int index to indexed write method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            if (indexedPropertyType != null && indexedPropertyType != params[1]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                throw new IntrospectionException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                                                 "type mismatch between indexed read and indexed write methods: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                                                 + getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            indexedPropertyType = params[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 6657
diff changeset
   397
        Class<?> propertyType = getPropertyType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (propertyType != null && (!propertyType.isArray() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                                     propertyType.getComponentType() != indexedPropertyType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            throw new IntrospectionException("type mismatch between indexed and non-indexed methods: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                                             + getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        return indexedPropertyType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * Compares this <code>PropertyDescriptor</code> against the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Returns true if the objects are the same. Two <code>PropertyDescriptor</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * are the same if the read, write, property types, property editor and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * flags  are equivalent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        // Note: This would be identical to PropertyDescriptor but they don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        // share the same fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            return true;
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 (obj != null && obj instanceof IndexedPropertyDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            IndexedPropertyDescriptor other = (IndexedPropertyDescriptor)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            Method otherIndexedReadMethod = other.getIndexedReadMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            Method otherIndexedWriteMethod = other.getIndexedWriteMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            if (!compareMethods(getIndexedReadMethod(), otherIndexedReadMethod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            if (!compareMethods(getIndexedWriteMethod(), otherIndexedWriteMethod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            if (getIndexedPropertyType() != other.getIndexedPropertyType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            return super.equals(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * Package-private constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * Merge two property descriptors.  Where they conflict, give the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * second argument (y) priority over the first argumnnt (x).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @param x  The first (lower priority) PropertyDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @param y  The second (higher priority) PropertyDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    IndexedPropertyDescriptor(PropertyDescriptor x, PropertyDescriptor y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        super(x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        if (x instanceof IndexedPropertyDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            IndexedPropertyDescriptor ix = (IndexedPropertyDescriptor)x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                Method xr = ix.getIndexedReadMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                if (xr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    setIndexedReadMethod(xr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                Method xw = ix.getIndexedWriteMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                if (xw != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    setIndexedWriteMethod(xw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            } catch (IntrospectionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                // Should not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                throw new AssertionError(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        if (y instanceof IndexedPropertyDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            IndexedPropertyDescriptor iy = (IndexedPropertyDescriptor)y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                Method yr = iy.getIndexedReadMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                if (yr != null && yr.getDeclaringClass() == getClass0()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    setIndexedReadMethod(yr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                Method yw = iy.getIndexedWriteMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                if (yw != null && yw.getDeclaringClass() == getClass0()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    setIndexedWriteMethod(yw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            } catch (IntrospectionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                // Should not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                throw new AssertionError(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * Package-private dup constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * This must isolate the new object from any changes to the old object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    IndexedPropertyDescriptor(IndexedPropertyDescriptor old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        super(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        indexedReadMethodRef = old.indexedReadMethodRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        indexedWriteMethodRef = old.indexedWriteMethodRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        indexedPropertyTypeRef = old.indexedPropertyTypeRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        indexedWriteMethodName = old.indexedWriteMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        indexedReadMethodName = old.indexedReadMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
13773
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13356
diff changeset
   502
    void updateGenericsFor(Class<?> type) {
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13356
diff changeset
   503
        super.updateGenericsFor(type);
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13356
diff changeset
   504
        try {
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13356
diff changeset
   505
            setIndexedPropertyType(findIndexedPropertyType(getIndexedReadMethod0(), getIndexedWriteMethod0()));
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13356
diff changeset
   506
        }
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13356
diff changeset
   507
        catch (IntrospectionException exception) {
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13356
diff changeset
   508
            setIndexedPropertyType(null);
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13356
diff changeset
   509
        }
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13356
diff changeset
   510
    }
69665c88db93 7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties
malenkov
parents: 13356
diff changeset
   511
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * Returns a hash code value for the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * See {@link java.lang.Object#hashCode} for a complete description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @return a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        int result = super.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        result = 37 * result + ((indexedWriteMethodName == null) ? 0 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                                indexedWriteMethodName.hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        result = 37 * result + ((indexedReadMethodName == null) ? 0 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                                indexedReadMethodName.hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        result = 37 * result + ((getIndexedPropertyType() == null) ? 0 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                                getIndexedPropertyType().hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
4960
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   532
    void appendTo(StringBuilder sb) {
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   533
        super.appendTo(sb);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   534
        appendTo(sb, "indexedPropertyType", this.indexedPropertyTypeRef);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   535
        appendTo(sb, "indexedReadMethod", this.indexedReadMethodRef);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   536
        appendTo(sb, "indexedWriteMethod", this.indexedWriteMethodRef);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
}