corba/src/share/classes/com/sun/corba/se/impl/orbutil/RepositoryId_1_3_1.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
child 13052 63c6c4c360e1
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, 2002, 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
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
package com.sun.corba.se.impl.orbutil;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import java.util.StringTokenizer;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
import java.lang.reflect.Method;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import java.net.MalformedURLException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import org.omg.CORBA.portable.ValueBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import org.omg.CORBA.portable.IDLEntity;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
//d11638 files in the same package, therefore remove their reference
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
//import com.sun.corba.se.impl.util.JDKBridge;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
//import com.sun.corba.se.impl.util.IdentityHashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import com.sun.corba.se.impl.util.JDKBridge;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import com.sun.corba.se.impl.util.Utility;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import com.sun.corba.se.impl.util.PackagePrefixChecker;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import com.sun.corba.se.impl.util.IdentityHashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import javax.rmi.CORBA.Util;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
 * Because all methods in RepositoryId are static, we have
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
 * to duplicate all of this code, freezing it in its 1.3.1
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
 * form for backwards compatibility.
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
 * For security reasons, we can't expose enough of
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
 * io/ObjectStreamClass, so it has to be duplicated in
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
 * orbutil.
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
public class RepositoryId_1_3_1 {
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
    // Legal IDL Identifier characters (1 = legal). Note
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
    // that '.' (2E) is marked as legal even though it is
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
    // not legal in IDL. This allows us to treat a fully
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
    // qualified Java name with '.' package separators
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
    // uniformly, and is safe because that is the only
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
    // legal use of '.' in a Java name.
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
    public static final byte[] IDL_IDENTIFIER_CHARS = {
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
        // 0 1 2 3  4 5 6 7  8 9 a b  c d e f
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 00-0f
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 10-1f
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,1,0, // 20-2f
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
        1,1,1,1, 1,1,1,1, 1,1,0,0, 0,0,0,0, // 30-3f
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
        0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // 40-4f
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
        1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,1, // 50-5f
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
        0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // 60-6f
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0, // 70-7f
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 80-8f
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 90-9f
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // a0-af
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // b0-bf
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
        1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // c0-cf
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
        0,1,1,1, 1,1,1,0, 1,1,1,1, 1,0,0,1, // d0-df
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
        1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // e0-ef
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
        0,1,1,1, 1,1,1,0, 1,1,1,1, 1,0,0,1, // f0-ff
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
    };
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
    private static final long serialVersionUID = 123456789L;
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
    private static String defaultServerURL = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
    private static boolean useCodebaseOnly = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
    static {
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
        if (defaultServerURL == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
            defaultServerURL = (String)JDKBridge.getLocalCodebase();
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
        useCodebaseOnly = JDKBridge.useCodebaseOnly();
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
    private static IdentityHashtable classToRepStr = new IdentityHashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
    private static IdentityHashtable classIDLToRepStr = new IdentityHashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
    private static IdentityHashtable classSeqToRepStr = new IdentityHashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
    private static IdentityHashtable repStrToByteArray = new IdentityHashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
    private static Hashtable repStrToClass = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
    private String repId = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
    private boolean isSupportedFormat = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
    private String typeString = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
    private String versionString = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
    private boolean isSequence = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
    private boolean isRMIValueType = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
    private boolean isIDLType = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
    private String completeClassName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
    private String unqualifiedName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
    private String definedInId = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
    private Class clazz = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
    private String suid = null, actualSuid = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
    private long suidLong = ObjectStreamClass_1_3_1.kDefaultUID, actualSuidLong = ObjectStreamClass_1_3_1.kDefaultUID;
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
    // Repository ID fragments
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
    private static final String kSequenceKeyword = "seq";
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
    private static final String kValuePrefix = "RMI:";
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
    private static final String kIDLPrefix = "IDL:";
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
    private static final String kIDLNamePrefix = "omg.org/";
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
    private static final String kIDLClassnamePrefix = "org.omg.";
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
    private static final String kSequencePrefix = "[";
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
    private static final String kCORBAPrefix = "CORBA/";
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
    private static final String kArrayPrefix = kValuePrefix + kSequencePrefix + kCORBAPrefix;
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
    private static final int kValuePrefixLength = kValuePrefix.length();
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
    private static final int kIDLPrefixLength = kIDLPrefix.length();
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
    private static final int kSequencePrefixLength = kSequencePrefix.length();
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
    private static final String kInterfaceHashCode = ":0000000000000000";
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    private static final String kInterfaceOnlyHashStr = "0000000000000000";
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
    private static final String kExternalizableHashStr = "0000000000000001";
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
    // Value tag utility methods and constants
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
    public static final int kInitialValueTag= 0x7fffff00;
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
    public static final int kNoTypeInfo = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
    public static final int kSingleRepTypeInfo = 0x02;
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
    public static final int  kPartialListTypeInfo = 0x06;
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
    public static final int  kChunkedMask = 0x08;
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
    public static final int kPreComputed_StandardRMIUnchunked = RepositoryId_1_3_1.computeValueTag(false, RepositoryId_1_3_1.kSingleRepTypeInfo, false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
    public static final int kPreComputed_CodeBaseRMIUnchunked = RepositoryId_1_3_1.computeValueTag(true, RepositoryId_1_3_1.kSingleRepTypeInfo, false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
    public static final int kPreComputed_StandardRMIChunked = RepositoryId_1_3_1.computeValueTag(false, RepositoryId_1_3_1.kSingleRepTypeInfo, true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    public static final int kPreComputed_CodeBaseRMIChunked = RepositoryId_1_3_1.computeValueTag(true, RepositoryId_1_3_1.kSingleRepTypeInfo, true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
    public static final int kPreComputed_StandardRMIUnchunked_NoRep = RepositoryId_1_3_1.computeValueTag(false, RepositoryId_1_3_1.kNoTypeInfo, false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
    public static final int kPreComputed_CodeBaseRMIUnchunked_NoRep = RepositoryId_1_3_1.computeValueTag(true, RepositoryId_1_3_1.kNoTypeInfo, false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
    public static final int kPreComputed_StandardRMIChunked_NoRep = RepositoryId_1_3_1.computeValueTag(false, RepositoryId_1_3_1.kNoTypeInfo, true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
    public static final int kPreComputed_CodeBaseRMIChunked_NoRep = RepositoryId_1_3_1.computeValueTag(true, RepositoryId_1_3_1.kNoTypeInfo, true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    // Public, well known repository IDs
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
    // _REVISIT_ : A table structure with a good search routine for all of this
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
    // would be more efficient and easier to maintain...
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    // String
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
    public static final String kWStringValueVersion = "1.0";
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
    public static final String kWStringValueHash = ":"+kWStringValueVersion;
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
    public static final String kWStringStubValue = "WStringValue";
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
    public static final String kWStringTypeStr = "omg.org/CORBA/"+kWStringStubValue;
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    public static final String kWStringValueRepID = kIDLPrefix + kWStringTypeStr + kWStringValueHash;
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    // Any
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
    public static final String kAnyRepID = kIDLPrefix + "omg.org/CORBA/Any";
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
    // Class
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
    // Anita4: convert to uppercase
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    public static final String kClassDescValueHash = ":" +
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
       Long.toHexString(
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
       ObjectStreamClass_1_3_1.getActualSerialVersionUID(javax.rmi.CORBA.ClassDesc.class)).toUpperCase() + ":" +
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
      Long.toHexString(
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
       ObjectStreamClass_1_3_1.getSerialVersionUID(javax.rmi.CORBA.ClassDesc.class)).toUpperCase();
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
    public static final String kClassDescStubValue = "ClassDesc";
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
    public static final String kClassDescTypeStr = "javax.rmi.CORBA."+kClassDescStubValue;
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
    public static final String kClassDescValueRepID = kValuePrefix + kClassDescTypeStr + kClassDescValueHash;
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
    // Object
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    public static final String kObjectValueHash = ":1.0";
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
    public static final String kObjectStubValue = "Object";
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
    // Sequence
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
    public static final String kSequenceValueHash = ":1.0";
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
    public static final String kPrimitiveSequenceValueHash = ":0000000000000000";
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
    // Serializable
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
    public static final String kSerializableValueHash = ":1.0";
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
    public static final String kSerializableStubValue = "Serializable";
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
    // Externalizable
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
    public static final String kExternalizableValueHash = ":1.0";
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
    public static final String kExternalizableStubValue = "Externalizable";
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
    // Remote (The empty string is used for java.rmi.Remote)
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
    public static final String kRemoteValueHash = "";
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
    public static final String kRemoteStubValue = "";
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
    public static final String kRemoteTypeStr = "";
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
    public static final String kRemoteValueRepID = "";
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
    public static final Hashtable kSpecialArrayTypeStrings = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
    static {
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
        kSpecialArrayTypeStrings.put("CORBA.WStringValue", new StringBuffer(java.lang.String.class.getName()));
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
        kSpecialArrayTypeStrings.put("javax.rmi.CORBA.ClassDesc", new StringBuffer(java.lang.Class.class.getName()));
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
        kSpecialArrayTypeStrings.put("CORBA.Object", new StringBuffer(java.rmi.Remote.class.getName()));
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
    public static final Hashtable kSpecialCasesRepIDs = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
    static {
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
        kSpecialCasesRepIDs.put(java.lang.String.class, kWStringValueRepID);
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
        kSpecialCasesRepIDs.put(java.lang.Class.class, kClassDescValueRepID);
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
        kSpecialCasesRepIDs.put(java.rmi.Remote.class, kRemoteValueRepID);
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
    public static final Hashtable kSpecialCasesStubValues = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
    static {
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
        kSpecialCasesStubValues.put(java.lang.String.class, kWStringStubValue);
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
        kSpecialCasesStubValues.put(java.lang.Class.class, kClassDescStubValue);
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
        kSpecialCasesStubValues.put(java.lang.Object.class, kObjectStubValue);
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
        kSpecialCasesStubValues.put(java.io.Serializable.class, kSerializableStubValue);
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
        kSpecialCasesStubValues.put(java.io.Externalizable.class, kExternalizableStubValue);
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
        kSpecialCasesStubValues.put(java.rmi.Remote.class, kRemoteStubValue);
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
    public static final Hashtable kSpecialCasesVersions = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
    static {
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
        kSpecialCasesVersions.put(java.lang.String.class, kWStringValueHash);
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
        kSpecialCasesVersions.put(java.lang.Class.class, kClassDescValueHash);
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
        kSpecialCasesVersions.put(java.lang.Object.class, kObjectValueHash);
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
        kSpecialCasesVersions.put(java.io.Serializable.class, kSerializableValueHash);
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
        kSpecialCasesVersions.put(java.io.Externalizable.class, kExternalizableValueHash);
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
        kSpecialCasesVersions.put(java.rmi.Remote.class, kRemoteValueHash);
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
    public static final Hashtable kSpecialCasesClasses = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
    static {
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
        kSpecialCasesClasses.put(kWStringTypeStr, java.lang.String.class);
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
        kSpecialCasesClasses.put(kClassDescTypeStr, java.lang.Class.class);
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
        kSpecialCasesClasses.put(kRemoteTypeStr, java.rmi.Remote.class);
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
        kSpecialCasesClasses.put("org.omg.CORBA.WStringValue", java.lang.String.class);
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
        kSpecialCasesClasses.put("javax.rmi.CORBA.ClassDesc", java.lang.Class.class);
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
        //kSpecialCasesClasses.put(kRemoteTypeStr, java.rmi.Remote.class);
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
    public static final Hashtable kSpecialCasesArrayPrefix = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
    static {
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
        kSpecialCasesArrayPrefix.put(java.lang.String.class, kValuePrefix + kSequencePrefix + kCORBAPrefix);
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
        kSpecialCasesArrayPrefix.put(java.lang.Class.class, kValuePrefix + kSequencePrefix + "javax/rmi/CORBA/");
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
        kSpecialCasesArrayPrefix.put(java.lang.Object.class, kValuePrefix + kSequencePrefix + "java/lang/");
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
        kSpecialCasesArrayPrefix.put(java.io.Serializable.class, kValuePrefix + kSequencePrefix + "java/io/");
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
        kSpecialCasesArrayPrefix.put(java.io.Externalizable.class, kValuePrefix + kSequencePrefix + "java/io/");
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
        kSpecialCasesArrayPrefix.put(java.rmi.Remote.class, kValuePrefix + kSequencePrefix + kCORBAPrefix);
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
    public static final Hashtable kSpecialPrimitives = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
    static {
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
        kSpecialPrimitives.put("int","long");
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
        kSpecialPrimitives.put("long","longlong");
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
        kSpecialPrimitives.put("byte","octet");
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
     * Used to convert ascii to hex.
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
    private static final byte ASCII_HEX[] =     {
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
        (byte)'0',
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
        (byte)'1',
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
        (byte)'2',
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
        (byte)'3',
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
        (byte)'4',
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
        (byte)'5',
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
        (byte)'6',
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
        (byte)'7',
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
        (byte)'8',
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
        (byte)'9',
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
        (byte)'A',
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
        (byte)'B',
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
        (byte)'C',
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
        (byte)'D',
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
        (byte)'E',
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
        (byte)'F',
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
    };
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
    // bug fix for 4328952; to eliminate possibility of overriding this
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
    // in a subclass.
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
    public static final RepositoryIdCache_1_3_1 cache = new RepositoryIdCache_1_3_1();
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
    // Interface Rep ID Strings
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
    public static final String kjava_rmi_Remote = createForAnyType(java.rmi.Remote.class);
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
    public static final String korg_omg_CORBA_Object = createForAnyType(org.omg.CORBA.Object.class);
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
    // Dummy arguments for getIdFromHelper method
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
    public static final Class kNoParamTypes[] ={};
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
    public static final Object kNoArgs[] = {};
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
    // To create a RepositoryID, use code similar to the following:
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
    // RepositoryId.cache.getId( id );
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
    RepositoryId_1_3_1(){}
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
    RepositoryId_1_3_1(String aRepId){
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
        init(aRepId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
    RepositoryId_1_3_1 init(String aRepId){
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
        this.repId = aRepId;
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
        // Special case for remote
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
        if (aRepId.length() == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
            clazz = java.rmi.Remote.class;
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
            typeString = "";
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
            isRMIValueType = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
            suid = kInterfaceOnlyHashStr;
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
            return this;
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
        else if (aRepId.equals(kWStringValueRepID)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
            clazz = java.lang.String.class;
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
            typeString = kWStringTypeStr;
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
            isIDLType = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
            // fix where Attempting to obtain a FullValueDescription
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
            // for an RMI value type with a String field causes an exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
            completeClassName = "java.lang.String";
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
            versionString = kWStringValueVersion;
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
            return this;
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
        else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
        String repId = convertFromISOLatin1(aRepId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
        versionString = repId.substring(repId.indexOf(':', repId.indexOf(':')+1));
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
        if (repId.startsWith(kIDLPrefix)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
            typeString =
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
                repId.substring(kIDLPrefixLength, repId.indexOf(':', kIDLPrefixLength));
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
            isIDLType = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
            if (typeString.startsWith(kIDLNamePrefix))
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
                completeClassName = kIDLClassnamePrefix +
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
                    typeString.substring(kIDLNamePrefix.length()).replace('/','.');
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
            else completeClassName = typeString.replace('/','.');
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
        else if (repId.startsWith(kValuePrefix)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
            typeString =
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
                repId.substring(kValuePrefixLength, repId.indexOf(':', kValuePrefixLength));
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
            isRMIValueType = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
            if (versionString.indexOf('.') == -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
                    actualSuid = versionString.substring(1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
                    suid = actualSuid;  // default if not explicitly specified
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
                    if (actualSuid.indexOf(':') != -1){
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
                    // we have a declared hash also
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
                        int pos = actualSuid.indexOf(':')+1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
                        // actualSuid = suid.substring(pos);
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
                        // suid = suid.substring(0, pos-1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
                        suid = actualSuid.substring(pos);
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
                        actualSuid = actualSuid.substring(0, pos-1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
            else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
                    // _REVISIT_ : Special case version failure ?
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
        else isSupportedFormat = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
        if (typeString.startsWith(kSequencePrefix)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
            isSequence = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
        return this;
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
    public final String getUnqualifiedName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
        if (unqualifiedName == null){
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
            String className = getClassName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
            int index = className.lastIndexOf('.');
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
            if (index == -1){
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
                unqualifiedName = className;
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
                definedInId = "IDL::1.0";
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
            else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
                unqualifiedName = className.substring(index);
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
                definedInId = "IDL:" + className.substring(0, index).replace('.','/') + ":1.0";
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
        return unqualifiedName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
    public final String getDefinedInId() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
        if (definedInId == null){
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
            getUnqualifiedName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
        return definedInId;
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
    public final String getTypeString() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
        return typeString;
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
    public final String getVersionString() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
        return versionString;
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
    public final String getSerialVersionUID() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
        return suid;
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
    public final String getActualSerialVersionUID() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
        return actualSuid;
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
    public final long getSerialVersionUIDAsLong() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
        return suidLong;
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
    public final long getActualSerialVersionUIDAsLong() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
        return actualSuidLong;
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
    public final boolean isRMIValueType() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
        return isRMIValueType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
    public final boolean isIDLType() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
        return isIDLType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
    public final String getRepositoryId() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
        return repId;
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
    public static byte[] getByteArray(String repStr) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
        synchronized (repStrToByteArray){
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
            return (byte[]) repStrToByteArray.get(repStr);
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
    public static void setByteArray(String repStr, byte[] repStrBytes) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
        synchronized (repStrToByteArray){
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
            repStrToByteArray.put(repStr, repStrBytes);
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
    public final boolean isSequence() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
        return isSequence;
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
    public final boolean isSupportedFormat() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
        return isSupportedFormat;
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
    // This method will return the classname from the typestring OR if the classname turns out to be
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
    // a special class "pseudo" name, then the matching real classname is returned.
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
    public final String getClassName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
        if (isRMIValueType)
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
            return typeString;
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
        else if (isIDLType)
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
            return completeClassName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
        else return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
    // This method calls getClazzFromType() and falls back to the repStrToClass
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
    // cache if no class was found.  It's used where any class matching the
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
    // given repid is an acceptable result.
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
    public final Class getAnyClassFromType() throws ClassNotFoundException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
            return getClassFromType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
        } catch (ClassNotFoundException cnfe) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
            Class clz = (Class)repStrToClass.get(repId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
            if (clz != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
                return clz;
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
                throw cnfe;
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
    public final Class getClassFromType()
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
        throws ClassNotFoundException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
        if (clazz != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
            return clazz;
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
        Class specialCase = (Class)kSpecialCasesClasses.get(getClassName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
        if (specialCase != null){
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
            clazz = specialCase;
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
            return specialCase;
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
                try{
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
                    return Util.loadClass(getClassName(), null, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
                catch(ClassNotFoundException cnfe){
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
                    if (defaultServerURL != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
                        try{
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
                            return getClassFromType(defaultServerURL);
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
                        catch(MalformedURLException mue){
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
                            throw cnfe;
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
                    else throw cnfe;
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
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
    public final Class getClassFromType(Class expectedType, String codebase)
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
        throws ClassNotFoundException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
        if (clazz != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
            return clazz;
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
        Class specialCase = (Class)kSpecialCasesClasses.get(getClassName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
        if (specialCase != null){
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
            clazz = specialCase;
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
            return specialCase;
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
            ClassLoader expectedTypeClassLoader = (expectedType == null ? null : expectedType.getClassLoader());
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
            return loadClassOfType(getClassName(),
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
                                   codebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
                                   expectedTypeClassLoader,
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
                                   expectedType,
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
                                   expectedTypeClassLoader);
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
    public final Class getClassFromType(String url)
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
        throws ClassNotFoundException, MalformedURLException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
        return Util.loadClass(getClassName(), url, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
    public final String toString() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
        return repId;
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
     * Checks to see if the FullValueDescription should be retrieved.
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
     * @exception Throws IOException if suids do not match or if the repositoryID
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
     * is not an RMIValueType
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
    public static boolean useFullValueDescription(Class clazz, String repositoryID)
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
        throws IOException{
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
        String clazzRepIDStr = createForAnyType(clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
        if (clazzRepIDStr.equals(repositoryID))
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
        RepositoryId_1_3_1 targetRepid;
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
        RepositoryId_1_3_1 clazzRepid;
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
        synchronized(cache) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
        // to avoid race condition where multiple threads could be
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
        // accessing this method, and their access to the cache may
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
        // be interleaved giving unexpected results
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
            targetRepid = cache.getId(repositoryID);
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
            clazzRepid = cache.getId(clazzRepIDStr);
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
        //ObjectStreamClass osc = ObjectStreamClass.lookup(clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
        if ((targetRepid.isRMIValueType()) && (clazzRepid.isRMIValueType())){
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
            if (!targetRepid.getSerialVersionUID().equals(clazzRepid.getSerialVersionUID())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
                String mssg = "Mismatched serialization UIDs : Source (Rep. ID" +
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
                    clazzRepid + ") = " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
                    clazzRepid.getSerialVersionUID() + " whereas Target (Rep. ID " + repositoryID +
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
                    ") = " + targetRepid.getSerialVersionUID();
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
                                //com.sun.corba.se.impl.io.ValueUtility.log("RepositoryId",mssg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
                throw new IOException(mssg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
            else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
                return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
        else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
            throw new IOException("The repository ID is not of an RMI value type (Expected ID = " + clazzRepIDStr + "; Received ID = " + repositoryID +")");
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
    private static String createHashString(java.io.Serializable ser) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
        return createHashString(ser.getClass());
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
    private static String createHashString(java.lang.Class clazz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
        if (clazz.isInterface() || !java.io.Serializable.class.isAssignableFrom(clazz))
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
            return kInterfaceHashCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
        //ObjectStreamClass osc = ObjectStreamClass.lookup(clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
        long actualLong = ObjectStreamClass_1_3_1.getActualSerialVersionUID(clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
        String hash = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
        if (actualLong == 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
            hash = kInterfaceOnlyHashStr;
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
        else if (actualLong == 1)
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
            hash = kExternalizableHashStr;
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
            hash = Long.toHexString(actualLong).toUpperCase();
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
        while(hash.length() < 16){
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
            hash = "0" + hash;
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
        long declaredLong = ObjectStreamClass_1_3_1.getSerialVersionUID(clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
        String declared = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
        if (declaredLong == 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
            declared = kInterfaceOnlyHashStr;
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
        else if (declaredLong == 1)
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
            declared = kExternalizableHashStr;
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
            declared = Long.toHexString(declaredLong).toUpperCase();
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
        while (declared.length() < 16){
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
            declared = "0" + declared;
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
        hash = hash + ":" + declared;
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
        return ":" + hash;
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
     * Creates a repository ID for a sequence.  This is for expert users only as
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
     * this method assumes the object passed is an array.  If passed an object
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
     * that is not an array, it will produce a rep id for a sequence of zero
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
     * length.  This would be an error.
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
     * @param ser The Java object to create a repository ID for
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
     **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
    public static String createSequenceRepID(java.lang.Object ser){
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
        return createSequenceRepID(ser.getClass());
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
     * Creates a repository ID for a sequence.  This is for expert users only as
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
     * this method assumes the object passed is an array.  If passed an object
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
     * that is not an array, it will produce a malformed rep id.
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
     * @param clazz The Java class to create a repository ID for
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
     **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
    public static String createSequenceRepID(java.lang.Class clazz){
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
        synchronized (classSeqToRepStr){
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
        String repid = (String)classSeqToRepStr.get(clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
        if (repid != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
            return repid;
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
        Class originalClazz = clazz;
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
        Class type = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
        int numOfDims = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
        while ((type = clazz.getComponentType()) != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
            numOfDims++;
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
            clazz = type;
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
        if (clazz.isPrimitive())
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
            repid = kValuePrefix + originalClazz.getName() + kPrimitiveSequenceValueHash;
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
        else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
            StringBuffer buf = new StringBuffer();
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
            buf.append(kValuePrefix);
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
            while(numOfDims-- > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
                buf.append("[");
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
            buf.append("L");
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
            buf.append(convertToISOLatin1(clazz.getName()));
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
            buf.append(";");
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
            buf.append(createHashString(clazz));
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
            repid = buf.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
        classSeqToRepStr.put(originalClazz,repid);
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
        return repid;
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
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
    public static String createForSpecialCase(java.lang.Class clazz){
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
        if (clazz.isArray()){
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
            return createSequenceRepID(clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
        else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
            return (String)kSpecialCasesRepIDs.get(clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
    public static String createForSpecialCase(java.io.Serializable ser){
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
        Class clazz = ser.getClass();
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
        if (clazz.isArray()){
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
            return createSequenceRepID(ser);
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
            return createForSpecialCase(clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
     * Creates a repository ID for a normal Java Type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
     * @param ser The Java object to create a repository ID for
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
     * @exception com.sun.corba.se.impl.io.TypeMismatchException if ser implements the
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
     * org.omg.CORBA.portable.IDLEntity interface which indicates it is an IDL Value type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
     **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
    public static String createForJavaType(java.io.Serializable ser)
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
        throws com.sun.corba.se.impl.io.TypeMismatchException
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
        synchronized (classToRepStr) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
        String repid = createForSpecialCase(ser);
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
        if (repid != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
            return repid;
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
        Class clazz = ser.getClass();
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
        repid = (String)classToRepStr.get(clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
        if (repid != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
            return repid;
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
        repid = kValuePrefix + convertToISOLatin1(clazz.getName()) +
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
            createHashString(clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
        classToRepStr.put(clazz, repid);
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
            repStrToClass.put(repid, clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
        return repid;
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
     * Creates a repository ID for a normal Java Type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
     * @param clz The Java class to create a repository ID for
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
     * @exception com.sun.corba.se.impl.io.TypeMismatchException if ser implements the
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
     * org.omg.CORBA.portable.IDLEntity interface which indicates it is an IDL Value type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
     **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
    public static String createForJavaType(Class clz)
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
        throws com.sun.corba.se.impl.io.TypeMismatchException
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
        synchronized (classToRepStr){
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
        String repid = createForSpecialCase(clz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
        if (repid != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
            return repid;
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
        repid = (String)classToRepStr.get(clz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
        if (repid != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
            return repid;
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
        repid = kValuePrefix + convertToISOLatin1(clz.getName()) +
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
            createHashString(clz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
        classToRepStr.put(clz, repid);
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
            repStrToClass.put(repid, clz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
        return repid;
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
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
     * Creates a repository ID for an IDL Java Type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
     * @param ser The IDL Value object to create a repository ID for
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
     * @param major The major version number
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
     * @param minor The minor version number
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
     * @exception com.sun.corba.se.impl.io.TypeMismatchException if ser does not implement the
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
     * org.omg.CORBA.portable.IDLEntity interface which indicates it is an IDL Value type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
     **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
    public static String createForIDLType(Class ser, int major, int minor)
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
        throws com.sun.corba.se.impl.io.TypeMismatchException
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
        synchronized (classIDLToRepStr){
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
        String repid = (String)classIDLToRepStr.get(ser);
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
        if (repid != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
            return repid;
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
        repid = kIDLPrefix + convertToISOLatin1(ser.getName()).replace('.','/') +
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
            ":" + major + "." + minor;
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
        classIDLToRepStr.put(ser, repid);
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
        return repid;
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
    private static String getIdFromHelper(Class clazz){
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
            Class helperClazz = Utility.loadClassForClass(clazz.getName()+"Helper", null,
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
                                    clazz.getClassLoader(), clazz, clazz.getClassLoader());
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
            Method idMethod = helperClazz.getDeclaredMethod("id", kNoParamTypes);
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
            return (String)idMethod.invoke(null, kNoArgs);
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
        catch(java.lang.ClassNotFoundException cnfe)
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
                throw new org.omg.CORBA.MARSHAL(cnfe.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
        catch(java.lang.NoSuchMethodException nsme)
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
                throw new org.omg.CORBA.MARSHAL(nsme.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
        catch(java.lang.reflect.InvocationTargetException ite)
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
                throw new org.omg.CORBA.MARSHAL(ite.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
        catch(java.lang.IllegalAccessException iae)
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
                throw new org.omg.CORBA.MARSHAL(iae.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
     * Createa a repository ID for the type if it is either a java type
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
     * or an IDL type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
     * @param type The type to create rep. id for
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
     * @return The rep. id.
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
     **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
    public static String createForAnyType(Class type) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
        try{
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
            if (type.isArray())
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
                return createSequenceRepID(type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
            else if (IDLEntity.class.isAssignableFrom(type))
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
                {
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
                    try{
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
                        return getIdFromHelper(type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
                    catch(Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
                        return createForIDLType(type, 1, 0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
            else return createForJavaType(type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
        catch(com.sun.corba.se.impl.io.TypeMismatchException e){
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
            return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
    public static boolean isAbstractBase(Class clazz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
        return (clazz.isInterface() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
                IDLEntity.class.isAssignableFrom(clazz) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
                (!ValueBase.class.isAssignableFrom(clazz)) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
                (!org.omg.CORBA.Object.class.isAssignableFrom(clazz)));
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
    public static boolean isAnyRequired(Class clazz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
        return ((clazz == java.lang.Object.class) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
                (clazz == java.io.Serializable.class) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
                (clazz == java.io.Externalizable.class));
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
    public static long fromHex(String hexNumber) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
        if (hexNumber.startsWith("0x"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
            return Long.valueOf(hexNumber.substring(2), 16).longValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   863
        else return Long.valueOf(hexNumber, 16).longValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   864
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   865
02bb8761fcce Initial load
duke
parents:
diff changeset
   866
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   867
     * Convert strings with illegal IDL identifier characters.
02bb8761fcce Initial load
duke
parents:
diff changeset
   868
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   869
     * Section 5.5.7 of OBV spec.
02bb8761fcce Initial load
duke
parents:
diff changeset
   870
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   871
    private static String convertToISOLatin1 (String name) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   872
02bb8761fcce Initial load
duke
parents:
diff changeset
   873
        int length = name.length();
02bb8761fcce Initial load
duke
parents:
diff changeset
   874
        if (length == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   875
            return name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   876
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   877
        StringBuffer buffer = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   878
02bb8761fcce Initial load
duke
parents:
diff changeset
   879
        for (int i = 0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   880
02bb8761fcce Initial load
duke
parents:
diff changeset
   881
            char c = name.charAt(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   882
02bb8761fcce Initial load
duke
parents:
diff changeset
   883
            if (c > 255 || IDL_IDENTIFIER_CHARS[c] == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   884
02bb8761fcce Initial load
duke
parents:
diff changeset
   885
                // We gotta convert. Have we already started?
02bb8761fcce Initial load
duke
parents:
diff changeset
   886
02bb8761fcce Initial load
duke
parents:
diff changeset
   887
                if (buffer == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   888
02bb8761fcce Initial load
duke
parents:
diff changeset
   889
                    // No, so get set up...
02bb8761fcce Initial load
duke
parents:
diff changeset
   890
02bb8761fcce Initial load
duke
parents:
diff changeset
   891
                    buffer = new StringBuffer(name.substring(0,i));
02bb8761fcce Initial load
duke
parents:
diff changeset
   892
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   893
02bb8761fcce Initial load
duke
parents:
diff changeset
   894
                // Convert the character into the IDL escape syntax...
02bb8761fcce Initial load
duke
parents:
diff changeset
   895
                buffer.append(
02bb8761fcce Initial load
duke
parents:
diff changeset
   896
                              "\\U" +
02bb8761fcce Initial load
duke
parents:
diff changeset
   897
                              (char)ASCII_HEX[(c & 0xF000) >>> 12] +
02bb8761fcce Initial load
duke
parents:
diff changeset
   898
                              (char)ASCII_HEX[(c & 0x0F00) >>> 8] +
02bb8761fcce Initial load
duke
parents:
diff changeset
   899
                              (char)ASCII_HEX[(c & 0x00F0) >>> 4] +
02bb8761fcce Initial load
duke
parents:
diff changeset
   900
                              (char)ASCII_HEX[(c & 0x000F)]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   901
02bb8761fcce Initial load
duke
parents:
diff changeset
   902
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   903
                if (buffer != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   904
                    buffer.append(c);
02bb8761fcce Initial load
duke
parents:
diff changeset
   905
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   906
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   907
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   908
02bb8761fcce Initial load
duke
parents:
diff changeset
   909
        if (buffer != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   910
            name = buffer.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   911
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   912
02bb8761fcce Initial load
duke
parents:
diff changeset
   913
        return name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   914
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   915
02bb8761fcce Initial load
duke
parents:
diff changeset
   916
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   917
     * Convert strings with ISO Latin 1 escape sequences back to original strings.
02bb8761fcce Initial load
duke
parents:
diff changeset
   918
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   919
     * Section 5.5.7 of OBV spec.
02bb8761fcce Initial load
duke
parents:
diff changeset
   920
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   921
    private static String convertFromISOLatin1 (String name) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   922
02bb8761fcce Initial load
duke
parents:
diff changeset
   923
        int index = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   924
        StringBuffer buf = new StringBuffer(name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   925
02bb8761fcce Initial load
duke
parents:
diff changeset
   926
        while ((index = buf.toString().indexOf("\\U")) != -1){
02bb8761fcce Initial load
duke
parents:
diff changeset
   927
            String str = "0000" + buf.toString().substring(index+2, index+6);
02bb8761fcce Initial load
duke
parents:
diff changeset
   928
02bb8761fcce Initial load
duke
parents:
diff changeset
   929
            // Convert Hexadecimal
02bb8761fcce Initial load
duke
parents:
diff changeset
   930
            byte[] buffer = new byte[(str.length() - 4) / 2];
02bb8761fcce Initial load
duke
parents:
diff changeset
   931
            for (int i=4, j=0; i < str.length(); i +=2, j++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   932
                buffer[j] = (byte)((ORBUtility.hexOf(str.charAt(i)) << 4) & 0xF0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   933
                buffer[j] |= (byte)((ORBUtility.hexOf(str.charAt(i+1)) << 0) & 0x0F);
02bb8761fcce Initial load
duke
parents:
diff changeset
   934
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   935
            buf = new StringBuffer(delete(buf.toString(), index, index+6));
02bb8761fcce Initial load
duke
parents:
diff changeset
   936
            buf.insert(index, (char)buffer[1]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   937
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   938
02bb8761fcce Initial load
duke
parents:
diff changeset
   939
        return buf.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   940
02bb8761fcce Initial load
duke
parents:
diff changeset
   941
02bb8761fcce Initial load
duke
parents:
diff changeset
   942
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   943
02bb8761fcce Initial load
duke
parents:
diff changeset
   944
    private static String delete(String str, int from, int to)
02bb8761fcce Initial load
duke
parents:
diff changeset
   945
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   946
        return str.substring(0, from) + str.substring(to, str.length());
02bb8761fcce Initial load
duke
parents:
diff changeset
   947
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   948
02bb8761fcce Initial load
duke
parents:
diff changeset
   949
    private static String replace(String target, String arg, String source)
02bb8761fcce Initial load
duke
parents:
diff changeset
   950
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   951
        int i = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   952
        i = target.indexOf(arg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   953
02bb8761fcce Initial load
duke
parents:
diff changeset
   954
        while(i != -1)
02bb8761fcce Initial load
duke
parents:
diff changeset
   955
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
   956
                String left = target.substring(0, i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   957
                String right = target.substring(i+arg.length());
02bb8761fcce Initial load
duke
parents:
diff changeset
   958
                target = new String(left+source+right);
02bb8761fcce Initial load
duke
parents:
diff changeset
   959
                i = target.indexOf(arg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   960
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   961
        return target;
02bb8761fcce Initial load
duke
parents:
diff changeset
   962
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   963
02bb8761fcce Initial load
duke
parents:
diff changeset
   964
    public static int computeValueTag(boolean codeBasePresent, int typeInfo, boolean chunkedEncoding){
02bb8761fcce Initial load
duke
parents:
diff changeset
   965
        int value_tag = kInitialValueTag;
02bb8761fcce Initial load
duke
parents:
diff changeset
   966
02bb8761fcce Initial load
duke
parents:
diff changeset
   967
        if (codeBasePresent)
02bb8761fcce Initial load
duke
parents:
diff changeset
   968
            value_tag = value_tag | 0x00000001;
02bb8761fcce Initial load
duke
parents:
diff changeset
   969
02bb8761fcce Initial load
duke
parents:
diff changeset
   970
        value_tag = value_tag | typeInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
   971
02bb8761fcce Initial load
duke
parents:
diff changeset
   972
        if (chunkedEncoding)
02bb8761fcce Initial load
duke
parents:
diff changeset
   973
            value_tag = value_tag | kChunkedMask;
02bb8761fcce Initial load
duke
parents:
diff changeset
   974
02bb8761fcce Initial load
duke
parents:
diff changeset
   975
        return value_tag;
02bb8761fcce Initial load
duke
parents:
diff changeset
   976
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   977
02bb8761fcce Initial load
duke
parents:
diff changeset
   978
    public static boolean isCodeBasePresent(int value_tag){
02bb8761fcce Initial load
duke
parents:
diff changeset
   979
        return ((value_tag & 0x00000001) == 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   980
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   981
02bb8761fcce Initial load
duke
parents:
diff changeset
   982
    public static int getTypeInfo(int value_tag){
02bb8761fcce Initial load
duke
parents:
diff changeset
   983
        return (value_tag & 0x00000006);
02bb8761fcce Initial load
duke
parents:
diff changeset
   984
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   985
02bb8761fcce Initial load
duke
parents:
diff changeset
   986
    public static boolean isChunkedEncoding(int value_tag){
02bb8761fcce Initial load
duke
parents:
diff changeset
   987
        return ((value_tag & kChunkedMask) != 0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   988
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   989
02bb8761fcce Initial load
duke
parents:
diff changeset
   990
    public static String getServerURL(){
02bb8761fcce Initial load
duke
parents:
diff changeset
   991
        return defaultServerURL;
02bb8761fcce Initial load
duke
parents:
diff changeset
   992
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   993
02bb8761fcce Initial load
duke
parents:
diff changeset
   994
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   995
     * Load a class and check that it is assignable to a given type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   996
     * @param className the class name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   997
     * @param remoteCodebase the codebase to use. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   998
     * @param loader the class loader of last resort. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   999
     * @param expectedType the expected type. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1000
     * @return the loaded class.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1001
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1002
    private Class loadClassOfType (String className,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1003
                                  String remoteCodebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1004
                                  ClassLoader loader,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1005
                                  Class expectedType,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1006
                                  ClassLoader expectedTypeClassLoader)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1007
        throws ClassNotFoundException {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1008
02bb8761fcce Initial load
duke
parents:
diff changeset
  1009
        Class loadedClass = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1010
02bb8761fcce Initial load
duke
parents:
diff changeset
  1011
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1012
            //Sequence finding of the stubs according to spec
02bb8761fcce Initial load
duke
parents:
diff changeset
  1013
            try{
02bb8761fcce Initial load
duke
parents:
diff changeset
  1014
                //If-else is put here for speed up of J2EE.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1015
                //According to the OMG spec, the if clause is not dead code.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1016
                //It can occur if some compiler has allowed generation
02bb8761fcce Initial load
duke
parents:
diff changeset
  1017
                //into org.omg.stub hierarchy for non-offending
02bb8761fcce Initial load
duke
parents:
diff changeset
  1018
                //classes. This will encourage people to
02bb8761fcce Initial load
duke
parents:
diff changeset
  1019
                //produce non-offending class stubs in their own hierarchy.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1020
                if(!PackagePrefixChecker
02bb8761fcce Initial load
duke
parents:
diff changeset
  1021
                   .hasOffendingPrefix(PackagePrefixChecker
02bb8761fcce Initial load
duke
parents:
diff changeset
  1022
                                       .withoutPackagePrefix(className))){
02bb8761fcce Initial load
duke
parents:
diff changeset
  1023
                    loadedClass = Util.loadClass
02bb8761fcce Initial load
duke
parents:
diff changeset
  1024
                        (PackagePrefixChecker.withoutPackagePrefix(className),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1025
                         remoteCodebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1026
                         loader);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1027
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1028
                    loadedClass = Util.loadClass
02bb8761fcce Initial load
duke
parents:
diff changeset
  1029
                        (className,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1030
                         remoteCodebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1031
                         loader);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1032
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1033
            } catch (ClassNotFoundException cnfe) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1034
                loadedClass = Util.loadClass
02bb8761fcce Initial load
duke
parents:
diff changeset
  1035
                    (className,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1036
                     remoteCodebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1037
                     loader);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1038
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1039
            if (expectedType == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1040
                return loadedClass;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1041
        } catch (ClassNotFoundException cnfe) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1042
            if (expectedType == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1043
                throw cnfe;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1044
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1045
02bb8761fcce Initial load
duke
parents:
diff changeset
  1046
        // If no class was not loaded, or if the loaded class is not of the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1047
        // correct type, make a further attempt to load the correct class
02bb8761fcce Initial load
duke
parents:
diff changeset
  1048
        // using the classloader of the expected type.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1049
        // _REVISIT_ Is this step necessary, or should the Util,loadClass
02bb8761fcce Initial load
duke
parents:
diff changeset
  1050
        // algorithm always produce a valid class if the setup is correct?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1051
        // Does the OMG standard algorithm need to be changed to include
02bb8761fcce Initial load
duke
parents:
diff changeset
  1052
        // this step?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1053
        if (loadedClass == null || !expectedType.isAssignableFrom(loadedClass)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1054
            if (expectedType.getClassLoader() != expectedTypeClassLoader)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1055
                throw new IllegalArgumentException("expectedTypeClassLoader not class loader of expectedType.");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1056
02bb8761fcce Initial load
duke
parents:
diff changeset
  1057
            if (expectedTypeClassLoader != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1058
                loadedClass = expectedTypeClassLoader.loadClass(className);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1059
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1060
                loadedClass = Class.forName(className);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1061
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1062
02bb8761fcce Initial load
duke
parents:
diff changeset
  1063
        return loadedClass;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1064
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1065
}