corba/src/jdk.rmic/share/classes/sun/rmi/rmic/iiop/ValueType.java
author gtriantafill
Wed, 14 Sep 2016 08:17:50 -0400
changeset 41092 c388d897472d
parent 25862 a5e25d68f971
permissions -rw-r--r--
8165889: Remove jdk.test.lib.unsafe.UnsafeHelper Summary: Remove use of setAccessible() to get Unsafe. Reviewed-by: shade, lfoltan
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) 1998, 2007, 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 sun.rmi.rmic.iiop;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import java.util.Vector;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import sun.tools.java.ClassNotFound;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import sun.tools.java.ClassDeclaration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import sun.tools.java.ClassDefinition;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import sun.tools.java.MemberDefinition;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import java.io.ObjectStreamClass;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import java.io.ObjectStreamField;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
 * ValueType represents any non-special class which does inherit from
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
 * java.io.Serializable and does not inherit from java.rmi.Remote.
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
 * The static forValue(...) method must be used to obtain an instance, and
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
 * will return null if the ClassDefinition is non-conforming.
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
 * @author      Bryan Atsatt
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
public class ValueType extends ClassType {
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
    private boolean isCustom;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
    // Public Interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
     * Create an ValueType object for the given class.
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
     * If the class is not a properly formed or if some other error occurs, the
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
     * return value will be null, and errors will have been reported to the
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
     * supplied BatchEnvironment.
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
    public static ValueType forValue(ClassDefinition classDef,
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
                                     ContextStack stack,
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
                                     boolean quiet) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
        if (stack.anyErrors()) return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
        // Do we already have it?
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        sun.tools.java.Type theType = classDef.getType();
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
        String typeKey = theType.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
        Type existing = getType(typeKey,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
        if (existing != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
            if (!(existing instanceof ValueType)) return null; // False hit.
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
            // Yep, so return it...
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
            return (ValueType) existing;
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
        // Is this java.lang.Class?
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
        boolean javaLangClass = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
        if (classDef.getClassDeclaration().getName() == idJavaLangClass) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
            // Yes, so replace classDef with one for
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
            // javax.rmi.CORBA.ClassDesc...
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
            javaLangClass = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
            BatchEnvironment env = stack.getEnv();
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
            ClassDeclaration decl = env.getClassDeclaration(idClassDesc);
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
            ClassDefinition def = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
                def = decl.getClassDefinition(env);
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
            } catch (ClassNotFound ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
                classNotFound(stack,ex);
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
                return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
            classDef = def;
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
        // Could this be a value?
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        if (couldBeValue(stack,classDef)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
            // Yes, so check it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
            ValueType it = new ValueType(classDef,stack,javaLangClass);
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
            putType(typeKey,it,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
            stack.push(it);
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
            if (it.initialize(stack,quiet)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
                stack.pop(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
                return it;
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
                removeType(typeKey,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
                stack.pop(false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
                return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
            return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
     * Return a string describing this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
    public String getTypeDescription () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
        String result = addExceptionDescription("Value");
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
        if (isCustom) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
            result = "Custom " + result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
        if (isIDLEntity) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
            result = result + " [IDLEntity]";
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
     * Return true if this type is a "custom" type (i.e.
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
     * it implements java.io.Externalizable or has a
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
     * method with the following signature:
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
     *  private void writeObject(java.io.ObjectOutputStream out);
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
    public boolean isCustom () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
        return isCustom;
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    // Subclass/Internal Interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
     * Create a ValueType instance for the given class.  The resulting
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
     * object is not yet completely initialized.
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
    private ValueType(ClassDefinition classDef,
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
                      ContextStack stack,
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
                      boolean isMappedJavaLangClass) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
        super(stack,classDef,TYPE_VALUE | TM_CLASS | TM_COMPOUND);
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
        isCustom = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
        // If this is the mapped version of java.lang.Class,
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
        // set the non-IDL names back to java.lang.Class...
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
        if (isMappedJavaLangClass) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
            setNames(idJavaLangClass,IDL_CLASS_MODULE,IDL_CLASS);
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
    // Internal Interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
     * Initialize this instance.
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
    private static boolean couldBeValue(ContextStack stack, ClassDefinition classDef) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
        boolean result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
        ClassDeclaration classDecl = classDef.getClassDeclaration();
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
        BatchEnvironment env = stack.getEnv();
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
            // Make sure it's not remote...
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
            if (env.defRemote.implementedBy(env, classDecl)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
                failedConstraint(10,false,stack,classDef.getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
                // Make sure it's Serializable...
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
                if (!env.defSerializable.implementedBy(env, classDecl)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
                    failedConstraint(11,false,stack,classDef.getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
                    result = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
        } catch (ClassNotFound e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
            classNotFound(stack,e);
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
     * Initialize this instance.
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
    private boolean initialize (ContextStack stack, boolean quiet) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
        ClassDefinition ourDef = getClassDefinition();
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
        ClassDeclaration ourDecl = getClassDeclaration();
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
            // Make sure our parentage is ok...
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
            if (!initParents(stack)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
                failedConstraint(12,quiet,stack,getQualifiedName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
                return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
            // We're ok, so make up our collections...
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
            Vector directInterfaces = new Vector();
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
            Vector directMethods = new Vector();
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
            Vector directMembers = new Vector();
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
            // Get interfaces...
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
            if (addNonRemoteInterfaces(directInterfaces,stack) != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
                // Get methods...
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
                if (addAllMethods(ourDef,directMethods,false,false,stack) != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
                    // Update parent class methods
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
                    if (updateParentClassMethods(ourDef,directMethods,false,stack) != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
                    // Get constants and members...
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
                    if (addAllMembers(directMembers,false,false,stack)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
                        // We're ok, so pass 'em up...
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
                        if (!initialize(directInterfaces,directMethods,directMembers,stack,quiet)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
                            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
                        // Is this class Externalizable?
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
                        boolean externalizable = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
                        if (!env.defExternalizable.implementedBy(env, ourDecl)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
                            // No, so check to see if we have a serialPersistentField
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
                            // that will modify the members.
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
                            if (!checkPersistentFields(getClassInstance(),quiet)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
                                return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
                        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
                            // Yes.
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
                            externalizable = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
                        // Should this class be considered "custom"? It is if
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
                        // it is Externalizable OR if it has a method with the
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
                        // following signature:
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
                        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
                        //  private void writeObject(java.io.ObjectOutputStream out);
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
                        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
                        if (externalizable) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
                            isCustom = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
                        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
                            for (MemberDefinition member = ourDef.getFirstMember();
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
                                 member != null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
                                 member = member.getNextMember()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
                                if (member.isMethod() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
                                    !member.isInitializer() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
                                    member.isPrivate() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
                                    member.getName().toString().equals("writeObject")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
                                    // Check return type, arguments and exceptions...
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
                                    sun.tools.java.Type methodType = member.getType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
                                    sun.tools.java.Type rtnType = methodType.getReturnType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
                                    if (rtnType == sun.tools.java.Type.tVoid) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
                                        // Return type is correct. How about arguments?
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
                                        sun.tools.java.Type[] args = methodType.getArgumentTypes();
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
                                        if (args.length == 1 &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
                                            args[0].getTypeSignature().equals("Ljava/io/ObjectOutputStream;")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
                                            // Arguments are correct, so it is a custom
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
                                            // value type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
                                            isCustom = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
                                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
                                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
                                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
                        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
        } catch (ClassNotFound e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
            classNotFound(stack,e);
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
    private boolean checkPersistentFields (Class clz, boolean quiet) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
        // Do we have a writeObject method?
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
        for (int i = 0; i < methods.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
            if (methods[i].getName().equals("writeObject") &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
                methods[i].getArguments().length == 1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
                Type returnType = methods[i].getReturnType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
                Type arg = methods[i].getArguments()[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
                String id = arg.getQualifiedName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
                if (returnType.isType(TYPE_VOID) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
                    id.equals("java.io.ObjectOutputStream")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
                    // Got one, so there's nothing to do...
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
                    return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
        // Do we have a valid serialPersistentField array?
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
        MemberDefinition spfDef = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
        for (int i = 0; i < members.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
            if (members[i].getName().equals("serialPersistentFields")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
                Member member = members[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
                Type type = member.getType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
                Type elementType = type.getElementType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
                // We have a member with the correct name. Make sure
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
                // we have the correct signature...
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
                if (elementType != null &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
                    elementType.getQualifiedName().equals(
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
                                                          "java.io.ObjectStreamField")
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
                    ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
                    if (member.isStatic() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
                        member.isFinal() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
                        member.isPrivate()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
                        // We have the correct signature
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
                        spfDef = member.getMemberDefinition();
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
                        // Bad signature...
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
                        failedConstraint(4,quiet,stack,getQualifiedName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
                        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
        // If we do not have a serialPersistentField,
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
        // there's nothing to do, so return with no error...
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
        if (spfDef == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
        // Ok, now we must examine the contents of the array -
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
        // then validate them...
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
        Hashtable fields = getPersistentFields(clz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
        boolean result = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
        for (int i = 0; i < members.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
            String fieldName = members[i].getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
            String fieldType = members[i].getType().getSignature();
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
            // Is this field present in the array?
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
            String type = (String) fields.get(fieldName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
            if (type == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
                // No, so mark it transient...
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
                members[i].setTransient();
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
                // Yes, does the type match?
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
                if (type.equals(fieldType)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
                    // Yes, so remove it from the fields table...
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
                    fields.remove(fieldName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
                    // No, so error...
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
                    result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
                    failedConstraint(2,quiet,stack,fieldName,getQualifiedName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
        // Ok, we've checked all of our fields. Are there any left in the "array"?
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
        // If so, it's an error...
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
        if (result && fields.size() > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
            result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
            failedConstraint(9,quiet,stack,getQualifiedName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
        // Return result...
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
     * Get the names and types of all the persistent fields of a Class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
    private Hashtable getPersistentFields (Class clz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
        Hashtable result = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
        ObjectStreamClass osc = ObjectStreamClass.lookup(clz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
        if (osc != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
            ObjectStreamField[] fields = osc.getFields();
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
            for (int i = 0; i < fields.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
                String typeSig;
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
                String typePrefix = String.valueOf(fields[i].getTypeCode());
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
                if (fields[i].isPrimitive()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
                    typeSig = typePrefix;
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
                    if (fields[i].getTypeCode() == '[') {
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
                        typePrefix = "";
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
                    typeSig = typePrefix + fields[i].getType().getName().replace('.','/');
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
                    if (typeSig.endsWith(";")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
                        typeSig = typeSig.substring(0,typeSig.length()-1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
                result.put(fields[i].getName(),typeSig);
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
}