src/share/classes/com/sun/corba/se/impl/util/RepositoryId.java

Wed, 28 Mar 2012 02:50:50 -0700

author
mbankal
date
Wed, 28 Mar 2012 02:50:50 -0700
changeset 371
e324dfb90c9e
parent 158
91006f157c46
child 748
6845b95cba6b
permissions
-rw-r--r--

7079902: Refine CORBA data models
Reviewed-by: coffeys

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

mercurial