jdk/src/share/classes/java/beans/DefaultPersistenceDelegate.java
author malenkov
Tue, 11 Sep 2012 10:58:39 +0400
changeset 13773 69665c88db93
parent 11120 f8576c769572
child 14887 226dd1cda199
permissions -rw-r--r--
7193977: REGRESSION:Java 7's JavaBeans persistence ignoring the "transient" flag on properties Reviewed-by: rupashka
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8760
diff changeset
     2
 * Copyright (c) 2000, 2011, 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: 4849
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: 4849
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: 4849
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4849
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4849
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.beans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.reflect.*;
9548
225dbdc1cb74 7041136: Use Objects.equals in JDK platform classes
darcy
parents: 9035
diff changeset
    29
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.reflect.misc.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * The <code>DefaultPersistenceDelegate</code> is a concrete implementation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * the abstract <code>PersistenceDelegate</code> class and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * is the delegate used by default for classes about
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * which no information is available. The <code>DefaultPersistenceDelegate</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * provides, version resilient, public API-based persistence for
8760
83843c0b84f7 7021517: java.beans code comments have issues with HTML4 compliance
malenkov
parents: 5597
diff changeset
    39
 * classes that follow the JavaBeans&trade; conventions without any class specific
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The key assumptions are that the class has a nullary constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * and that its state is accurately represented by matching pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * of "setter" and "getter" methods in the order they are returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * by the Introspector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * In addition to providing code-free persistence for JavaBeans,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the <code>DefaultPersistenceDelegate</code> provides a convenient means
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * to effect persistent storage for classes that have a constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * that, while not nullary, simply requires some property values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * as arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see #DefaultPersistenceDelegate(String[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see java.beans.Introspector
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author Philip Milne
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class DefaultPersistenceDelegate extends PersistenceDelegate {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private String[] constructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private Boolean definesEquals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Creates a persistence delegate for a class with a nullary constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @see #DefaultPersistenceDelegate(java.lang.String[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public DefaultPersistenceDelegate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        this(new String[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Creates a default persistence delegate for a class with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * constructor whose arguments are the values of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * names as specified by <code>constructorPropertyNames</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * The constructor arguments are created by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * evaluating the property names in the order they are supplied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * To use this class to specify a single preferred constructor for use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * in the serialization of a particular type, we state the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * names of the properties that make up the constructor's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * arguments. For example, the <code>Font</code> class which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * does not define a nullary constructor can be handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * with the following persistence delegate:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *     new DefaultPersistenceDelegate(new String[]{"name", "style", "size"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param  constructorPropertyNames The property names for the arguments of this constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @see #instantiate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public DefaultPersistenceDelegate(String[] constructorPropertyNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        this.constructor = constructorPropertyNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
    98
    private static boolean definesEquals(Class<?> type) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            return type == type.getMethod("equals", Object.class).getDeclaringClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        catch(NoSuchMethodException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private boolean definesEquals(Object instance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (definesEquals != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            return (definesEquals == Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            boolean result = definesEquals(instance.getClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            definesEquals = result ? Boolean.TRUE : Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * If the number of arguments in the specified constructor is non-zero and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * the class of <code>oldInstance</code> explicitly declares an "equals" method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * this method returns the value of <code>oldInstance.equals(newInstance)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Otherwise, this method uses the superclass's definition which returns true if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * classes of the two instances are equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param oldInstance The instance to be copied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @param newInstance The instance that is to be modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @return True if an equivalent copy of <code>newInstance</code> may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *         created by applying a series of mutations to <code>oldInstance</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @see #DefaultPersistenceDelegate(String[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        // Assume the instance is either mutable or a singleton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // if it has a nullary constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return (constructor.length == 0) || !definesEquals(oldInstance) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            super.mutatesTo(oldInstance, newInstance) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            oldInstance.equals(newInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * This default implementation of the <code>instantiate</code> method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * an expression containing the predefined method name "new" which denotes a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * call to a constructor with the arguments as specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * the <code>DefaultPersistenceDelegate</code>'s constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param  oldInstance The instance to be instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @param  out The code output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @return An expression whose value is <code>oldInstance</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
4849
c83eca4dbb8f 6412286: DOC: LTP: Unspecified NPE in java.beans.DefaultPersistenceDelegate.instantiate method
malenkov
parents: 1280
diff changeset
   150
     * @throws NullPointerException if {@code out} is {@code null}
c83eca4dbb8f 6412286: DOC: LTP: Unspecified NPE in java.beans.DefaultPersistenceDelegate.instantiate method
malenkov
parents: 1280
diff changeset
   151
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @see #DefaultPersistenceDelegate(String[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        int nArgs = constructor.length;
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   156
        Class<?> type = oldInstance.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        Object[] constructorArgs = new Object[nArgs];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        for(int i = 0; i < nArgs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                Method method = findMethod(type, this.constructor[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                constructorArgs[i] = MethodUtil.invoke(method, oldInstance, new Object[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                out.getExceptionListener().exceptionThrown(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return new Expression(oldInstance, oldInstance.getClass(), "new", constructorArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   170
    private Method findMethod(Class<?> type, String property) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (property == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            throw new IllegalArgumentException("Property name is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   174
        PropertyDescriptor pd = getPropertyDescriptor(type, property);
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   175
        if (pd == null) {
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   176
            throw new IllegalStateException("Could not find property by the name " + property);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   178
        Method method = pd.getReadMethod();
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   179
        if (method == null) {
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   180
            throw new IllegalStateException("Could not find getter for the property " + property);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   182
        return method;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   185
    private void doProperty(Class<?> type, PropertyDescriptor pd, Object oldInstance, Object newInstance, Encoder out) throws Exception {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        Method getter = pd.getReadMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        Method setter = pd.getWriteMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   189
        if (getter != null && setter != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            Expression oldGetExp = new Expression(oldInstance, getter.getName(), new Object[]{});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            Expression newGetExp = new Expression(newInstance, getter.getName(), new Object[]{});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            Object oldValue = oldGetExp.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            Object newValue = newGetExp.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            out.writeExpression(oldGetExp);
9548
225dbdc1cb74 7041136: Use Objects.equals in JDK platform classes
darcy
parents: 9035
diff changeset
   195
            if (!Objects.equals(newValue, out.get(oldValue))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                // Search for a static constant with this value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                Object e = (Object[])pd.getValue("enumerationValues");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                if (e instanceof Object[] && Array.getLength(e) % 3 == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    Object[] a = (Object[])e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    for(int i = 0; i < a.length; i = i + 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                           Field f = type.getField((String)a[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                           if (f.get(null).equals(oldValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                               out.remove(oldValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                               out.writeExpression(new Expression(oldValue, f, "get", new Object[]{null}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                        catch (Exception ex) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                invokeStatement(oldInstance, setter.getName(), new Object[]{oldValue}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    static void invokeStatement(Object instance, String methodName, Object[] args, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        out.writeStatement(new Statement(instance, methodName, args));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    // Write out the properties of this instance.
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   221
    private void initBean(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
5583
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   222
        for (Field field : type.getFields()) {
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   223
            int mod = field.getModifiers();
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   224
            if (Modifier.isFinal(mod) || Modifier.isStatic(mod) || Modifier.isTransient(mod)) {
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   225
                continue;
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   226
            }
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   227
            try {
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   228
                Expression oldGetExp = new Expression(field, "get", new Object[] { oldInstance });
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   229
                Expression newGetExp = new Expression(field, "get", new Object[] { newInstance });
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   230
                Object oldValue = oldGetExp.getValue();
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   231
                Object newValue = newGetExp.getValue();
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   232
                out.writeExpression(oldGetExp);
9548
225dbdc1cb74 7041136: Use Objects.equals in JDK platform classes
darcy
parents: 9035
diff changeset
   233
                if (!Objects.equals(newValue, out.get(oldValue))) {
5583
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   234
                    out.writeStatement(new Statement(field, "set", new Object[] { oldInstance, oldValue }));
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   235
                }
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   236
            }
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   237
            catch (Exception exception) {
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   238
                out.getExceptionListener().exceptionThrown(exception);
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   239
            }
6cb5bb2e8335 6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
malenkov
parents: 4849
diff changeset
   240
        }
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   241
        BeanInfo info;
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   242
        try {
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   243
            info = Introspector.getBeanInfo(type);
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   244
        } catch (IntrospectionException exception) {
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   245
            return;
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   246
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        // Properties
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   248
        for (PropertyDescriptor d : info.getPropertyDescriptors()) {
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   249
            if (d.isTransient()) {
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   250
                continue;
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   251
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            try {
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   253
                doProperty(type, d, oldInstance, newInstance, out);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                out.getExceptionListener().exceptionThrown(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        // Listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        Pending(milne). There is a general problem with the archival of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        listeners which is unresolved as of 1.4. Many of the methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        which install one object inside another (typically "add" methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        or setters) automatically install a listener on the "child" object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        so that its "parent" may respond to changes that are made to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        For example the JTable:setModel() method automatically adds a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        TableModelListener (the JTable itself in this case) to the supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        table model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        We do not need to explictly add these listeners to the model in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        archive as they will be added automatically by, in the above case,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        the JTable's "setModel" method. In some cases, we must specifically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        avoid trying to do this since the listener may be an inner class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        that cannot be instantiated using public API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        No general mechanism currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        exists for differentiating between these kind of listeners and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        those which were added explicitly by the user. A mechanism must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        be created to provide a general means to differentiate these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        special cases so as to provide reliable persistence of listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        for the general case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (!java.awt.Component.class.isAssignableFrom(type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            return; // Just handle the listeners of Components for now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   287
        for (EventSetDescriptor d : info.getEventSetDescriptors()) {
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   288
            if (d.isTransient()) {
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   289
                continue;
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   290
            }
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   291
            Class<?> listenerType = d.getListenerType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            // The ComponentListener is added automatically, when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            // Contatiner:add is called on the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            if (listenerType == java.awt.event.ComponentListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            // JMenuItems have a change listener added to them in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            // their "add" methods to enable accessibility support -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            // see the add method in JMenuItem for details. We cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            // instantiate this instance as it is a private inner class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            // and do not need to do this anyway since it will be created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            // and installed by the "add" method. Special case this for now,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            // ignoring all change listeners on JMenuItems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            if (listenerType == javax.swing.event.ChangeListener.class &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                type == javax.swing.JMenuItem.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            EventListener[] oldL = new EventListener[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            EventListener[] newL = new EventListener[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                Method m = d.getGetListenerMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                oldL = (EventListener[])MethodUtil.invoke(m, oldInstance, new Object[]{});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                newL = (EventListener[])MethodUtil.invoke(m, newInstance, new Object[]{});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            }
1280
f58fc9f575e3 6351692: catch(Throwable) in java.beans.MetaData preventing thread shutdown
malenkov
parents: 466
diff changeset
   319
            catch (Exception e2) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                try {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   321
                    Method m = type.getMethod("getListeners", new Class<?>[]{Class.class});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    oldL = (EventListener[])MethodUtil.invoke(m, oldInstance, new Object[]{listenerType});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                    newL = (EventListener[])MethodUtil.invoke(m, newInstance, new Object[]{listenerType});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                catch (Exception e3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            // Asssume the listeners are in the same order and that there are no gaps.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            // Eventually, this may need to do true differencing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            String addListenerMethodName = d.getAddListenerMethod().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            for (int i = newL.length; i < oldL.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                // System.out.println("Adding listener: " + addListenerMethodName + oldL[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                invokeStatement(oldInstance, addListenerMethodName, new Object[]{oldL[i]}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            String removeListenerMethodName = d.getRemoveListenerMethod().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            for (int i = oldL.length; i < newL.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                invokeStatement(oldInstance, removeListenerMethodName, new Object[]{newL[i]}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * This default implementation of the <code>initialize</code> method assumes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * all state held in objects of this type is exposed via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * matching pairs of "setter" and "getter" methods in the order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * they are returned by the Introspector. If a property descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * defines a "transient" attribute with a value equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * <code>Boolean.TRUE</code> the property is ignored by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * default implementation. Note that this use of the word
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * "transient" is quite independent of the field modifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * that is used by the <code>ObjectOutputStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * For each non-transient property, an expression is created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * in which the nullary "getter" method is applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * to the <code>oldInstance</code>. The value of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * expression is the value of the property in the instance that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * being serialized. If the value of this expression
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * in the cloned environment <code>mutatesTo</code> the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * target value, the new value is initialized to make it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * equivalent to the old value. In this case, because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * the property value has not changed there is no need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * call the corresponding "setter" method and no statement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * is emitted. If not however, the expression for this value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * is replaced with another expression (normally a constructor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * and the corresponding "setter" method is called to install
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * the new property value in the object. This scheme removes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * default information from the output produced by streams
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * using this delegate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * In passing these statements to the output stream, where they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * will be executed, side effects are made to the <code>newInstance</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * In most cases this allows the problem of properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * whose values depend on each other to actually help the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * serialization process by making the number of statements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * that need to be written to the output smaller. In general,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * the problem of handling interdependent properties is reduced to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * that of finding an order for the properties in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * a class such that no property value depends on the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * a subsequent property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @param oldInstance The instance to be copied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @param newInstance The instance that is to be modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @param out The stream to which any initialization statements should be written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *
4849
c83eca4dbb8f 6412286: DOC: LTP: Unspecified NPE in java.beans.DefaultPersistenceDelegate.instantiate method
malenkov
parents: 1280
diff changeset
   388
     * @throws NullPointerException if {@code out} is {@code null}
c83eca4dbb8f 6412286: DOC: LTP: Unspecified NPE in java.beans.DefaultPersistenceDelegate.instantiate method
malenkov
parents: 1280
diff changeset
   389
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @see java.beans.Introspector#getBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @see java.beans.PropertyDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    protected void initialize(Class<?> type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                              Object oldInstance, Object newInstance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                              Encoder out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        // System.out.println("DefulatPD:initialize" + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        super.initialize(type, oldInstance, newInstance, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        if (oldInstance.getClass() == type) { // !type.isInterface()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            initBean(type, oldInstance, newInstance, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   403
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   404
    private static PropertyDescriptor getPropertyDescriptor(Class<?> type, String property) {
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   405
        try {
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   406
            for (PropertyDescriptor pd : Introspector.getBeanInfo(type).getPropertyDescriptors()) {
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   407
                if (property.equals(pd.getName()))
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   408
                    return pd;
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   409
            }
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   410
        } catch (IntrospectionException exception) {
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   411
        }
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   412
        return null;
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   413
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
}