jdk/src/share/classes/java/beans/IndexedPropertyDescriptor.java
author lana
Tue, 01 Jun 2010 14:17:38 -0700
changeset 5597 ab490f66d2cf
parent 5506 202f599c92aa
child 5947 0e6f2837eeca
permissions -rw-r--r--
Merge
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
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            Class[] args = { int.class };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            indexedReadMethod = Introspector.findMethod(cls, indexedReadMethodName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                                                        1, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            if (indexedReadMethod == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                // no "is" method, so look for a "get" method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                indexedReadMethodName = Introspector.GET_PREFIX + getBaseName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                indexedReadMethod = Introspector.findMethod(cls, indexedReadMethodName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                                                            1, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            setIndexedReadMethod0(indexedReadMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return indexedReadMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Sets the method that should be used to read an indexed property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @param readMethod The new indexed read method.
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) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            Class cls = getClass0();
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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            Class type = getIndexedPropertyType0();
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    Class propType = getPropertyType();
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
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            indexedWriteMethod = Introspector.findMethod(cls, indexedWriteMethodName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                         2, (type == null) ? null : new Class[] { int.class, type });
3241
6fd229e009e7 6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents: 466
diff changeset
   275
            if (indexedWriteMethod != null) {
6fd229e009e7 6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents: 466
diff changeset
   276
                if (!indexedWriteMethod.getReturnType().equals(void.class)) {
6fd229e009e7 6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents: 466
diff changeset
   277
                    indexedWriteMethod = null;
6fd229e009e7 6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents: 466
diff changeset
   278
                }
6fd229e009e7 6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents: 466
diff changeset
   279
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            setIndexedWriteMethod0(indexedWriteMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return indexedWriteMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Sets the method that should be used to write an indexed property value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @param writeMethod The new indexed write method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public synchronized void setIndexedWriteMethod(Method writeMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        // If the indexed property type has not been set, then set it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        Class type = findIndexedPropertyType(getIndexedReadMethod(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                                             writeMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        setIndexedPropertyType(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        setIndexedWriteMethod0(writeMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    private void setIndexedWriteMethod0(Method writeMethod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (writeMethod == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            indexedWriteMethodName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            indexedWriteMethodRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        setClass0(writeMethod.getDeclaringClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        indexedWriteMethodName = writeMethod.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        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
   310
        setTransient(writeMethod.getAnnotation(Transient.class));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
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
     * 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
   315
     * Note that the {@code Class} object may describe
4a92100685fa 4638075: DOC: Doc for java.beans.PropertyDescriptor.getPropertyType() is incorrect.
malenkov
parents: 3241
diff changeset
   316
     * primitive Java types such as {@code int}.
4a92100685fa 4638075: DOC: Doc for java.beans.PropertyDescriptor.getPropertyType() is incorrect.
malenkov
parents: 3241
diff changeset
   317
     * 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
   318
     * or is used as the parameter type of the indexed write method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
4392
4a92100685fa 4638075: DOC: Doc for java.beans.PropertyDescriptor.getPropertyType() is incorrect.
malenkov
parents: 3241
diff changeset
   320
     * @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
   321
     *         or {@code null} if the type cannot be determined
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    public synchronized Class<?> getIndexedPropertyType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        Class type = getIndexedPropertyType0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if (type == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                type = findIndexedPropertyType(getIndexedReadMethod(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                                               getIndexedWriteMethod());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                setIndexedPropertyType(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            } catch (IntrospectionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                // fall
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        return 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 methods which set get/set the Reference objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    private void setIndexedPropertyType(Class type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        this.indexedPropertyTypeRef = getWeakReference(type);
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 Class getIndexedPropertyType0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return (this.indexedPropertyTypeRef != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                ? this.indexedPropertyTypeRef.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 getIndexedReadMethod0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return (this.indexedReadMethodRef != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                ? this.indexedReadMethodRef.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 Method getIndexedWriteMethod0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return (this.indexedWriteMethodRef != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                ? this.indexedWriteMethodRef.get()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    private Class findIndexedPropertyType(Method indexedReadMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                                          Method indexedWriteMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        Class indexedPropertyType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if (indexedReadMethod != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            Class params[] = getParameterTypes(getClass0(), indexedReadMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            if (params.length != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                throw new IntrospectionException("bad indexed read method arg count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            if (params[0] != Integer.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                throw new IntrospectionException("non int index to indexed read method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            indexedPropertyType = getReturnType(getClass0(), indexedReadMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            if (indexedPropertyType == Void.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                throw new IntrospectionException("indexed read method returns void");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (indexedWriteMethod != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            Class params[] = getParameterTypes(getClass0(), indexedWriteMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if (params.length != 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                throw new IntrospectionException("bad indexed write method arg count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            if (params[0] != Integer.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                throw new IntrospectionException("non int index to indexed write method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            if (indexedPropertyType != null && indexedPropertyType != params[1]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                throw new IntrospectionException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                                                 "type mismatch between indexed read and indexed write methods: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                                                 + getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            indexedPropertyType = params[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        Class propertyType = getPropertyType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (propertyType != null && (!propertyType.isArray() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                                     propertyType.getComponentType() != indexedPropertyType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            throw new IntrospectionException("type mismatch between indexed and non-indexed methods: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                             + getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return indexedPropertyType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Compares this <code>PropertyDescriptor</code> against the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Returns true if the objects are the same. Two <code>PropertyDescriptor</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * are the same if the read, write, property types, property editor and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * flags  are equivalent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        // Note: This would be identical to PropertyDescriptor but they don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        // share the same fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        if (obj != null && obj instanceof IndexedPropertyDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            IndexedPropertyDescriptor other = (IndexedPropertyDescriptor)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            Method otherIndexedReadMethod = other.getIndexedReadMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            Method otherIndexedWriteMethod = other.getIndexedWriteMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            if (!compareMethods(getIndexedReadMethod(), otherIndexedReadMethod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            if (!compareMethods(getIndexedWriteMethod(), otherIndexedWriteMethod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            if (getIndexedPropertyType() != other.getIndexedPropertyType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            return super.equals(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * Package-private constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * Merge two property descriptors.  Where they conflict, give the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * second argument (y) priority over the first argumnnt (x).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @param x  The first (lower priority) PropertyDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @param y  The second (higher priority) PropertyDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    IndexedPropertyDescriptor(PropertyDescriptor x, PropertyDescriptor y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        super(x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if (x instanceof IndexedPropertyDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            IndexedPropertyDescriptor ix = (IndexedPropertyDescriptor)x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                Method xr = ix.getIndexedReadMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                if (xr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    setIndexedReadMethod(xr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                Method xw = ix.getIndexedWriteMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                if (xw != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    setIndexedWriteMethod(xw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            } catch (IntrospectionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                // Should not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                throw new AssertionError(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (y instanceof IndexedPropertyDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            IndexedPropertyDescriptor iy = (IndexedPropertyDescriptor)y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                Method yr = iy.getIndexedReadMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                if (yr != null && yr.getDeclaringClass() == getClass0()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    setIndexedReadMethod(yr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                Method yw = iy.getIndexedWriteMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                if (yw != null && yw.getDeclaringClass() == getClass0()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    setIndexedWriteMethod(yw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            } catch (IntrospectionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                // Should not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                throw new AssertionError(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * Package-private dup constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * This must isolate the new object from any changes to the old object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    IndexedPropertyDescriptor(IndexedPropertyDescriptor old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        super(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        indexedReadMethodRef = old.indexedReadMethodRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        indexedWriteMethodRef = old.indexedWriteMethodRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        indexedPropertyTypeRef = old.indexedPropertyTypeRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        indexedWriteMethodName = old.indexedWriteMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        indexedReadMethodName = old.indexedReadMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * Returns a hash code value for the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * See {@link java.lang.Object#hashCode} for a complete description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @return a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        int result = super.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        result = 37 * result + ((indexedWriteMethodName == null) ? 0 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                                indexedWriteMethodName.hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        result = 37 * result + ((indexedReadMethodName == null) ? 0 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                                indexedReadMethodName.hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        result = 37 * result + ((getIndexedPropertyType() == null) ? 0 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                                getIndexedPropertyType().hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
4960
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   519
    void appendTo(StringBuilder sb) {
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   520
        super.appendTo(sb);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   521
        appendTo(sb, "indexedPropertyType", this.indexedPropertyTypeRef);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   522
        appendTo(sb, "indexedReadMethod", this.indexedReadMethodRef);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 4392
diff changeset
   523
        appendTo(sb, "indexedWriteMethod", this.indexedWriteMethodRef);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
}