jdk/src/share/classes/java/beans/MetaData.java
author darcy
Tue, 03 Jun 2014 09:22:59 -0700
changeset 25123 1f70b30da563
parent 23010 6dadb192ad81
child 25777 bb88947b6766
permissions -rw-r--r--
8042860: Fix raw and unchecked warnings in java.beans Reviewed-by: malenkov, alanb, mduigou
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
25123
1f70b30da563 8042860: Fix raw and unchecked warnings in java.beans
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 2000, 2014, 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: 4232
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: 4232
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: 4232
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4232
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4232
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
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1281
diff changeset
    27
import com.sun.beans.finder.PrimitiveWrapperMap;
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1281
diff changeset
    28
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.AWTKeyStroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.BorderLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.GridBagConstraints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.event.KeyEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.font.TextAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.lang.reflect.Array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.lang.reflect.Constructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.lang.reflect.Field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.lang.reflect.Method;
20802
758273542f3d 8012071: Better Building of Beans
malenkov
parents: 17148
diff changeset
    45
import java.lang.reflect.Modifier;
4232
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
    46
import java.lang.reflect.InvocationTargetException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import javax.swing.Box;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.swing.JLayeredPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import javax.swing.border.MatteBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import javax.swing.plaf.ColorUIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.swing.PrintColorUIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
20802
758273542f3d 8012071: Better Building of Beans
malenkov
parents: 17148
diff changeset
    60
import static sun.reflect.misc.ReflectUtil.isPackageAccessible;
9548
225dbdc1cb74 7041136: Use Objects.equals in JDK platform classes
darcy
parents: 7668
diff changeset
    61
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Like the <code>Intropector</code>, the <code>MetaData</code> class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * contains <em>meta</em> objects that describe the way
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * classes should express their state in terms of their
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * own public APIs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @see java.beans.Intropector
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @author Philip Milne
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * @author Steve Langley
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 */
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
    73
class MetaData {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
    75
static final class NullPersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // Note this will be called by all classes when they reach the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // top of their superclass chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    protected Expression instantiate(Object oldInstance, Encoder out) { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public void writeObject(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // System.out.println("NullPersistenceDelegate:writeObject " + oldInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * The persistence delegate for <CODE>enum</CODE> classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * @author Sergey A. Malenkov
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 */
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
    92
static final class EnumPersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return oldInstance == newInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
    98
        Enum<?> e = (Enum<?>) oldInstance;
3095
094359fe94bb 6852574: EnumPersistenceDelegate fails to persist instances with blocks
malenkov
parents: 1844
diff changeset
    99
        return new Expression(e, Enum.class, "valueOf", new Object[]{e.getDeclaringClass(), e.name()});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   103
static final class PrimitivePersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return oldInstance.equals(newInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return new Expression(oldInstance, oldInstance.getClass(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                  "new", new Object[]{oldInstance.toString()});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   114
static final class ArrayPersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return (newInstance != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                oldInstance.getClass() == newInstance.getClass() && // Also ensures the subtype is correct.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                Array.getLength(oldInstance) == Array.getLength(newInstance));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        // System.out.println("instantiate: " + type + " " + oldInstance);
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   123
        Class<?> oldClass = oldInstance.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return new Expression(oldInstance, Array.class, "newInstance",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                   new Object[]{oldClass.getComponentType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                new Integer(Array.getLength(oldInstance))});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        int n = Array.getLength(oldInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            Object index = new Integer(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            // Expression oldGetExp = new Expression(Array.class, "get", new Object[]{oldInstance, index});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            // Expression newGetExp = new Expression(Array.class, "get", new Object[]{newInstance, index});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            Expression oldGetExp = new Expression(oldInstance, "get", new Object[]{index});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            Expression newGetExp = new Expression(newInstance, "get", new Object[]{index});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                Object oldValue = oldGetExp.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                Object newValue = newGetExp.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                out.writeExpression(oldGetExp);
9548
225dbdc1cb74 7041136: Use Objects.equals in JDK platform classes
darcy
parents: 7668
diff changeset
   141
                if (!Objects.equals(newValue, out.get(oldValue))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    // System.out.println("Not equal: " + newGetExp + " != " + actualGetExp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    // invokeStatement(Array.class, "set", new Object[]{oldInstance, index, oldValue}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    DefaultPersistenceDelegate.invokeStatement(oldInstance, "set", new Object[]{index, oldValue}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                // System.err.println("Warning:: failed to write: " + oldGetExp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                out.getExceptionListener().exceptionThrown(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   155
static final class ProxyPersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   157
        Class<?> type = oldInstance.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        java.lang.reflect.Proxy p = (java.lang.reflect.Proxy)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        // This unappealing hack is not required but makes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        // representation of EventHandlers much more concise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        java.lang.reflect.InvocationHandler ih = java.lang.reflect.Proxy.getInvocationHandler(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (ih instanceof EventHandler) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            EventHandler eh = (EventHandler)ih;
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   164
            Vector<Object> args = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            args.add(type.getInterfaces()[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            args.add(eh.getTarget());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            args.add(eh.getAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            if (eh.getEventPropertyName() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                args.add(eh.getEventPropertyName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (eh.getListenerMethodName() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                args.setSize(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                args.add(eh.getListenerMethodName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            return new Expression(oldInstance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                  EventHandler.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                  "create",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                  args.toArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return new Expression(oldInstance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                              java.lang.reflect.Proxy.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                              "newProxyInstance",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                              new Object[]{type.getClassLoader(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                           type.getInterfaces(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                           ih});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
// Strings
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   190
static final class java_lang_String_PersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    protected Expression instantiate(Object oldInstance, Encoder out) { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public void writeObject(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        // System.out.println("NullPersistenceDelegate:writeObject " + oldInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
// Classes
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   199
static final class java_lang_Class_PersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return oldInstance.equals(newInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   205
        Class<?> c = (Class)oldInstance;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        // As of 1.3 it is not possible to call Class.forName("int"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        // so we have to generate different code for primitive types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        // This is needed for arrays whose subtype may be primitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (c.isPrimitive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            Field field = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            try {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1281
diff changeset
   212
                field = PrimitiveWrapperMap.getType(c.getName()).getDeclaredField("TYPE");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            } catch (NoSuchFieldException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                System.err.println("Unknown primitive type: " + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            return new Expression(oldInstance, field, "get", new Object[]{null});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        else if (oldInstance == String.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return new Expression(oldInstance, "", "getClass", new Object[]{});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        else if (oldInstance == Class.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            return new Expression(oldInstance, String.class, "getClass", new Object[]{});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        else {
3240
2f79c1748c93 6329581: RFE: LTP: java.beans.XMLEncoder does not manage ClassLoader.
malenkov
parents: 3095
diff changeset
   225
            Expression newInstance = new Expression(oldInstance, Class.class, "forName", new Object[] { c.getName() });
2f79c1748c93 6329581: RFE: LTP: java.beans.XMLEncoder does not manage ClassLoader.
malenkov
parents: 3095
diff changeset
   226
            newInstance.loader = c.getClassLoader();
2f79c1748c93 6329581: RFE: LTP: java.beans.XMLEncoder does not manage ClassLoader.
malenkov
parents: 3095
diff changeset
   227
            return newInstance;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
// Fields
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   233
static final class java_lang_reflect_Field_PersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return oldInstance.equals(newInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        Field f = (Field)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        return new Expression(oldInstance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                f.getDeclaringClass(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                "getField",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                new Object[]{f.getName()});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
// Methods
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   248
static final class java_lang_reflect_Method_PersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return oldInstance.equals(newInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        Method m = (Method)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return new Expression(oldInstance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                m.getDeclaringClass(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                "getMethod",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                new Object[]{m.getName(), m.getParameterTypes()});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
// Dates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 * The persistence delegate for <CODE>java.util.Date</CODE> classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 * Do not extend DefaultPersistenceDelegate to improve performance and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 * to avoid problems with <CODE>java.sql.Date</CODE>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 * <CODE>java.sql.Time</CODE> and <CODE>java.sql.Timestamp</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 * @author Sergey A. Malenkov
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 */
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   272
static class java_util_Date_PersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (!super.mutatesTo(oldInstance, newInstance)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        Date oldDate = (Date)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        Date newDate = (Date)newInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return oldDate.getTime() == newDate.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        Date date = (Date)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        return new Expression(date, date.getClass(), "new", new Object[] {date.getTime()});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 * The persistence delegate for <CODE>java.sql.Timestamp</CODE> classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 * It supports nanoseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 * @author Sergey A. Malenkov
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 */
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   295
static final class java_sql_Timestamp_PersistenceDelegate extends java_util_Date_PersistenceDelegate {
4232
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   296
    private static final Method getNanosMethod = getNanosMethod();
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   297
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   298
    private static Method getNanosMethod() {
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   299
        try {
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   300
            Class<?> c = Class.forName("java.sql.Timestamp", true, null);
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   301
            return c.getMethod("getNanos");
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   302
        } catch (ClassNotFoundException e) {
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   303
            return null;
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   304
        } catch (NoSuchMethodException e) {
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   305
            throw new AssertionError(e);
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   306
        }
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   307
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
4232
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   309
    /**
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   310
     * Invoke Timstamp getNanos.
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   311
     */
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   312
    private static int getNanos(Object obj) {
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   313
        if (getNanosMethod == null)
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   314
            throw new AssertionError("Should not get here");
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   315
        try {
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   316
            return (Integer)getNanosMethod.invoke(obj);
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   317
        } catch (InvocationTargetException e) {
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   318
            Throwable cause = e.getCause();
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   319
            if (cause instanceof RuntimeException)
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   320
                throw (RuntimeException)cause;
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   321
            if (cause instanceof Error)
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   322
                throw (Error)cause;
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   323
            throw new AssertionError(e);
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   324
        } catch (IllegalAccessException iae) {
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   325
            throw new AssertionError(iae);
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   326
        }
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   327
    }
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   328
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   329
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   330
        // assumes oldInstance and newInstance are Timestamps
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   331
        int nanos = getNanos(oldInstance);
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   332
        if (nanos != getNanos(newInstance)) {
16c44c226bdc 6899147: java.beans.MetaData should not require JDBC to be present
alanb
parents: 3476
diff changeset
   333
            out.writeStatement(new Statement(oldInstance, "setNanos", new Object[] {nanos}));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
// Collections
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
The Hashtable and AbstractMap classes have no common ancestor yet may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
be handled with a single persistence delegate: one which uses the methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
of the Map insterface exclusively. Attatching the persistence delegates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
to the interfaces themselves is fraught however since, in the case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
the Map, both the AbstractMap and HashMap classes are declared to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
implement the Map interface, leaving the obvious implementation prone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
to repeating their initialization. These issues and questions around
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
the ordering of delegates attached to interfaces have lead us to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
ignore any delegates attached to interfaces and force all persistence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
delegates to be registered with concrete classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
 * The base class for persistence delegates for inner classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
 * that can be created using {@link Collections}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
 * @author Sergey A. Malenkov
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
 */
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   359
private static abstract class java_util_Collections extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        if (!super.mutatesTo(oldInstance, newInstance)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if ((oldInstance instanceof List) || (oldInstance instanceof Set) || (oldInstance instanceof Map)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            return oldInstance.equals(newInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   367
        Collection<?> oldC = (Collection<?>) oldInstance;
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   368
        Collection<?> newC = (Collection<?>) newInstance;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return (oldC.size() == newC.size()) && oldC.containsAll(newC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   372
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   373
        // do not initialize these custom collections in default way
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   374
    }
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   375
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    static final class EmptyList_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            return new Expression(oldInstance, Collections.class, "emptyList", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    static final class EmptySet_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            return new Expression(oldInstance, Collections.class, "emptySet", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    static final class EmptyMap_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            return new Expression(oldInstance, Collections.class, "emptyMap", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    static final class SingletonList_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   396
            List<?> list = (List<?>) oldInstance;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            return new Expression(oldInstance, Collections.class, "singletonList", new Object[]{list.get(0)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    static final class SingletonSet_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   403
            Set<?> set = (Set<?>) oldInstance;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            return new Expression(oldInstance, Collections.class, "singleton", new Object[]{set.iterator().next()});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    static final class SingletonMap_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   410
            Map<?,?> map = (Map<?,?>) oldInstance;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            Object key = map.keySet().iterator().next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            return new Expression(oldInstance, Collections.class, "singletonMap", new Object[]{key, map.get(key)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    static final class UnmodifiableCollection_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   418
            List<?> list = new ArrayList<>((Collection<?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            return new Expression(oldInstance, Collections.class, "unmodifiableCollection", new Object[]{list});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    static final class UnmodifiableList_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   425
            List<?> list = new LinkedList<>((Collection<?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            return new Expression(oldInstance, Collections.class, "unmodifiableList", new Object[]{list});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    static final class UnmodifiableRandomAccessList_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   432
            List<?> list = new ArrayList<>((Collection<?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            return new Expression(oldInstance, Collections.class, "unmodifiableList", new Object[]{list});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    static final class UnmodifiableSet_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   439
            Set<?> set = new HashSet<>((Set<?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            return new Expression(oldInstance, Collections.class, "unmodifiableSet", new Object[]{set});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    static final class UnmodifiableSortedSet_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   446
            SortedSet<?> set = new TreeSet<>((SortedSet<?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            return new Expression(oldInstance, Collections.class, "unmodifiableSortedSet", new Object[]{set});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    static final class UnmodifiableMap_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   453
            Map<?,?> map = new HashMap<>((Map<?,?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            return new Expression(oldInstance, Collections.class, "unmodifiableMap", new Object[]{map});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    static final class UnmodifiableSortedMap_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   460
            SortedMap<?,?> map = new TreeMap<>((SortedMap<?,?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            return new Expression(oldInstance, Collections.class, "unmodifiableSortedMap", new Object[]{map});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    static final class SynchronizedCollection_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   467
            List<?> list = new ArrayList<>((Collection<?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            return new Expression(oldInstance, Collections.class, "synchronizedCollection", new Object[]{list});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    static final class SynchronizedList_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   474
            List<?> list = new LinkedList<>((Collection<?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            return new Expression(oldInstance, Collections.class, "synchronizedList", new Object[]{list});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    static final class SynchronizedRandomAccessList_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   481
            List<?> list = new ArrayList<>((Collection<?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            return new Expression(oldInstance, Collections.class, "synchronizedList", new Object[]{list});
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
    static final class SynchronizedSet_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   488
            Set<?> set = new HashSet<>((Set<?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            return new Expression(oldInstance, Collections.class, "synchronizedSet", new Object[]{set});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    static final class SynchronizedSortedSet_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   495
            SortedSet<?> set = new TreeSet<>((SortedSet<?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            return new Expression(oldInstance, Collections.class, "synchronizedSortedSet", new Object[]{set});
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
    static final class SynchronizedMap_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   502
            Map<?,?> map = new HashMap<>((Map<?,?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            return new Expression(oldInstance, Collections.class, "synchronizedMap", new Object[]{map});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    static final class SynchronizedSortedMap_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        protected Expression instantiate(Object oldInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   509
            SortedMap<?,?> map = new TreeMap<>((SortedMap<?,?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            return new Expression(oldInstance, Collections.class, "synchronizedSortedMap", new Object[]{map});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    static final class CheckedCollection_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        protected Expression instantiate(Object oldInstance, Encoder out) {
3439
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
   516
            Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   517
            List<?> list = new ArrayList<>((Collection<?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            return new Expression(oldInstance, Collections.class, "checkedCollection", new Object[]{list, type});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    static final class CheckedList_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        protected Expression instantiate(Object oldInstance, Encoder out) {
3439
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
   524
            Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   525
            List<?> list = new LinkedList<>((Collection<?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            return new Expression(oldInstance, Collections.class, "checkedList", new Object[]{list, type});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    static final class CheckedRandomAccessList_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        protected Expression instantiate(Object oldInstance, Encoder out) {
3439
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
   532
            Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   533
            List<?> list = new ArrayList<>((Collection<?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            return new Expression(oldInstance, Collections.class, "checkedList", new Object[]{list, type});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    static final class CheckedSet_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        protected Expression instantiate(Object oldInstance, Encoder out) {
3439
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
   540
            Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   541
            Set<?> set = new HashSet<>((Set<?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            return new Expression(oldInstance, Collections.class, "checkedSet", new Object[]{set, type});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    static final class CheckedSortedSet_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        protected Expression instantiate(Object oldInstance, Encoder out) {
3439
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
   548
            Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   549
            SortedSet<?> set = new TreeSet<>((SortedSet<?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            return new Expression(oldInstance, Collections.class, "checkedSortedSet", new Object[]{set, type});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    static final class CheckedMap_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        protected Expression instantiate(Object oldInstance, Encoder out) {
3439
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
   556
            Object keyType   = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.keyType");
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
   557
            Object valueType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.valueType");
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   558
            Map<?,?> map = new HashMap<>((Map<?,?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            return new Expression(oldInstance, Collections.class, "checkedMap", new Object[]{map, keyType, valueType});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    static final class CheckedSortedMap_PersistenceDelegate extends java_util_Collections {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        protected Expression instantiate(Object oldInstance, Encoder out) {
3439
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
   565
            Object keyType   = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.keyType");
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
   566
            Object valueType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.valueType");
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   567
            SortedMap<?,?> map = new TreeMap<>((SortedMap<?,?>) oldInstance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            return new Expression(oldInstance, Collections.class, "checkedSortedMap", new Object[]{map, keyType, valueType});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
 * The persistence delegate for <CODE>java.util.EnumMap</CODE> classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
 * @author Sergey A. Malenkov
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
 */
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   578
static final class java_util_EnumMap_PersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        return super.mutatesTo(oldInstance, newInstance) && (getType(oldInstance) == getType(newInstance));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        return new Expression(oldInstance, EnumMap.class, "new", new Object[] {getType(oldInstance)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    private static Object getType(Object instance) {
3439
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
   588
        return MetaData.getPrivateFieldValue(instance, "java.util.EnumMap.keyType");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
 * The persistence delegate for <CODE>java.util.EnumSet</CODE> classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
 * @author Sergey A. Malenkov
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
 */
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   597
static final class java_util_EnumSet_PersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        return super.mutatesTo(oldInstance, newInstance) && (getType(oldInstance) == getType(newInstance));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        return new Expression(oldInstance, EnumSet.class, "noneOf", new Object[] {getType(oldInstance)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    private static Object getType(Object instance) {
3439
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
   607
        return MetaData.getPrivateFieldValue(instance, "java.util.EnumSet.elementType");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
// Collection
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   612
static class java_util_Collection_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   614
        java.util.Collection<?> oldO = (java.util.Collection)oldInstance;
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   615
        java.util.Collection<?> newO = (java.util.Collection)newInstance;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        if (newO.size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            invokeStatement(oldInstance, "clear", new Object[]{}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   620
        for (Iterator<?> i = oldO.iterator(); i.hasNext();) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            invokeStatement(oldInstance, "add", new Object[]{i.next()}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
// List
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   627
static class java_util_List_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   629
        java.util.List<?> oldO = (java.util.List<?>)oldInstance;
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   630
        java.util.List<?> newO = (java.util.List<?>)newInstance;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        int oldSize = oldO.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        int newSize = (newO == null) ? 0 : newO.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        if (oldSize < newSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            invokeStatement(oldInstance, "clear", new Object[]{}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            newSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        for (int i = 0; i < newSize; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            Object index = new Integer(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            Expression oldGetExp = new Expression(oldInstance, "get", new Object[]{index});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            Expression newGetExp = new Expression(newInstance, "get", new Object[]{index});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                Object oldValue = oldGetExp.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                Object newValue = newGetExp.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                out.writeExpression(oldGetExp);
9548
225dbdc1cb74 7041136: Use Objects.equals in JDK platform classes
darcy
parents: 7668
diff changeset
   646
                if (!Objects.equals(newValue, out.get(oldValue))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                    invokeStatement(oldInstance, "set", new Object[]{index, oldValue}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                out.getExceptionListener().exceptionThrown(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        for (int i = newSize; i < oldSize; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            invokeStatement(oldInstance, "add", new Object[]{oldO.get(i)}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
// Map
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   662
static class java_util_Map_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        // System.out.println("Initializing: " + newInstance);
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   665
        java.util.Map<?,?> oldMap = (java.util.Map)oldInstance;
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   666
        java.util.Map<?,?> newMap = (java.util.Map)newInstance;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        // Remove the new elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        // Do this first otherwise we undo the adding work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        if (newMap != null) {
1281
b2928adc218e 4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents: 1279
diff changeset
   670
            for (Object newKey : newMap.keySet().toArray()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
               // PENDING: This "key" is not in the right environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                if (!oldMap.containsKey(newKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                    invokeStatement(oldInstance, "remove", new Object[]{newKey}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        // Add the new elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        for ( Object oldKey : oldMap.keySet() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            Expression oldGetExp = new Expression(oldInstance, "get", new Object[]{oldKey});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            // Pending: should use newKey.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            Expression newGetExp = new Expression(newInstance, "get", new Object[]{oldKey});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                Object oldValue = oldGetExp.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                Object newValue = newGetExp.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                out.writeExpression(oldGetExp);
9548
225dbdc1cb74 7041136: Use Objects.equals in JDK platform classes
darcy
parents: 7668
diff changeset
   686
                if (!Objects.equals(newValue, out.get(oldValue))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                    invokeStatement(oldInstance, "put", new Object[]{oldKey, oldValue}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                } else if ((newValue == null) && !newMap.containsKey(oldKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                    // put oldValue(=null?) if oldKey is absent in newMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                    invokeStatement(oldInstance, "put", new Object[]{oldKey, oldValue}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                out.getExceptionListener().exceptionThrown(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   700
static final class java_util_AbstractCollection_PersistenceDelegate extends java_util_Collection_PersistenceDelegate {}
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   701
static final class java_util_AbstractList_PersistenceDelegate extends java_util_List_PersistenceDelegate {}
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   702
static final class java_util_AbstractMap_PersistenceDelegate extends java_util_Map_PersistenceDelegate {}
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   703
static final class java_util_Hashtable_PersistenceDelegate extends java_util_Map_PersistenceDelegate {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
// Beans
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   707
static final class java_beans_beancontext_BeanContextSupport_PersistenceDelegate extends java_util_Collection_PersistenceDelegate {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
// AWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
 * The persistence delegate for {@link Insets}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
 * It is impossible to use {@link DefaultPersistenceDelegate}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
 * because this class does not have any properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
 * @author Sergey A. Malenkov
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
 */
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   718
static final class java_awt_Insets_PersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        return oldInstance.equals(newInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        Insets insets = (Insets) oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        Object[] args = new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                insets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                insets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                insets.bottom,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                insets.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        return new Expression(insets, insets.getClass(), "new", args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
 * The persistence delegate for {@link Font}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
 * It is impossible to use {@link DefaultPersistenceDelegate}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
 * because size of the font can be float value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
 * @author Sergey A. Malenkov
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
 */
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   742
static final class java_awt_Font_PersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        return oldInstance.equals(newInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        Font font = (Font) oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        String family = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        int style = Font.PLAIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        int size = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   755
        Map<TextAttribute, ?> basic = font.getAttributes();
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   756
        Map<TextAttribute, Object> clone = new HashMap<>(basic.size());
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   757
        for (TextAttribute key : basic.keySet()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            Object value = basic.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                clone.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            if (key == TextAttribute.FAMILY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                if (value instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                    family = (String) value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            else if (key == TextAttribute.WEIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                if (TextAttribute.WEIGHT_REGULAR.equals(value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                } else if (TextAttribute.WEIGHT_BOLD.equals(value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                    style |= Font.BOLD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            else if (key == TextAttribute.POSTURE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                if (TextAttribute.POSTURE_REGULAR.equals(value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                } else if (TextAttribute.POSTURE_OBLIQUE.equals(value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                    style |= Font.ITALIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            } else if (key == TextAttribute.SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                if (value instanceof Number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                    Number number = (Number) value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                    size = number.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                    if (size == number.floatValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                        count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        }
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   793
        Class<?> type = font.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        if (count == clone.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            return new Expression(font, type, "new", new Object[]{family, style, size});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        if (type == Font.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            return new Expression(font, type, "getFont", new Object[]{clone});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        return new Expression(font, type, "new", new Object[]{Font.getFont(clone)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
 * The persistence delegate for {@link AWTKeyStroke}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
 * It is impossible to use {@link DefaultPersistenceDelegate}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
 * because this class have no public constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
 * @author Sergey A. Malenkov
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
 */
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   811
static final class java_awt_AWTKeyStroke_PersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        return oldInstance.equals(newInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        AWTKeyStroke key = (AWTKeyStroke) oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        char ch = key.getKeyChar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        int code = key.getKeyCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        int mask = key.getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        boolean onKeyRelease = key.isOnKeyRelease();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        Object[] args = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        if (ch == KeyEvent.CHAR_UNDEFINED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            args = !onKeyRelease
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                    ? new Object[]{code, mask}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                    : new Object[]{code, mask, onKeyRelease};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        } else if (code == KeyEvent.VK_UNDEFINED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            if (!onKeyRelease) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                args = (mask == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                        ? new Object[]{ch}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                        : new Object[]{ch, mask};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            } else if (mask == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                args = new Object[]{ch, onKeyRelease};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        if (args == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            throw new IllegalStateException("Unsupported KeyStroke: " + key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        }
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
   841
        Class<?> type = key.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        String name = type.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        // get short name of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        int index = name.lastIndexOf('.') + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        if (index > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            name = name.substring(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        return new Expression( key, type, "get" + name, args );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   852
static class StaticFieldsPersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    protected void installFields(Encoder out, Class<?> cls) {
20802
758273542f3d 8012071: Better Building of Beans
malenkov
parents: 17148
diff changeset
   854
        if (Modifier.isPublic(cls.getModifiers()) && isPackageAccessible(cls)) {
758273542f3d 8012071: Better Building of Beans
malenkov
parents: 17148
diff changeset
   855
            Field fields[] = cls.getFields();
758273542f3d 8012071: Better Building of Beans
malenkov
parents: 17148
diff changeset
   856
            for(int i = 0; i < fields.length; i++) {
758273542f3d 8012071: Better Building of Beans
malenkov
parents: 17148
diff changeset
   857
                Field field = fields[i];
758273542f3d 8012071: Better Building of Beans
malenkov
parents: 17148
diff changeset
   858
                // Don't install primitives, their identity will not be preserved
758273542f3d 8012071: Better Building of Beans
malenkov
parents: 17148
diff changeset
   859
                // by wrapping.
758273542f3d 8012071: Better Building of Beans
malenkov
parents: 17148
diff changeset
   860
                if (Object.class.isAssignableFrom(field.getType())) {
758273542f3d 8012071: Better Building of Beans
malenkov
parents: 17148
diff changeset
   861
                    out.writeExpression(new Expression(field, "get", new Object[]{null}));
758273542f3d 8012071: Better Building of Beans
malenkov
parents: 17148
diff changeset
   862
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        throw new RuntimeException("Unrecognized instance: " + oldInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    public void writeObject(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        if (out.getAttribute(this) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            out.setAttribute(this, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            installFields(out, oldInstance.getClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        super.writeObject(oldInstance, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
// SystemColor
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   881
static final class java_awt_SystemColor_PersistenceDelegate extends StaticFieldsPersistenceDelegate {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
// TextAttribute
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   884
static final class java_awt_font_TextAttribute_PersistenceDelegate extends StaticFieldsPersistenceDelegate {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
// MenuShortcut
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   887
static final class java_awt_MenuShortcut_PersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        return oldInstance.equals(newInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        java.awt.MenuShortcut m = (java.awt.MenuShortcut)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        return new Expression(oldInstance, m.getClass(), "new",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                   new Object[]{new Integer(m.getKey()), Boolean.valueOf(m.usesShiftModifier())});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
// Component
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   900
static final class java_awt_Component_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        super.initialize(type, oldInstance, newInstance, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        java.awt.Component c = (java.awt.Component)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        java.awt.Component c2 = (java.awt.Component)newInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        // The "background", "foreground" and "font" properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        // The foreground and font properties of Windows change from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        // null to defined values after the Windows are made visible -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        // special case them for now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        if (!(oldInstance instanceof java.awt.Window)) {
1279
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
   910
            Object oldBackground = c.isBackgroundSet() ? c.getBackground() : null;
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
   911
            Object newBackground = c2.isBackgroundSet() ? c2.getBackground() : null;
9548
225dbdc1cb74 7041136: Use Objects.equals in JDK platform classes
darcy
parents: 7668
diff changeset
   912
            if (!Objects.equals(oldBackground, newBackground)) {
1279
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
   913
                invokeStatement(oldInstance, "setBackground", new Object[] { oldBackground }, out);
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
   914
            }
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
   915
            Object oldForeground = c.isForegroundSet() ? c.getForeground() : null;
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
   916
            Object newForeground = c2.isForegroundSet() ? c2.getForeground() : null;
9548
225dbdc1cb74 7041136: Use Objects.equals in JDK platform classes
darcy
parents: 7668
diff changeset
   917
            if (!Objects.equals(oldForeground, newForeground)) {
1279
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
   918
                invokeStatement(oldInstance, "setForeground", new Object[] { oldForeground }, out);
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
   919
            }
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
   920
            Object oldFont = c.isFontSet() ? c.getFont() : null;
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
   921
            Object newFont = c2.isFontSet() ? c2.getFont() : null;
9548
225dbdc1cb74 7041136: Use Objects.equals in JDK platform classes
darcy
parents: 7668
diff changeset
   922
            if (!Objects.equals(oldFont, newFont)) {
1279
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
   923
                invokeStatement(oldInstance, "setFont", new Object[] { oldFont }, out);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        // Bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        java.awt.Container p = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        if (p == null || p.getLayout() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            // Use the most concise construct.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            boolean locationCorrect = c.getLocation().equals(c2.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            boolean sizeCorrect = c.getSize().equals(c2.getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            if (!locationCorrect && !sizeCorrect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                invokeStatement(oldInstance, "setBounds", new Object[]{c.getBounds()}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            else if (!locationCorrect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                invokeStatement(oldInstance, "setLocation", new Object[]{c.getLocation()}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            else if (!sizeCorrect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                invokeStatement(oldInstance, "setSize", new Object[]{c.getSize()}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
// Container
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   947
static final class java_awt_Container_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        super.initialize(type, oldInstance, newInstance, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        // Ignore the children of a JScrollPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        // Pending(milne) find a better way to do this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        if (oldInstance instanceof javax.swing.JScrollPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        java.awt.Container oldC = (java.awt.Container)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        java.awt.Component[] oldChildren = oldC.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        java.awt.Container newC = (java.awt.Container)newInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        java.awt.Component[] newChildren = (newC == null) ? new java.awt.Component[0] : newC.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        BorderLayout layout = ( oldC.getLayout() instanceof BorderLayout )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                ? ( BorderLayout )oldC.getLayout()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        JLayeredPane oldLayeredPane = (oldInstance instanceof JLayeredPane)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                ? (JLayeredPane) oldInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        // Pending. Assume all the new children are unaltered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        for(int i = newChildren.length; i < oldChildren.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            Object[] args = ( layout != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                    ? new Object[] {oldChildren[i], layout.getConstraints( oldChildren[i] )}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                    : (oldLayeredPane != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                            ? new Object[] {oldChildren[i], oldLayeredPane.getLayer(oldChildren[i]), Integer.valueOf(-1)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                            : new Object[] {oldChildren[i]};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            invokeStatement(oldInstance, "add", args, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
// Choice
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   982
static final class java_awt_Choice_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        super.initialize(type, oldInstance, newInstance, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        java.awt.Choice m = (java.awt.Choice)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        java.awt.Choice n = (java.awt.Choice)newInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        for (int i = n.getItemCount(); i < m.getItemCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            invokeStatement(oldInstance, "add", new Object[]{m.getItem(i)}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
// Menu
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
   994
static final class java_awt_Menu_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        super.initialize(type, oldInstance, newInstance, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        java.awt.Menu m = (java.awt.Menu)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        java.awt.Menu n = (java.awt.Menu)newInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        for (int i = n.getItemCount(); i < m.getItemCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            invokeStatement(oldInstance, "add", new Object[]{m.getItem(i)}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
// MenuBar
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1006
static final class java_awt_MenuBar_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        super.initialize(type, oldInstance, newInstance, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        java.awt.MenuBar m = (java.awt.MenuBar)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        java.awt.MenuBar n = (java.awt.MenuBar)newInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        for (int i = n.getMenuCount(); i < m.getMenuCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            invokeStatement(oldInstance, "add", new Object[]{m.getMenu(i)}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
// List
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1018
static final class java_awt_List_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        super.initialize(type, oldInstance, newInstance, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        java.awt.List m = (java.awt.List)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        java.awt.List n = (java.awt.List)newInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        for (int i = n.getItemCount(); i < m.getItemCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            invokeStatement(oldInstance, "add", new Object[]{m.getItem(i)}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
// LayoutManagers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
// BorderLayout
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1033
static final class java_awt_BorderLayout_PersistenceDelegate extends DefaultPersistenceDelegate {
1279
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1034
    private static final String[] CONSTRAINTS = {
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1035
            BorderLayout.NORTH,
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1036
            BorderLayout.SOUTH,
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1037
            BorderLayout.EAST,
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1038
            BorderLayout.WEST,
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1039
            BorderLayout.CENTER,
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1040
            BorderLayout.PAGE_START,
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1041
            BorderLayout.PAGE_END,
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1042
            BorderLayout.LINE_START,
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1043
            BorderLayout.LINE_END,
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1044
    };
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1045
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    protected void initialize(Class<?> type, Object oldInstance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                              Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        super.initialize(type, oldInstance, newInstance, out);
1279
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1049
        BorderLayout oldLayout = (BorderLayout) oldInstance;
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1050
        BorderLayout newLayout = (BorderLayout) newInstance;
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1051
        for (String constraints : CONSTRAINTS) {
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1052
            Object oldC = oldLayout.getLayoutComponent(constraints);
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1053
            Object newC = newLayout.getLayoutComponent(constraints);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            // Pending, assume any existing elements are OK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            if (oldC != null && newC == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                invokeStatement(oldInstance, "addLayoutComponent",
1279
09ac82fafd79 4916852: RFE: LTP: BorderLayout Persistence Delegate should use 1.5 API
malenkov
parents: 466
diff changeset
  1057
                                new Object[] { oldC, constraints }, out);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
// CardLayout
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1064
static final class java_awt_CardLayout_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    protected void initialize(Class<?> type, Object oldInstance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                              Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        super.initialize(type, oldInstance, newInstance, out);
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1068
        if (getVector(newInstance).isEmpty()) {
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1069
            for (Object card : getVector(oldInstance)) {
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1070
                Object[] args = {MetaData.getPrivateFieldValue(card, "java.awt.CardLayout$Card.name"),
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1071
                                 MetaData.getPrivateFieldValue(card, "java.awt.CardLayout$Card.comp")};
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1072
                invokeStatement(oldInstance, "addLayoutComponent", args, out);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    }
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1076
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1077
        return super.mutatesTo(oldInstance, newInstance) && getVector(newInstance).isEmpty();
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1078
    }
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1079
    private static Vector<?> getVector(Object instance) {
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1080
        return (Vector<?>) MetaData.getPrivateFieldValue(instance, "java.awt.CardLayout.vector");
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1081
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
// GridBagLayout
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1085
static final class java_awt_GridBagLayout_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    protected void initialize(Class<?> type, Object oldInstance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                              Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        super.initialize(type, oldInstance, newInstance, out);
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1089
        if (getHashtable(newInstance).isEmpty()) {
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1090
            for (Map.Entry<?,?> entry : getHashtable(oldInstance).entrySet()) {
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1091
                Object[] args = {entry.getKey(), entry.getValue()};
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1092
                invokeStatement(oldInstance, "addLayoutComponent", args, out);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    }
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1096
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1097
        return super.mutatesTo(oldInstance, newInstance) && getHashtable(newInstance).isEmpty();
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1098
    }
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1099
    private static Hashtable<?,?> getHashtable(Object instance) {
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1100
        return (Hashtable<?,?>) MetaData.getPrivateFieldValue(instance, "java.awt.GridBagLayout.comptable");
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1101
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
// Swing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
// JFrame (If we do this for Window instead of JFrame, the setVisible call
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
// will be issued before we have added all the children to the JFrame and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
// will appear blank).
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1109
static final class javax_swing_JFrame_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        super.initialize(type, oldInstance, newInstance, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        java.awt.Window oldC = (java.awt.Window)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        java.awt.Window newC = (java.awt.Window)newInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        boolean oldV = oldC.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        boolean newV = newC.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        if (newV != oldV) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            // false means: don't execute this statement at write time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            boolean executeStatements = out.executeStatements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            out.executeStatements = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            invokeStatement(oldInstance, "setVisible", new Object[]{Boolean.valueOf(oldV)}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            out.executeStatements = executeStatements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
// Models
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
// DefaultListModel
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1129
static final class javax_swing_DefaultListModel_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        // Note, the "size" property will be set here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        super.initialize(type, oldInstance, newInstance, out);
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
  1133
        javax.swing.DefaultListModel<?> m = (javax.swing.DefaultListModel<?>)oldInstance;
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
  1134
        javax.swing.DefaultListModel<?> n = (javax.swing.DefaultListModel<?>)newInstance;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        for (int i = n.getSize(); i < m.getSize(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            invokeStatement(oldInstance, "add", // Can also use "addElement".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                    new Object[]{m.getElementAt(i)}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
// DefaultComboBoxModel
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1143
static final class javax_swing_DefaultComboBoxModel_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        super.initialize(type, oldInstance, newInstance, out);
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
  1146
        javax.swing.DefaultComboBoxModel<?> m = (javax.swing.DefaultComboBoxModel<?>)oldInstance;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        for (int i = 0; i < m.getSize(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            invokeStatement(oldInstance, "addElement", new Object[]{m.getElementAt(i)}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
// DefaultMutableTreeNode
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1155
static final class javax_swing_tree_DefaultMutableTreeNode_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    protected void initialize(Class<?> type, Object oldInstance, Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                              newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        super.initialize(type, oldInstance, newInstance, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        javax.swing.tree.DefaultMutableTreeNode m =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            (javax.swing.tree.DefaultMutableTreeNode)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        javax.swing.tree.DefaultMutableTreeNode n =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            (javax.swing.tree.DefaultMutableTreeNode)newInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        for (int i = n.getChildCount(); i < m.getChildCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            invokeStatement(oldInstance, "add", new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                Object[]{m.getChildAt(i)}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
// ToolTipManager
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1171
static final class javax_swing_ToolTipManager_PersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        return new Expression(oldInstance, javax.swing.ToolTipManager.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                              "sharedInstance", new Object[]{});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
// JTabbedPane
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1179
static final class javax_swing_JTabbedPane_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        super.initialize(type, oldInstance, newInstance, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        javax.swing.JTabbedPane p = (javax.swing.JTabbedPane)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        for (int i = 0; i < p.getTabCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            invokeStatement(oldInstance, "addTab",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                                          new Object[]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                                              p.getTitleAt(i),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                                              p.getIconAt(i),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                                              p.getComponentAt(i)}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
// Box
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1194
static final class javax_swing_Box_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        return super.mutatesTo(oldInstance, newInstance) && getAxis(oldInstance).equals(getAxis(newInstance));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        return new Expression(oldInstance, oldInstance.getClass(), "new", new Object[] {getAxis(oldInstance)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    private Integer getAxis(Object object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        Box box = (Box) object;
3439
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1205
        return (Integer) MetaData.getPrivateFieldValue(box.getLayout(), "javax.swing.BoxLayout.axis");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
// JMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
// Note that we do not need to state the initialiser for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
// JMenuItems since the getComponents() method defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
// Container will return all of the sub menu items that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
// need to be added to the menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
// Not so for JMenu apparently.
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1215
static final class javax_swing_JMenu_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        super.initialize(type, oldInstance, newInstance, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        javax.swing.JMenu m = (javax.swing.JMenu)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        java.awt.Component[] c = m.getMenuComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        for (int i = 0; i < c.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            invokeStatement(oldInstance, "add", new Object[]{c[i]}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
 * The persistence delegate for {@link MatteBorder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
 * It is impossible to use {@link DefaultPersistenceDelegate}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
 * because this class does not have writable properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
 * @author Sergey A. Malenkov
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
 */
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1233
static final class javax_swing_border_MatteBorder_PersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        MatteBorder border = (MatteBorder) oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        Insets insets = border.getBorderInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        Object object = border.getTileIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        if (object == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            object = border.getMatteColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        Object[] args = new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                insets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                insets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                insets.bottom,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                insets.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        return new Expression(border, border.getClass(), "new", args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
/* XXX - doens't seem to work. Debug later.
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1253
static final class javax_swing_JMenu_PersistenceDelegate extends DefaultPersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        super.initialize(type, oldInstance, newInstance, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        javax.swing.JMenu m = (javax.swing.JMenu)oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        javax.swing.JMenu n = (javax.swing.JMenu)newInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        for (int i = n.getItemCount(); i < m.getItemCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
            invokeStatement(oldInstance, "add", new Object[]{m.getItem(i)}, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
 * The persistence delegate for {@link PrintColorUIResource}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
 * It is impossible to use {@link DefaultPersistenceDelegate}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
 * because this class has special rule for serialization:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
 * it should be converted to {@link ColorUIResource}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
 * @see PrintColorUIResource#writeReplace
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
 * @author Sergey A. Malenkov
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
 */
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1275
static final class sun_swing_PrintColorUIResource_PersistenceDelegate extends PersistenceDelegate {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        return oldInstance.equals(newInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    protected Expression instantiate(Object oldInstance, Encoder out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        Color color = (Color) oldInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        Object[] args = new Object[] {color.getRGB()};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        return new Expression(color, ColorUIResource.class, "new", args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
3439
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1287
    private static final Map<String,Field> fields = Collections.synchronizedMap(new WeakHashMap<String, Field>());
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
  1288
    private static Hashtable<String, PersistenceDelegate> internalPersistenceDelegates = new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    private static PersistenceDelegate nullPersistenceDelegate = new NullPersistenceDelegate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    private static PersistenceDelegate enumPersistenceDelegate = new EnumPersistenceDelegate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    private static PersistenceDelegate primitivePersistenceDelegate = new PrimitivePersistenceDelegate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    private static PersistenceDelegate defaultPersistenceDelegate = new DefaultPersistenceDelegate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    private static PersistenceDelegate arrayPersistenceDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    private static PersistenceDelegate proxyPersistenceDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        internalPersistenceDelegates.put("java.net.URI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                                         new PrimitivePersistenceDelegate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        // it is possible because MatteBorder is assignable from MatteBorderUIResource
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
        internalPersistenceDelegates.put("javax.swing.plaf.BorderUIResource$MatteBorderUIResource",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                                         new javax_swing_border_MatteBorder_PersistenceDelegate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        // it is possible because FontUIResource is supported by java_awt_Font_PersistenceDelegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        internalPersistenceDelegates.put("javax.swing.plaf.FontUIResource",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                                         new java_awt_Font_PersistenceDelegate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        // it is possible because KeyStroke is supported by java_awt_AWTKeyStroke_PersistenceDelegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        internalPersistenceDelegates.put("javax.swing.KeyStroke",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                                         new java_awt_AWTKeyStroke_PersistenceDelegate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        internalPersistenceDelegates.put("java.sql.Date", new java_util_Date_PersistenceDelegate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        internalPersistenceDelegates.put("java.sql.Time", new java_util_Date_PersistenceDelegate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        internalPersistenceDelegates.put("java.util.JumboEnumSet", new java_util_EnumSet_PersistenceDelegate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        internalPersistenceDelegates.put("java.util.RegularEnumSet", new java_util_EnumSet_PersistenceDelegate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
  1321
    @SuppressWarnings("rawtypes")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
    public synchronized static PersistenceDelegate getPersistenceDelegate(Class type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        if (type == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            return nullPersistenceDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        if (Enum.class.isAssignableFrom(type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            return enumPersistenceDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        }
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1329
        if (null != XMLEncoder.primitiveTypeFor(type)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            return primitivePersistenceDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        // The persistence delegate for arrays is non-trivial; instantiate it lazily.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        if (type.isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            if (arrayPersistenceDelegate == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                arrayPersistenceDelegate = new ArrayPersistenceDelegate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            return arrayPersistenceDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        // Handle proxies lazily for backward compatibility with 1.2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            if (java.lang.reflect.Proxy.isProxyClass(type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                if (proxyPersistenceDelegate == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                    proxyPersistenceDelegate = new ProxyPersistenceDelegate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                return proxyPersistenceDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        catch(Exception e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        // else if (type.getDeclaringClass() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        //     return new DefaultPersistenceDelegate(new String[]{"this$0"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        // }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        String typeName = type.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        PersistenceDelegate pd = (PersistenceDelegate)getBeanAttribute(type, "persistenceDelegate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        if (pd == null) {
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
  1356
            pd = internalPersistenceDelegates.get(typeName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
            if (pd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
                return pd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            internalPersistenceDelegates.put(typeName, defaultPersistenceDelegate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                String name =  type.getName();
17148
bb5fff33bf49 8007458: [findbugs] One more beans issue, with ReflectionUtils
malenkov
parents: 11120
diff changeset
  1363
                Class c = Class.forName("java.beans.MetaData$" + name.replace('.', '_')
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                                        + "_PersistenceDelegate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                pd = (PersistenceDelegate)c.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                internalPersistenceDelegates.put(typeName, pd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
            catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                String[] properties = getConstructorProperties(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                if (properties != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                    pd = new DefaultPersistenceDelegate(properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                    internalPersistenceDelegates.put(typeName, pd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                System.err.println("Internal error: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        return (pd != null) ? pd : defaultPersistenceDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
  1383
    private static String[] getConstructorProperties(Class<?> type) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        String[] names = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        int length = 0;
268
aa06754a95de 6643627: JMX source code includes incorrect Java code
emcmanus
parents: 2
diff changeset
  1386
        for (Constructor<?> constructor : type.getConstructors()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            String[] value = getAnnotationValue(constructor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
            if ((value != null) && (length < value.length) && isValid(constructor, value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                names = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                length = value.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        return names;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
268
aa06754a95de 6643627: JMX source code includes incorrect Java code
emcmanus
parents: 2
diff changeset
  1396
    private static String[] getAnnotationValue(Constructor<?> constructor) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        ConstructorProperties annotation = constructor.getAnnotation(ConstructorProperties.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
        return (annotation != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                ? annotation.value()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
268
aa06754a95de 6643627: JMX source code includes incorrect Java code
emcmanus
parents: 2
diff changeset
  1403
    private static boolean isValid(Constructor<?> constructor, String[] names) {
25123
1f70b30da563 8042860: Fix raw and unchecked warnings in java.beans
darcy
parents: 23010
diff changeset
  1404
        Class<?>[] parameters = constructor.getParameterTypes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        if (names.length != parameters.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
        for (String name : names) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
11120
f8576c769572 7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents: 9548
diff changeset
  1416
    private static Object getBeanAttribute(Class<?> type, String attribute) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        try {
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 268
diff changeset
  1418
            return Introspector.getBeanInfo(type).getBeanDescriptor().getValue(attribute);
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 268
diff changeset
  1419
        } catch (IntrospectionException exception) {
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 268
diff changeset
  1420
            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
    }
3439
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1423
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1424
    static Object getPrivateFieldValue(Object instance, String name) {
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1425
        Field field = fields.get(name);
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1426
        if (field == null) {
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1427
            int index = name.lastIndexOf('.');
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1428
            final String className = name.substring(0, index);
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1429
            final String fieldName = name.substring(1 + index);
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1430
            field = AccessController.doPrivileged(new PrivilegedAction<Field>() {
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1431
                public Field run() {
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1432
                    try {
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1433
                        Field field = Class.forName(className).getDeclaredField(fieldName);
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1434
                        field.setAccessible(true);
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1435
                        return field;
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1436
                    }
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1437
                    catch (ClassNotFoundException exception) {
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1438
                        throw new IllegalStateException("Could not find class", exception);
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1439
                    }
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1440
                    catch (NoSuchFieldException exception) {
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1441
                        throw new IllegalStateException("Could not find field", exception);
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1442
                    }
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1443
                }
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1444
            });
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1445
            fields.put(name, field);
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1446
        }
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1447
        try {
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1448
            return field.get(instance);
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1449
        }
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1450
        catch (IllegalAccessException exception) {
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1451
            throw new IllegalStateException("Could not get value of the field", exception);
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1452
        }
4a7dc61594ac 6777487: Encoder allows reading private variables with certain names
malenkov
parents: 1844
diff changeset
  1453
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
}