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