corba/src/share/classes/com/sun/corba/se/impl/orbutil/ObjectStreamClass_1_3_1.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
child 16139 db11907a8b7f
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
 * Licensed Materials - Property of IBM
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
 * RMI-IIOP v1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 * Copyright IBM Corp. 1998 1999  All Rights Reserved
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
package com.sun.corba.se.impl.orbutil;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import java.security.MessageDigest;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import java.security.NoSuchAlgorithmException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import java.security.DigestOutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import java.security.AccessController;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import java.security.PrivilegedExceptionAction;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import java.security.PrivilegedActionException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import java.security.PrivilegedAction;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import java.lang.reflect.Modifier;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import java.lang.reflect.Array;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import java.lang.reflect.Field;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import java.lang.reflect.Member;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import java.lang.reflect.Method;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import java.lang.reflect.Constructor;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import java.lang.reflect.Proxy;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import java.lang.reflect.InvocationTargetException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import java.io.DataOutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
import java.io.ByteArrayOutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
import java.io.InvalidClassException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
import java.io.Serializable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
import java.util.Arrays;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
import java.util.Comparator;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
import org.omg.CORBA.ValueMember;
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
import com.sun.corba.se.impl.io.ValueUtility;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
import com.sun.corba.se.impl.io.ObjectStreamClass;
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
 * This is duplicated here to preserve the JDK 1.3.1FCS behavior
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
 * of calculating the OMG hash code incorrectly when serialPersistentFields
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
 * is used, but some of the fields no longer exist in the class itself.
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
 * We have to duplicate it since we aren't allowed to modify the
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
 * com.sun.corba.se.impl.io version further, and can't make it
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
 * public outside of its package for security reasons.
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
 * A ObjectStreamClass_1_3_1 describes a class that can be serialized to a stream
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
 * or a class that was serialized to a stream.  It contains the name
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
 * and the serialVersionUID of the class.
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
 * <br>
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
 * The ObjectStreamClass_1_3_1 for a specific class loaded in this Java VM can
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
 * be found using the lookup method.
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
 * @author  Roger Riggs
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
 * @since   JDK1.1
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
public class ObjectStreamClass_1_3_1 implements java.io.Serializable {
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
    public static final long kDefaultUID = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
    private static Object noArgsList[] = {};
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
    private static Class noTypesList[] = {};
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
    private static Hashtable translatedFields;
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
    /** Find the descriptor for a class that can be serialized.  Null
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
     * is returned if the specified class does not implement
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
     * java.io.Serializable or java.io.Externalizable.
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
    static final ObjectStreamClass_1_3_1 lookup(Class cl)
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
        ObjectStreamClass_1_3_1 desc = lookupInternal(cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
        if (desc.isSerializable() || desc.isExternalizable())
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
            return desc;
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
     * Find the class descriptor for the specified class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
     * Package access only so it can be called from ObjectIn/OutStream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
    static ObjectStreamClass_1_3_1 lookupInternal(Class cl)
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
        /* Synchronize on the hashtable so no two threads will do
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
         * this at the same time.
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
        ObjectStreamClass_1_3_1 desc = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
        synchronized (descriptorFor) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
            /* Find the matching descriptor if it already known */
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
            desc = findDescriptorFor(cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
            if (desc != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
                return desc;
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
                /* Check if it's serializable */
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
                boolean serializable = classSerializable.isAssignableFrom(cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
                /* If the class is only Serializable,
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
                 * lookup the descriptor for the superclass.
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
                 */
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
                ObjectStreamClass_1_3_1 superdesc = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
                if (serializable) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
                    Class superclass = cl.getSuperclass();
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
                    if (superclass != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
                        superdesc = lookup(superclass);
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
                /* Check if its' externalizable.
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
                 * If it's Externalizable, clear the serializable flag.
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
                 * Only one or the other may be set in the protocol.
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
                 */
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
                boolean externalizable = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
                if (serializable) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
                    externalizable =
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
                        ((superdesc != null) && superdesc.isExternalizable()) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
                        classExternalizable.isAssignableFrom(cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
                    if (externalizable) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
                        serializable = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
            /* Create a new version descriptor,
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
             * it put itself in the known table.
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
             */
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
            desc = new ObjectStreamClass_1_3_1(cl, superdesc,
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
                                         serializable, externalizable);
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
        desc.init();
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
        return desc;
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
     * The name of the class described by this descriptor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    public final String getName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
        return name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
     * Return the serialVersionUID for this class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
     * The serialVersionUID defines a set of classes all with the same name
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
     * that have evolved from a common root class and agree to be serialized
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
     * and deserialized using a common format.
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
    public static final long getSerialVersionUID( java.lang.Class clazz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
        ObjectStreamClass_1_3_1 theosc = ObjectStreamClass_1_3_1.lookup( clazz );
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
        if( theosc != null )
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
                return theosc.getSerialVersionUID( );
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
        return 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
     * Return the serialVersionUID for this class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
     * The serialVersionUID defines a set of classes all with the same name
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
     * that have evolved from a common root class and agree to be serialized
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
     * and deserialized using a common format.
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
    public final long getSerialVersionUID() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
        return suid;
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
     * Return the serialVersionUID string for this class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
     * The serialVersionUID defines a set of classes all with the same name
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
     * that have evolved from a common root class and agree to be serialized
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
     * and deserialized using a common format.
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
    public final String getSerialVersionUIDStr() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
        if (suidStr == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
            suidStr = Long.toHexString(suid).toUpperCase();
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
        return suidStr;
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
     * Return the actual (computed) serialVersionUID for this class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
    public static final long getActualSerialVersionUID( java.lang.Class clazz )
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
        ObjectStreamClass_1_3_1 theosc = ObjectStreamClass_1_3_1.lookup( clazz );
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
        if( theosc != null )
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
                return theosc.getActualSerialVersionUID( );
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
        return 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
     * Return the actual (computed) serialVersionUID for this class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
    public final long getActualSerialVersionUID() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
        return actualSuid;
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
     * Return the actual (computed) serialVersionUID for this class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
    public final String getActualSerialVersionUIDStr() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
        if (actualSuidStr == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
            actualSuidStr = Long.toHexString(actualSuid).toUpperCase();
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
        return actualSuidStr;
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
     * Return the class in the local VM that this version is mapped to.
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
     * Null is returned if there is no corresponding local class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
    public final Class forClass() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
        return ofClass;
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
     * Return an array of the fields of this serializable class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
     * @return an array containing an element for each persistent
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
     * field of this class. Returns an array of length zero if
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
     * there are no fields.
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
     * @since JDK1.2
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
    public ObjectStreamField[] getFields() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
        // Return a copy so the caller can't change the fields.
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
        if (fields.length > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
            ObjectStreamField[] dup = new ObjectStreamField[fields.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
            System.arraycopy(fields, 0, dup, 0, fields.length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
            return dup;
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
            return fields;
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
    public boolean hasField(ValueMember field){
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
        for (int i = 0; i < fields.length; i++){
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
            try{
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
                if (fields[i].getName().equals(field.name)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
                    if (fields[i].getSignature().equals(ValueUtility.getSignature(field)))
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
                        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
            catch(Throwable t){}
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
    /* Avoid unnecessary allocations. */
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
    final ObjectStreamField[] getFieldsNoCopy() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
        return fields;
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
     * Get the field of this class by name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
     * @return The ObjectStreamField object of the named field or null if there
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
     * is no such named field.
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
    public final ObjectStreamField getField(String name) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
        /* Binary search of fields by name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
        for (int i = fields.length-1; i >= 0; i--) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
            if (name.equals(fields[i].getName())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
                return fields[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
    public Serializable writeReplace(Serializable value) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
        if (writeReplaceObjectMethod != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
                return (Serializable) writeReplaceObjectMethod.invoke(value,noArgsList);
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
            catch(Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
                throw new RuntimeException(t.getMessage());
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
        else return value;
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
    public Object readResolve(Object value) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
        if (readResolveObjectMethod != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
                return readResolveObjectMethod.invoke(value,noArgsList);
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
            catch(Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
                throw new RuntimeException(t.getMessage());
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
        else return value;
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
     * Return a string describing this ObjectStreamClass_1_3_1.
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
    public final String toString() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
        StringBuffer sb = new StringBuffer();
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
        sb.append(name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
        sb.append(": static final long serialVersionUID = ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
        sb.append(Long.toString(suid));
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
        sb.append("L;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
        return sb.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
     * Create a new ObjectStreamClass_1_3_1 from a loaded class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
     * Don't call this directly, call lookup instead.
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
    private ObjectStreamClass_1_3_1(java.lang.Class cl, ObjectStreamClass_1_3_1 superdesc,
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
                              boolean serial, boolean extern)
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
        ofClass = cl;           /* created from this class */
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
        if (Proxy.isProxyClass(cl)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
            forProxyClass = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
        name = cl.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
        superclass = superdesc;
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
        serializable = serial;
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
        if (!forProxyClass) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
            // proxy classes are never externalizable
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
            externalizable = extern;
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
        /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
         * Enter this class in the table of known descriptors.
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
         * Otherwise, when the fields are read it may recurse
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
         * trying to find the descriptor for itself.
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
        insertDescriptorFor(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
        /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
         * The remainder of initialization occurs in init(), which is called
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
         * after the lock on the global class descriptor table has been
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
         * released.
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
     * Initialize class descriptor.  This method is only invoked on class
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
     * descriptors created via calls to lookupInternal().  This method is kept
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
     * separate from the ObjectStreamClass_1_3_1 constructor so that lookupInternal
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
     * does not have to hold onto a global class descriptor table lock while the
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
     * class descriptor is being initialized (see bug 4165204).
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
    private void init() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
      synchronized (lock) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
        final Class cl = ofClass;
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
        if (fields != null) // already initialized
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
                return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
        if (!serializable ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
            externalizable ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
            forProxyClass ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
            name.equals("java.lang.String")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
            fields = NO_FIELDS;
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
        } else if (serializable) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
            /* Ask for permission to override field access checks.
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
             */
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
            AccessController.doPrivileged(new PrivilegedAction() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
                public Object run() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
                /* Fill in the list of persistent fields.
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
                 * If it is declared, use the declared serialPersistentFields.
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
                 * Otherwise, extract the fields from the class itself.
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
                 */
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
                    Field pf = cl.getDeclaredField("serialPersistentFields");
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
                    // serial bug 7; the serialPersistentFields were not
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
                    // being read and stored as Accessible bit was not set
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
                    pf.setAccessible(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
                    // serial bug 7; need to find if the field is of type
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
                    // java.io.ObjectStreamField
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
                    java.io.ObjectStreamField[] f =
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
                           (java.io.ObjectStreamField[])pf.get(cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
                    int mods = pf.getModifiers();
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
                    if ((Modifier.isPrivate(mods)) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
                        (Modifier.isStatic(mods)) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
                        (Modifier.isFinal(mods)))
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
                    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
                        fields = (ObjectStreamField[])translateFields((Object[])pf.get(cl));
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
                } catch (NoSuchFieldException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
                    fields = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
                } catch (IllegalAccessException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
                    fields = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
                } catch (IllegalArgumentException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
                    fields = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
                } catch (ClassCastException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
                    /* Thrown if a field serialPersistentField exists
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
                     * but it is not of type ObjectStreamField.
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
                     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
                    fields = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
                if (fields == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
                    /* Get all of the declared fields for this
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
                     * Class. setAccessible on all fields so they
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
                     * can be accessed later.  Create a temporary
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
                     * ObjectStreamField array to hold each
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
                     * non-static, non-transient field. Then copy the
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
                     * temporary array into an array of the correct
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
                     * size once the number of fields is known.
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
                     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
                    Field[] actualfields = cl.getDeclaredFields();
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
                    int numFields = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
                    ObjectStreamField[] tempFields =
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
                        new ObjectStreamField[actualfields.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
                    for (int i = 0; i < actualfields.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
                        int modifiers = actualfields[i].getModifiers();
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
                        if (!Modifier.isStatic(modifiers) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
                            !Modifier.isTransient(modifiers)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
                            tempFields[numFields++] =
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
                                new ObjectStreamField(actualfields[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
                    fields = new ObjectStreamField[numFields];
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
                    System.arraycopy(tempFields, 0, fields, 0, numFields);
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
                    // For each declared persistent field, look for an actual
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
                    // reflected Field. If there is one, make sure it's the correct
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
                    // type and cache it in the ObjectStreamClass_1_3_1 for that field.
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
                    for (int j = fields.length-1; j >= 0; j--) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
                        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
                            Field reflField = cl.getDeclaredField(fields[j].getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
                            if (fields[j].getType() == reflField.getType()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
                                // reflField.setAccessible(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
                                fields[j].setField(reflField);
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
                        } catch (NoSuchFieldException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
                            // Nothing to do
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
                return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
            });
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
            if (fields.length > 1)
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
                Arrays.sort(fields);
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
            /* Set up field data for use while writing using the API api. */
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
            computeFieldInfo();
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
        /* Get the serialVersionUID from the class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
         * It uses the access override mechanism so make sure
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
         * the field objects is only used here.
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
         *
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
         * NonSerializable classes have a serialVerisonUID of 0L.
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
         if (isNonSerializable()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
             suid = 0L;
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
         } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
             // Lookup special Serializable members using reflection.
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
             AccessController.doPrivileged(new PrivilegedAction() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
                public Object run() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
                if (forProxyClass) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
                    // proxy classes always have serialVersionUID of 0L
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
                    suid = 0L;
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
                        final Field f = cl.getDeclaredField("serialVersionUID");
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
                        int mods = f.getModifiers();
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
                    // SerialBug 5:  static final SUID should be read
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
                        if (Modifier.isStatic(mods) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
                            Modifier.isFinal(mods) ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
                            f.setAccessible(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
                            suid = f.getLong(cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
                            // get rid of native code
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
                            // suid = getSerialVersionUIDField(cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
                    // SerialBug 2: should be computed after writeObject
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
                    // actualSuid = computeStructuralUID(cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
                        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
                            suid = ObjectStreamClass.getSerialVersionUID(cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
                            // SerialBug 2: should be computed after writeObject
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
                            // actualSuid = computeStructuralUID(cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
                    } catch (NoSuchFieldException ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
                        suid = ObjectStreamClass.getSerialVersionUID(cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
                        // SerialBug 2: should be computed after writeObject
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
                        // actualSuid = computeStructuralUID(cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
                    } catch (IllegalAccessException ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
                        suid = ObjectStreamClass.getSerialVersionUID(cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
                    writeReplaceObjectMethod = cl.getDeclaredMethod("writeReplace", noTypesList);
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
                    if (Modifier.isStatic(writeReplaceObjectMethod.getModifiers())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
                        writeReplaceObjectMethod = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
                        writeReplaceObjectMethod.setAccessible(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
                } catch (NoSuchMethodException e2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
                    readResolveObjectMethod = cl.getDeclaredMethod("readResolve", noTypesList);
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
                    if (Modifier.isStatic(readResolveObjectMethod.getModifiers())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
                       readResolveObjectMethod = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
                       readResolveObjectMethod.setAccessible(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
                } catch (NoSuchMethodException e2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
                /* Cache lookup of writeObject and readObject for
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
                 * Serializable classes. (Do not lookup for
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
                 * Externalizable)
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
                 */
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
                if (serializable && !forProxyClass) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
                    /* Look for the writeObject method
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
                     * Set the accessible flag on it here. ObjectOutputStream
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
                     * will call it as necessary.
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
                     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
                      Class[] args = {java.io.ObjectOutputStream.class};
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
                      writeObjectMethod = cl.getDeclaredMethod("writeObject", args);
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
                      hasWriteObjectMethod = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
                      int mods = writeObjectMethod.getModifiers();
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
                      // Method must be private and non-static
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
                      if (!Modifier.isPrivate(mods) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
                        Modifier.isStatic(mods)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
                        writeObjectMethod = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
                        hasWriteObjectMethod = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
                      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
                    } catch (NoSuchMethodException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
                    /* Look for the readObject method
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
                     * set the access override and save the reference for
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
                     * ObjectInputStream so it can all the method directly.
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
                     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
                      Class[] args = {java.io.ObjectInputStream.class};
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
                      readObjectMethod = cl.getDeclaredMethod("readObject", args);
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
                      int mods = readObjectMethod.getModifiers();
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
                      // Method must be private and non-static
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
                      if (!Modifier.isPrivate(mods) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
                        Modifier.isStatic(mods)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
                        readObjectMethod = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
                      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
                    } catch (NoSuchMethodException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
                    // Compute the structural UID.  This must be done after the
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
                    // calculation for writeObject.  Fixed 4/20/2000, eea1
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
                    // SerialBug 2: to have correct value in RepId
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
                return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
          });
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
        actualSuid = computeStructuralUID(this, cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
      }
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
     * Create an empty ObjectStreamClass_1_3_1 for a class about to be read.
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
     * This is separate from read so ObjectInputStream can assign the
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
     * wire handle early, before any nested ObjectStreamClass_1_3_1 might
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
     * be read.
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
    ObjectStreamClass_1_3_1(String n, long s) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
        name = n;
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
        suid = s;
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
        superclass = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
    private static Object[] translateFields(Object objs[])
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
        throws NoSuchFieldException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
        try{
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
            java.io.ObjectStreamField fields[] = (java.io.ObjectStreamField[])objs;
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
            Object translation[] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
            if (translatedFields == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
                translatedFields = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
            translation = (Object[])translatedFields.get(fields);
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
            if (translation != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
                return translation;
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
            else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
                Class osfClass = com.sun.corba.se.impl.orbutil.ObjectStreamField.class;
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
                translation = (Object[])java.lang.reflect.Array.newInstance(osfClass, objs.length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
                Object arg[] = new Object[2];
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
                Class types[] = {String.class, Class.class};
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
                Constructor constructor = osfClass.getDeclaredConstructor(types);
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
                for (int i = fields.length -1; i >= 0; i--){
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
                    arg[0] = fields[i].getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
                    arg[1] = fields[i].getType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
                    translation[i] = constructor.newInstance(arg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
                translatedFields.put(fields, translation);
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
            return (Object[])translation;
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
        catch(Throwable t){
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
            throw new NoSuchFieldException();
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
    /* Compare the base class names of streamName and localName.
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
     * @return  Return true iff the base class name compare.
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
     * @parameter streamName    Fully qualified class name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
     * @parameter localName     Fully qualified class name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
     * @parameter pkgSeparator  class names use either '.' or '/'.
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
     * Only compare base class name to allow package renaming.
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
    static boolean compareClassNames(String streamName,
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
                                     String localName,
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
                                     char pkgSeparator) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
        /* compare the class names, stripping off package names. */
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
        int streamNameIndex = streamName.lastIndexOf(pkgSeparator);
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
        if (streamNameIndex < 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
            streamNameIndex = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
        int localNameIndex = localName.lastIndexOf(pkgSeparator);
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
        if (localNameIndex < 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
            localNameIndex = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
        return streamName.regionMatches(false, streamNameIndex,
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
                                        localName, localNameIndex,
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
                                        streamName.length() - streamNameIndex);
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
     * Compare the types of two class descriptors.
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
     * They match if they have the same class name and suid
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
    final boolean typeEquals(ObjectStreamClass_1_3_1 other) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
        return (suid == other.suid) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
            compareClassNames(name, other.name, '.');
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
     * Return the superclass descriptor of this descriptor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
    final void setSuperclass(ObjectStreamClass_1_3_1 s) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
        superclass = s;
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
     * Return the superclass descriptor of this descriptor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
    final ObjectStreamClass_1_3_1 getSuperclass() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
        return superclass;
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
     * Return whether the class has a writeObject method
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
    final boolean hasWriteObject() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
        return hasWriteObjectMethod;
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
    final boolean isCustomMarshaled() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
        return (hasWriteObject() || isExternalizable());
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
     * Return true if all instances of 'this' Externalizable class
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
     * are written in block-data mode from the stream that 'this' was read
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
     * from. <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
     * In JDK 1.1, all Externalizable instances are not written
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
     * in block-data mode.
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
     * In JDK 1.2, all Externalizable instances, by default, are written
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
     * in block-data mode and the Externalizable instance is terminated with
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
     * tag TC_ENDBLOCKDATA. Change enabled the ability to skip Externalizable
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
     * instances.
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
     * IMPLEMENTATION NOTE:
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
     *   This should have been a mode maintained per stream; however,
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
     *   for compatibility reasons, it was only possible to record
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
     *   this change per class. All Externalizable classes within
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
     *   a given stream should either have this mode enabled or
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
     *   disabled. This is enforced by not allowing the PROTOCOL_VERSION
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
     *   of a stream to he changed after any objects have been written.
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
     * @see ObjectOutputStream#useProtocolVersion
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
     * @see ObjectStreamConstants#PROTOCOL_VERSION_1
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
     * @see ObjectStreamConstants#PROTOCOL_VERSION_2
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
     * @since JDK 1.2
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
    boolean hasExternalizableBlockDataMode() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
        return hasExternalizableBlockData;
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
     * Return the ObjectStreamClass_1_3_1 of the local class this one is based on.
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
    final ObjectStreamClass_1_3_1 localClassDescriptor() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
        return localClassDesc;
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
     * Get the Serializability of the class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
    boolean isSerializable() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
        return serializable;
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
     * Get the externalizability of the class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
    boolean isExternalizable() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
        return externalizable;
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
    boolean isNonSerializable() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
        return ! (externalizable || serializable);
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
     * Calculate the size of the array needed to store primitive data and the
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
     * number of object references to read when reading from the input
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
     * stream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
    private void computeFieldInfo() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
        primBytes = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
        objFields = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
        for (int i = 0; i < fields.length; i++ ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
            switch (fields[i].getTypeCode()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
            case 'B':
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
            case 'Z':
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
                primBytes += 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
            case 'C':
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
            case 'S':
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
                primBytes += 2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
            case 'I':
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
            case 'F':
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
                primBytes += 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
            case 'J':
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
            case 'D' :
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
                primBytes += 8;
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
            case 'L':
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
            case '[':
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
                objFields += 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
    private static long computeStructuralUID(ObjectStreamClass_1_3_1 osc, Class cl) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
        ByteArrayOutputStream devnull = new ByteArrayOutputStream(512);
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
        long h = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
            if ((!java.io.Serializable.class.isAssignableFrom(cl)) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
                (cl.isInterface())){
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
                return 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
            if (java.io.Externalizable.class.isAssignableFrom(cl)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
                return 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
            MessageDigest md = MessageDigest.getInstance("SHA");
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
            DigestOutputStream mdo = new DigestOutputStream(devnull, md);
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
            DataOutputStream data = new DataOutputStream(mdo);
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
            // Get SUID of parent
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
            Class parent = cl.getSuperclass();
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
            if ((parent != null))
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
            // SerialBug 1; acc. to spec the one for
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
            // java.lang.object
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
            // should be computed and put
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
            //     && (parent != java.lang.Object.class))
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
                                //data.writeLong(computeSerialVersionUID(null,parent));
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
                data.writeLong(computeStructuralUID(lookup(parent), parent));
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
            if (osc.hasWriteObject())
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
                data.writeInt(2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
                data.writeInt(1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
            /* Sort the field names to get a deterministic order */
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
            // Field[] field = ObjectStreamClass_1_3_1.getDeclaredFields(cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
            ObjectStreamField[] fields = osc.getFields();
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
            // Must make sure that the Field array we allocate
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
            // below is exactly the right size.  Bug fix for
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
            // 4397133.
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
            int numNonNullFields = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
            for (int i = 0; i < fields.length; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
                if (fields[i].getField() != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
                    numNonNullFields++;
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
            Field [] field = new java.lang.reflect.Field[numNonNullFields];
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
            for (int i = 0, fieldNum = 0; i < fields.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
                if (fields[i].getField() != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
                    field[fieldNum++] = fields[i].getField();
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
02bb8761fcce Initial load
duke
parents:
diff changeset
   863
            if (field.length > 1)
02bb8761fcce Initial load
duke
parents:
diff changeset
   864
                Arrays.sort(field, compareMemberByName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   865
02bb8761fcce Initial load
duke
parents:
diff changeset
   866
            for (int i = 0; i < field.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   867
                Field f = field[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   868
02bb8761fcce Initial load
duke
parents:
diff changeset
   869
                                /* Include in the hash all fields except those that are
02bb8761fcce Initial load
duke
parents:
diff changeset
   870
                                 * transient
02bb8761fcce Initial load
duke
parents:
diff changeset
   871
                                 */
02bb8761fcce Initial load
duke
parents:
diff changeset
   872
                int m = f.getModifiers();
02bb8761fcce Initial load
duke
parents:
diff changeset
   873
                //Serial 6
02bb8761fcce Initial load
duke
parents:
diff changeset
   874
                //if (Modifier.isTransient(m) || Modifier.isStatic(m))
02bb8761fcce Initial load
duke
parents:
diff changeset
   875
                // spec reference 00-01-06.pdf, 1.3.5.6, states non-static
02bb8761fcce Initial load
duke
parents:
diff changeset
   876
                // non-transient, public fields are mapped to Java IDL.
02bb8761fcce Initial load
duke
parents:
diff changeset
   877
                //
02bb8761fcce Initial load
duke
parents:
diff changeset
   878
                // Here's the quote from the first paragraph:
02bb8761fcce Initial load
duke
parents:
diff changeset
   879
                // Java non-static non-transient public fields are mapped to
02bb8761fcce Initial load
duke
parents:
diff changeset
   880
                // OMG IDL public data members, and other Java fields are
02bb8761fcce Initial load
duke
parents:
diff changeset
   881
                // not mapped.
02bb8761fcce Initial load
duke
parents:
diff changeset
   882
02bb8761fcce Initial load
duke
parents:
diff changeset
   883
                // if (Modifier.isTransient(m) || Modifier.isStatic(m))
02bb8761fcce Initial load
duke
parents:
diff changeset
   884
                //     continue;
02bb8761fcce Initial load
duke
parents:
diff changeset
   885
02bb8761fcce Initial load
duke
parents:
diff changeset
   886
                data.writeUTF(f.getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   887
                data.writeUTF(getSignature(f.getType()));
02bb8761fcce Initial load
duke
parents:
diff changeset
   888
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   889
02bb8761fcce Initial load
duke
parents:
diff changeset
   890
            /* Compute the hash value for this class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   891
             * Use only the first 64 bits of the hash.
02bb8761fcce Initial load
duke
parents:
diff changeset
   892
             */
02bb8761fcce Initial load
duke
parents:
diff changeset
   893
            data.flush();
02bb8761fcce Initial load
duke
parents:
diff changeset
   894
            byte hasharray[] = md.digest();
02bb8761fcce Initial load
duke
parents:
diff changeset
   895
            // int minimum = Math.min(8, hasharray.length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   896
            // SerialBug 3: SHA computation is wrong; for loop reversed
02bb8761fcce Initial load
duke
parents:
diff changeset
   897
            //for (int i = minimum; i > 0; i--)
02bb8761fcce Initial load
duke
parents:
diff changeset
   898
            for (int i = 0; i < Math.min(8, hasharray.length); i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   899
                h += (long)(hasharray[i] & 255) << (i * 8);
02bb8761fcce Initial load
duke
parents:
diff changeset
   900
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   901
        } catch (IOException ignore) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   902
            /* can't happen, but be deterministic anyway. */
02bb8761fcce Initial load
duke
parents:
diff changeset
   903
            h = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   904
        } catch (NoSuchAlgorithmException complain) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   905
            throw new SecurityException(complain.getMessage());
02bb8761fcce Initial load
duke
parents:
diff changeset
   906
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   907
        return h;
02bb8761fcce Initial load
duke
parents:
diff changeset
   908
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   909
02bb8761fcce Initial load
duke
parents:
diff changeset
   910
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   911
     * Compute the JVM signature for the class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   912
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   913
    static String getSignature(Class clazz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   914
        String type = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   915
        if (clazz.isArray()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   916
            Class cl = clazz;
02bb8761fcce Initial load
duke
parents:
diff changeset
   917
            int dimensions = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   918
            while (cl.isArray()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   919
                dimensions++;
02bb8761fcce Initial load
duke
parents:
diff changeset
   920
                cl = cl.getComponentType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   921
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   922
            StringBuffer sb = new StringBuffer();
02bb8761fcce Initial load
duke
parents:
diff changeset
   923
            for (int i = 0; i < dimensions; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   924
                sb.append("[");
02bb8761fcce Initial load
duke
parents:
diff changeset
   925
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   926
            sb.append(getSignature(cl));
02bb8761fcce Initial load
duke
parents:
diff changeset
   927
            type = sb.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   928
        } else if (clazz.isPrimitive()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   929
            if (clazz == Integer.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   930
                type = "I";
02bb8761fcce Initial load
duke
parents:
diff changeset
   931
            } else if (clazz == Byte.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   932
                type = "B";
02bb8761fcce Initial load
duke
parents:
diff changeset
   933
            } else if (clazz == Long.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   934
                type = "J";
02bb8761fcce Initial load
duke
parents:
diff changeset
   935
            } else if (clazz == Float.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   936
                type = "F";
02bb8761fcce Initial load
duke
parents:
diff changeset
   937
            } else if (clazz == Double.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   938
                type = "D";
02bb8761fcce Initial load
duke
parents:
diff changeset
   939
            } else if (clazz == Short.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   940
                type = "S";
02bb8761fcce Initial load
duke
parents:
diff changeset
   941
            } else if (clazz == Character.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   942
                type = "C";
02bb8761fcce Initial load
duke
parents:
diff changeset
   943
            } else if (clazz == Boolean.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   944
                type = "Z";
02bb8761fcce Initial load
duke
parents:
diff changeset
   945
            } else if (clazz == Void.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   946
                type = "V";
02bb8761fcce Initial load
duke
parents:
diff changeset
   947
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   948
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   949
            type = "L" + clazz.getName().replace('.', '/') + ";";
02bb8761fcce Initial load
duke
parents:
diff changeset
   950
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   951
        return type;
02bb8761fcce Initial load
duke
parents:
diff changeset
   952
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   953
02bb8761fcce Initial load
duke
parents:
diff changeset
   954
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   955
     * Compute the JVM method descriptor for the method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   956
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   957
    static String getSignature(Method meth) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   958
        StringBuffer sb = new StringBuffer();
02bb8761fcce Initial load
duke
parents:
diff changeset
   959
02bb8761fcce Initial load
duke
parents:
diff changeset
   960
        sb.append("(");
02bb8761fcce Initial load
duke
parents:
diff changeset
   961
02bb8761fcce Initial load
duke
parents:
diff changeset
   962
        Class[] params = meth.getParameterTypes(); // avoid clone
02bb8761fcce Initial load
duke
parents:
diff changeset
   963
        for (int j = 0; j < params.length; j++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   964
            sb.append(getSignature(params[j]));
02bb8761fcce Initial load
duke
parents:
diff changeset
   965
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   966
        sb.append(")");
02bb8761fcce Initial load
duke
parents:
diff changeset
   967
        sb.append(getSignature(meth.getReturnType()));
02bb8761fcce Initial load
duke
parents:
diff changeset
   968
        return sb.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   969
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   970
02bb8761fcce Initial load
duke
parents:
diff changeset
   971
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   972
     * Compute the JVM constructor descriptor for the constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   973
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   974
    static String getSignature(Constructor cons) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   975
        StringBuffer sb = new StringBuffer();
02bb8761fcce Initial load
duke
parents:
diff changeset
   976
02bb8761fcce Initial load
duke
parents:
diff changeset
   977
        sb.append("(");
02bb8761fcce Initial load
duke
parents:
diff changeset
   978
02bb8761fcce Initial load
duke
parents:
diff changeset
   979
        Class[] params = cons.getParameterTypes(); // avoid clone
02bb8761fcce Initial load
duke
parents:
diff changeset
   980
        for (int j = 0; j < params.length; j++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   981
            sb.append(getSignature(params[j]));
02bb8761fcce Initial load
duke
parents:
diff changeset
   982
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   983
        sb.append(")V");
02bb8761fcce Initial load
duke
parents:
diff changeset
   984
        return sb.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   985
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   986
02bb8761fcce Initial load
duke
parents:
diff changeset
   987
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   988
     * Cache of Class -> ClassDescriptor Mappings.
02bb8761fcce Initial load
duke
parents:
diff changeset
   989
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   990
    static private ObjectStreamClassEntry[] descriptorFor = new ObjectStreamClassEntry[61];
02bb8761fcce Initial load
duke
parents:
diff changeset
   991
02bb8761fcce Initial load
duke
parents:
diff changeset
   992
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   993
     * findDescriptorFor a Class.  This looks in the cache for a
02bb8761fcce Initial load
duke
parents:
diff changeset
   994
     * mapping from Class -> ObjectStreamClass mappings.  The hashCode
02bb8761fcce Initial load
duke
parents:
diff changeset
   995
     * of the Class is used for the lookup since the Class is the key.
02bb8761fcce Initial load
duke
parents:
diff changeset
   996
     * The entries are extended from java.lang.ref.SoftReference so the
02bb8761fcce Initial load
duke
parents:
diff changeset
   997
     * gc will be able to free them if needed.
02bb8761fcce Initial load
duke
parents:
diff changeset
   998
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   999
    private static ObjectStreamClass_1_3_1 findDescriptorFor(Class cl) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1000
02bb8761fcce Initial load
duke
parents:
diff changeset
  1001
        int hash = cl.hashCode();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1002
        int index = (hash & 0x7FFFFFFF) % descriptorFor.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1003
        ObjectStreamClassEntry e;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1004
        ObjectStreamClassEntry prev;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1005
02bb8761fcce Initial load
duke
parents:
diff changeset
  1006
        /* Free any initial entries whose refs have been cleared */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1007
        while ((e = descriptorFor[index]) != null && e.get() == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1008
            descriptorFor[index] = e.next;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1009
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1010
02bb8761fcce Initial load
duke
parents:
diff changeset
  1011
        /* Traverse the chain looking for a descriptor with ofClass == cl.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1012
         * unlink entries that are unresolved.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1013
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1014
        prev = e;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1015
        while (e != null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1016
            ObjectStreamClass_1_3_1 desc = (ObjectStreamClass_1_3_1)(e.get());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1017
            if (desc == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1018
                // This entry has been cleared,  unlink it
02bb8761fcce Initial load
duke
parents:
diff changeset
  1019
                prev.next = e.next;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1020
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1021
                if (desc.ofClass == cl)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1022
                    return desc;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1023
                prev = e;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1024
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1025
            e = e.next;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1026
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1027
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1028
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1029
02bb8761fcce Initial load
duke
parents:
diff changeset
  1030
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1031
     * insertDescriptorFor a Class -> ObjectStreamClass_1_3_1 mapping.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1032
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1033
    private static void insertDescriptorFor(ObjectStreamClass_1_3_1 desc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1034
        // Make sure not already present
02bb8761fcce Initial load
duke
parents:
diff changeset
  1035
        if (findDescriptorFor(desc.ofClass) != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1036
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1037
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1038
02bb8761fcce Initial load
duke
parents:
diff changeset
  1039
        int hash = desc.ofClass.hashCode();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1040
        int index = (hash & 0x7FFFFFFF) % descriptorFor.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1041
        ObjectStreamClassEntry e = new ObjectStreamClassEntry(desc);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1042
        e.next = descriptorFor[index];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1043
        descriptorFor[index] = e;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1044
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1045
02bb8761fcce Initial load
duke
parents:
diff changeset
  1046
    private static Field[] getDeclaredFields(final Class clz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1047
        return (Field[]) AccessController.doPrivileged(new PrivilegedAction() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1048
            public Object run() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1049
                return clz.getDeclaredFields();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1050
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1051
        });
02bb8761fcce Initial load
duke
parents:
diff changeset
  1052
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1053
02bb8761fcce Initial load
duke
parents:
diff changeset
  1054
02bb8761fcce Initial load
duke
parents:
diff changeset
  1055
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1056
     * The name of this descriptor
02bb8761fcce Initial load
duke
parents:
diff changeset
  1057
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1058
    private String name;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1059
02bb8761fcce Initial load
duke
parents:
diff changeset
  1060
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1061
     * The descriptor of the supertype.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1062
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1063
    private ObjectStreamClass_1_3_1 superclass;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1064
02bb8761fcce Initial load
duke
parents:
diff changeset
  1065
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1066
     * Flags for Serializable and Externalizable.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1067
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1068
    private boolean serializable;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1069
    private boolean externalizable;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1070
02bb8761fcce Initial load
duke
parents:
diff changeset
  1071
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1072
     * Array of persistent fields of this class, sorted by
02bb8761fcce Initial load
duke
parents:
diff changeset
  1073
     * type and name.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1074
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1075
    private ObjectStreamField[] fields;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1076
02bb8761fcce Initial load
duke
parents:
diff changeset
  1077
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1078
     * Class that is a descriptor for in this virtual machine.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1079
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1080
    private Class ofClass;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1081
02bb8761fcce Initial load
duke
parents:
diff changeset
  1082
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1083
     * True if descriptor for a proxy class.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1084
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1085
    boolean forProxyClass;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1086
02bb8761fcce Initial load
duke
parents:
diff changeset
  1087
02bb8761fcce Initial load
duke
parents:
diff changeset
  1088
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1089
     * SerialVersionUID for this class.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1090
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1091
    private long suid = kDefaultUID;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1092
    private String suidStr = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1093
02bb8761fcce Initial load
duke
parents:
diff changeset
  1094
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1095
     * Actual (computed) SerialVersionUID for this class.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1096
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1097
    private long actualSuid = kDefaultUID;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1098
    private String actualSuidStr = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1099
02bb8761fcce Initial load
duke
parents:
diff changeset
  1100
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1101
     * The total number of bytes of primitive fields.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1102
     * The total number of object fields.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1103
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1104
    int primBytes;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1105
    int objFields;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1106
02bb8761fcce Initial load
duke
parents:
diff changeset
  1107
    /* Internal lock object. */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1108
    private Object lock = new Object();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1109
02bb8761fcce Initial load
duke
parents:
diff changeset
  1110
    /* True if this class has/had a writeObject method */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1111
    private boolean hasWriteObjectMethod;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1112
02bb8761fcce Initial load
duke
parents:
diff changeset
  1113
    /* In JDK 1.1, external data was not written in block mode.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1114
     * As of JDK 1.2, external data is written in block data mode. This
02bb8761fcce Initial load
duke
parents:
diff changeset
  1115
     * flag enables JDK 1.2 to be able to read JDK 1.1 written external data.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1116
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1117
     * @since JDK 1.2
02bb8761fcce Initial load
duke
parents:
diff changeset
  1118
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1119
    private boolean hasExternalizableBlockData;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1120
    Method writeObjectMethod;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1121
    Method readObjectMethod;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1122
    private Method writeReplaceObjectMethod;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1123
    private Method readResolveObjectMethod;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1124
02bb8761fcce Initial load
duke
parents:
diff changeset
  1125
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1126
     * ObjectStreamClass_1_3_1 that this one was built from.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1127
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1128
    private ObjectStreamClass_1_3_1 localClassDesc;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1129
02bb8761fcce Initial load
duke
parents:
diff changeset
  1130
    /* Get the private static final field for serial version UID */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1131
    // private static native long getSerialVersionUIDField(Class cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1132
02bb8761fcce Initial load
duke
parents:
diff changeset
  1133
    /* The Class Object for java.io.Serializable */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1134
    private static Class classSerializable = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1135
    private static Class classExternalizable = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1136
02bb8761fcce Initial load
duke
parents:
diff changeset
  1137
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1138
     * Resolve java.io.Serializable at load time.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1139
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1140
    static {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1141
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1142
            classSerializable = Class.forName("java.io.Serializable");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1143
            classExternalizable = Class.forName("java.io.Externalizable");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1144
        } catch (Throwable e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1145
            System.err.println("Could not load java.io.Serializable or java.io.Externalizable.");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1146
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1147
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1148
02bb8761fcce Initial load
duke
parents:
diff changeset
  1149
    /** use serialVersionUID from JDK 1.1. for interoperability */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1150
    private static final long serialVersionUID = -6120832682080437368L;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1151
02bb8761fcce Initial load
duke
parents:
diff changeset
  1152
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1153
     * Set serialPersistentFields of a Serializable class to this value to
02bb8761fcce Initial load
duke
parents:
diff changeset
  1154
     * denote that the class has no Serializable fields.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1155
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1156
    public static final ObjectStreamField[] NO_FIELDS =
02bb8761fcce Initial load
duke
parents:
diff changeset
  1157
        new ObjectStreamField[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1158
02bb8761fcce Initial load
duke
parents:
diff changeset
  1159
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1160
     * Entries held in the Cache of known ObjectStreamClass_1_3_1 objects.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1161
     * Entries are chained together with the same hash value (modulo array size).
02bb8761fcce Initial load
duke
parents:
diff changeset
  1162
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1163
    private static class ObjectStreamClassEntry // extends java.lang.ref.SoftReference
02bb8761fcce Initial load
duke
parents:
diff changeset
  1164
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1165
        ObjectStreamClassEntry(ObjectStreamClass_1_3_1 c) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1166
            //super(c);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1167
            this.c = c;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1168
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1169
        ObjectStreamClassEntry next;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1170
02bb8761fcce Initial load
duke
parents:
diff changeset
  1171
        public Object get()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1172
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1173
            return c;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1174
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1175
        private ObjectStreamClass_1_3_1 c;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1176
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1177
02bb8761fcce Initial load
duke
parents:
diff changeset
  1178
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1179
     * Comparator object for Classes and Interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
  1180
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1181
    private static Comparator compareClassByName =
02bb8761fcce Initial load
duke
parents:
diff changeset
  1182
        new CompareClassByName();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1183
02bb8761fcce Initial load
duke
parents:
diff changeset
  1184
    private static class CompareClassByName implements Comparator {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1185
        public int compare(Object o1, Object o2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1186
            Class c1 = (Class)o1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1187
            Class c2 = (Class)o2;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1188
            return (c1.getName()).compareTo(c2.getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1189
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1190
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1191
02bb8761fcce Initial load
duke
parents:
diff changeset
  1192
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1193
     * Comparator object for Members, Fields, and Methods
02bb8761fcce Initial load
duke
parents:
diff changeset
  1194
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1195
    private static Comparator compareMemberByName =
02bb8761fcce Initial load
duke
parents:
diff changeset
  1196
        new CompareMemberByName();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1197
02bb8761fcce Initial load
duke
parents:
diff changeset
  1198
    private static class CompareMemberByName implements Comparator {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1199
        public int compare(Object o1, Object o2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1200
            String s1 = ((Member)o1).getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1201
            String s2 = ((Member)o2).getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1202
02bb8761fcce Initial load
duke
parents:
diff changeset
  1203
            if (o1 instanceof Method) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1204
                s1 += getSignature((Method)o1);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1205
                s2 += getSignature((Method)o2);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1206
            } else if (o1 instanceof Constructor) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1207
                s1 += getSignature((Constructor)o1);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1208
                s2 += getSignature((Constructor)o2);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1209
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1210
            return s1.compareTo(s2);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1211
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1212
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1213
02bb8761fcce Initial load
duke
parents:
diff changeset
  1214
    /* It is expensive to recompute a method or constructor signature
02bb8761fcce Initial load
duke
parents:
diff changeset
  1215
       many times, so compute it only once using this data structure. */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1216
    private static class MethodSignature implements Comparator {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1217
        Member member;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1218
        String signature;      // cached parameter signature
02bb8761fcce Initial load
duke
parents:
diff changeset
  1219
02bb8761fcce Initial load
duke
parents:
diff changeset
  1220
        /* Given an array of Method or Constructor members,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1221
           return a sorted array of the non-private members.*/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1222
        /* A better implementation would be to implement the returned data
02bb8761fcce Initial load
duke
parents:
diff changeset
  1223
           structure as an insertion sorted link list.*/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1224
        static MethodSignature[] removePrivateAndSort(Member[] m) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1225
            int numNonPrivate = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1226
            for (int i = 0; i < m.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1227
                if (! Modifier.isPrivate(m[i].getModifiers())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1228
                    numNonPrivate++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1229
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1230
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1231
            MethodSignature[] cm = new MethodSignature[numNonPrivate];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1232
            int cmi = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1233
            for (int i = 0; i < m.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1234
                if (! Modifier.isPrivate(m[i].getModifiers())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1235
                    cm[cmi] = new MethodSignature(m[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1236
                    cmi++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1237
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1238
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1239
            if (cmi > 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1240
                Arrays.sort(cm, cm[0]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1241
            return cm;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1242
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1243
02bb8761fcce Initial load
duke
parents:
diff changeset
  1244
        /* Assumes that o1 and o2 are either both methods
02bb8761fcce Initial load
duke
parents:
diff changeset
  1245
           or both constructors.*/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1246
        public int compare(Object o1, Object o2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1247
            /* Arrays.sort calls compare when o1 and o2 are equal.*/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1248
            if (o1 == o2)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1249
                return 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1250
02bb8761fcce Initial load
duke
parents:
diff changeset
  1251
            MethodSignature c1 = (MethodSignature)o1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1252
            MethodSignature c2 = (MethodSignature)o2;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1253
02bb8761fcce Initial load
duke
parents:
diff changeset
  1254
            int result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1255
            if (isConstructor()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1256
                result = c1.signature.compareTo(c2.signature);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1257
            } else { // is a Method.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1258
                result = c1.member.getName().compareTo(c2.member.getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1259
                if (result == 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1260
                    result = c1.signature.compareTo(c2.signature);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1261
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1262
            return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1263
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1264
02bb8761fcce Initial load
duke
parents:
diff changeset
  1265
        final private boolean isConstructor() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1266
            return member instanceof Constructor;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1267
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1268
        private MethodSignature(Member m) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1269
            member = m;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1270
            if (isConstructor()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1271
                signature = ObjectStreamClass_1_3_1.getSignature((Constructor)m);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1272
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1273
                signature = ObjectStreamClass_1_3_1.getSignature((Method)m);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1274
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1275
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1276
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1277
}