1 7 15 16 package com.sun.corba.se.impl.orbutil; 17 18 import java.util.StringTokenizer ; 19 import java.util.Hashtable ; 20 import java.io.IOException ; 21 import java.lang.reflect.Method ; 22 23 import java.net.MalformedURLException ; 25 import org.omg.CORBA.portable.ValueBase ; 26 import org.omg.CORBA.portable.IDLEntity ; 27 28 import com.sun.corba.se.impl.util.JDKBridge; 29 import com.sun.corba.se.impl.util.Utility; 30 import com.sun.corba.se.impl.util.PackagePrefixChecker; 31 import com.sun.corba.se.impl.util.IdentityHashtable; 32 import com.sun.corba.se.impl.io.ObjectStreamClass; 33 34 import javax.rmi.CORBA.Util ; 35 36 39 public class RepositoryId_1_3 { 40 41 48 public static final RepositoryIdCache_1_3 cache = new RepositoryIdCache_1_3(); 49 public static final byte[] IDL_IDENTIFIER_CHARS = { 50 51 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,1,0, 1,1,1,1, 1,1,1,1, 1,1,0,0, 0,0,0,0, 0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,1, 0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 0,1,1,1, 1,1,1,0, 1,1,1,1, 1,0,0,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 0,1,1,1, 1,1,1,0, 1,1,1,1, 1,0,0,1, }; 69 70 private static String defaultServerURL = null; 71 private static boolean useCodebaseOnly = false; 72 73 static { 74 if (defaultServerURL == null) 75 defaultServerURL = (String )JDKBridge.getLocalCodebase(); 76 useCodebaseOnly = JDKBridge.useCodebaseOnly(); 77 78 } 79 80 private static IdentityHashtable classToRepStr = new IdentityHashtable(); 81 private static IdentityHashtable classIDLToRepStr = new IdentityHashtable(); 82 private static IdentityHashtable classSeqToRepStr = new IdentityHashtable(); 83 84 private static IdentityHashtable repStrToByteArray = new IdentityHashtable(); 85 private static Hashtable repStrToClass = new Hashtable (); 86 87 private String repId = null; 88 private boolean isSupportedFormat = true; 89 private String typeString = null; 90 private String versionString = null; 91 private boolean isSequence = false; 92 private boolean isRMIValueType = false; 93 private boolean isIDLType = false; 94 private String completeClassName = null; 95 private String unqualifiedName = null; 96 private String definedInId = null; 97 private Class clazz = null; 98 private String suid = null, actualSuid = null; 99 private long suidLong = ObjectStreamClass.kDefaultUID, actualSuidLong = ObjectStreamClass.kDefaultUID; 100 101 private static final String kValuePrefix = "RMI:"; 103 private static final String kIDLPrefix = "IDL:"; 104 private static final String kIDLNamePrefix = "omg.org/"; 105 private static final String kIDLClassnamePrefix = "org.omg."; 106 private static final String kSequencePrefix = "["; 107 private static final String kCORBAPrefix = "CORBA/"; 108 private static final String kArrayPrefix = kValuePrefix + kSequencePrefix + kCORBAPrefix; 109 private static final int kValuePrefixLength = kValuePrefix.length(); 110 private static final int kIDLPrefixLength = kIDLPrefix.length(); 111 private static final int kSequencePrefixLength = kSequencePrefix.length(); 112 private static final String kInterfaceHashCode = ":0000000000000000"; 113 private static final String kInterfaceOnlyHashStr = "0000000000000000"; 114 private static final String kExternalizableHashStr = "0000000000000001"; 115 116 public static final int kInitialValueTag= 0x7fffff00; 118 public static final int kNoTypeInfo = 0; 119 public static final int kSingleRepTypeInfo = 0x02; 120 public static final int kPartialListTypeInfo = 0x06; 121 public static final int kChunkedMask = 0x08; 122 123 125 128 public static final String kWStringValueVersion = "1.0"; 130 public static final String kWStringValueHash = ":"+kWStringValueVersion; 131 public static final String kWStringStubValue = "WStringValue"; 132 public static final String kWStringTypeStr = "omg.org/CORBA/"+kWStringStubValue; 133 public static final String kWStringValueRepID = kIDLPrefix + kWStringTypeStr + kWStringValueHash; 134 135 public static final String kAnyRepID = kIDLPrefix + "omg.org/CORBA/Any"; 137 138 public static final String kClassDescValueHash = ":" + Long.toHexString( 140 ObjectStreamClass.getSerialVersionUID(javax.rmi.CORBA.ClassDesc .class)); 141 public static final String kClassDescStubValue = "ClassDesc"; 142 public static final String kClassDescTypeStr = "javax.rmi.CORBA."+kClassDescStubValue; 143 public static final String kClassDescValueRepID = kValuePrefix + kClassDescTypeStr + kClassDescValueHash; 144 145 public static final String kObjectValueHash = ":1.0"; 147 public static final String kObjectStubValue = "Object"; 148 149 public static final String kSequenceValueHash = ":1.0"; 151 public static final String kPrimitiveSequenceValueHash = ":0000000000000000"; 152 153 public static final String kSerializableValueHash = ":1.0"; 155 public static final String kSerializableStubValue = "Serializable"; 156 157 public static final String kExternalizableValueHash = ":1.0"; 159 public static final String kExternalizableStubValue = "Externalizable"; 160 161 public static final String kRemoteValueHash = ""; 163 public static final String kRemoteStubValue = ""; 164 public static final String kRemoteTypeStr = ""; 165 public static final String kRemoteValueRepID = ""; 166 167 public static final Hashtable kSpecialArrayTypeStrings = new Hashtable (); 168 169 static { 170 kSpecialArrayTypeStrings.put("CORBA.WStringValue", new StringBuffer (java.lang.String .class.getName())); 171 kSpecialArrayTypeStrings.put("javax.rmi.CORBA.ClassDesc", new StringBuffer (java.lang.Class .class.getName())); 172 kSpecialArrayTypeStrings.put("CORBA.Object", new StringBuffer (java.rmi.Remote .class.getName())); 173 174 } 175 176 public static final Hashtable kSpecialCasesRepIDs = new Hashtable (); 177 178 static { 179 kSpecialCasesRepIDs.put(java.lang.String .class, kWStringValueRepID); 180 kSpecialCasesRepIDs.put(java.lang.Class .class, kClassDescValueRepID); 181 kSpecialCasesRepIDs.put(java.rmi.Remote .class, kRemoteValueRepID); 182 } 183 184 public static final Hashtable kSpecialCasesStubValues = new Hashtable (); 185 186 static { 187 kSpecialCasesStubValues.put(java.lang.String .class, kWStringStubValue); 188 kSpecialCasesStubValues.put(java.lang.Class .class, kClassDescStubValue); 189 kSpecialCasesStubValues.put(java.lang.Object .class, kObjectStubValue); 190 kSpecialCasesStubValues.put(java.io.Serializable .class, kSerializableStubValue); 191 kSpecialCasesStubValues.put(java.io.Externalizable .class, kExternalizableStubValue); 192 kSpecialCasesStubValues.put(java.rmi.Remote .class, kRemoteStubValue); 193 } 194 195 196 public static final Hashtable kSpecialCasesVersions = new Hashtable (); 197 198 static { 199 kSpecialCasesVersions.put(java.lang.String .class, kWStringValueHash); 200 kSpecialCasesVersions.put(java.lang.Class .class, kClassDescValueHash); 201 kSpecialCasesVersions.put(java.lang.Object .class, kObjectValueHash); 202 kSpecialCasesVersions.put(java.io.Serializable .class, kSerializableValueHash); 203 kSpecialCasesVersions.put(java.io.Externalizable .class, kExternalizableValueHash); 204 kSpecialCasesVersions.put(java.rmi.Remote .class, kRemoteValueHash); 205 } 206 207 public static final Hashtable kSpecialCasesClasses = new Hashtable (); 208 209 static { 210 kSpecialCasesClasses.put(kWStringTypeStr, java.lang.String .class); 211 kSpecialCasesClasses.put(kClassDescTypeStr, java.lang.Class .class); 212 kSpecialCasesClasses.put(kRemoteTypeStr, java.rmi.Remote .class); 213 214 kSpecialCasesClasses.put("org.omg.CORBA.WStringValue", java.lang.String .class); 215 kSpecialCasesClasses.put("javax.rmi.CORBA.ClassDesc", java.lang.Class .class); 216 } 218 219 public static final Hashtable kSpecialCasesArrayPrefix = new Hashtable (); 220 221 static { 222 kSpecialCasesArrayPrefix.put(java.lang.String .class, kValuePrefix + kSequencePrefix + kCORBAPrefix); 223 kSpecialCasesArrayPrefix.put(java.lang.Class .class, kValuePrefix + kSequencePrefix + "javax/rmi/CORBA/"); 224 kSpecialCasesArrayPrefix.put(java.lang.Object .class, kValuePrefix + kSequencePrefix + "java/lang/"); 225 kSpecialCasesArrayPrefix.put(java.io.Serializable .class, kValuePrefix + kSequencePrefix + "java/io/"); 226 kSpecialCasesArrayPrefix.put(java.io.Externalizable .class, kValuePrefix + kSequencePrefix + "java/io/"); 227 kSpecialCasesArrayPrefix.put(java.rmi.Remote .class, kValuePrefix + kSequencePrefix + kCORBAPrefix); 228 } 229 230 public static final Hashtable kSpecialPrimitives = new Hashtable (); 231 232 static { 233 kSpecialPrimitives.put("int","long"); 234 kSpecialPrimitives.put("long","longlong"); 235 kSpecialPrimitives.put("byte","octet"); 236 } 237 238 241 private static final byte ASCII_HEX[] = { 242 (byte)'0', 243 (byte)'1', 244 (byte)'2', 245 (byte)'3', 246 (byte)'4', 247 (byte)'5', 248 (byte)'6', 249 (byte)'7', 250 (byte)'8', 251 (byte)'9', 252 (byte)'A', 253 (byte)'B', 254 (byte)'C', 255 (byte)'D', 256 (byte)'E', 257 (byte)'F', 258 }; 259 260 261 public static final String kjava_rmi_Remote = createForAnyType(java.rmi.Remote .class); 263 public static final String korg_omg_CORBA_Object = createForAnyType(org.omg.CORBA.Object .class); 264 265 public static final Class kNoParamTypes[] ={}; 267 public static final Object kNoArgs[] = {}; 268 269 270 RepositoryId_1_3(){} 271 272 RepositoryId_1_3(String aRepId){ 273 init(aRepId); 274 } 275 276 RepositoryId_1_3 init(String aRepId){ 277 278 this.repId = aRepId; 279 280 if (aRepId.length() == 0) { 282 clazz = java.rmi.Remote .class; 283 typeString = ""; 284 isRMIValueType = true; 285 suid = kInterfaceOnlyHashStr; 286 return this; 287 } 288 else if (aRepId.equals(kWStringValueRepID)) { 289 clazz = java.lang.String .class; 290 typeString = kWStringTypeStr; 291 isIDLType = true; 292 versionString = kWStringValueVersion; 293 return this; 294 } 295 else { 296 297 String repId = convertFromISOLatin1(aRepId); 298 299 versionString = repId.substring(repId.indexOf(':', repId.indexOf(':')+1)); 300 if (repId.startsWith(kIDLPrefix)) { 301 typeString = 302 repId.substring(kIDLPrefixLength, repId.indexOf(':', kIDLPrefixLength)); 303 isIDLType = true; 304 if (typeString.startsWith(kIDLNamePrefix)) 305 completeClassName = kIDLClassnamePrefix + 306 typeString.substring(kIDLNamePrefix.length()).replace('/','.'); 307 else completeClassName = typeString.replace('/','.'); 308 309 } 310 else if (repId.startsWith(kValuePrefix)) { 311 typeString = 312 repId.substring(kValuePrefixLength, repId.indexOf(':', kValuePrefixLength)); 313 isRMIValueType = true; 314 315 if (versionString.indexOf('.') == -1) { 316 actualSuid = versionString.substring(1); 317 suid = actualSuid; 319 if (actualSuid.indexOf(':') != -1){ 320 int pos = actualSuid.indexOf(':')+1; 322 suid = actualSuid.substring(pos); 325 actualSuid = actualSuid.substring(0, pos-1); 326 } 327 328 } 329 else { 330 } 332 } 333 else isSupportedFormat = false; 334 335 if (typeString.startsWith(kSequencePrefix)) { 336 isSequence = true; 337 } 338 339 340 return this; 341 } 342 } 343 344 public final String getUnqualifiedName() { 345 if (unqualifiedName == null){ 346 String className = getClassName(); 347 int index = (className != null) ? className.lastIndexOf('.') : -1; 348 if (index == -1){ 349 unqualifiedName = className; 350 definedInId = "IDL::1.0"; 351 } 352 else { 353 unqualifiedName = className.substring(index); 354 definedInId = "IDL:" + className.substring(0, index).replace('.','/') + ":1.0"; 355 } 356 } 357 358 return unqualifiedName; 359 } 360 361 public final String getDefinedInId() { 362 if (definedInId == null){ 363 getUnqualifiedName(); 364 } 365 366 return definedInId; 367 } 368 369 public final String getTypeString() { 370 return typeString; 371 } 372 373 public final String getVersionString() { 374 return versionString; 375 } 376 377 public final String getSerialVersionUID() { 378 return suid; 379 } 380 381 public final String getActualSerialVersionUID() { 382 return actualSuid; 383 } 384 public final long getSerialVersionUIDAsLong() { 385 return suidLong; 386 } 387 388 public final long getActualSerialVersionUIDAsLong() { 389 return actualSuidLong; 390 } 391 392 public final boolean isRMIValueType() { 393 return isRMIValueType; 394 } 395 396 public final boolean isIDLType() { 397 return isIDLType; 398 } 399 400 public final String getRepositoryId() { 401 return repId; 402 } 403 404 public static byte[] getByteArray(String repStr) { 405 synchronized (repStrToByteArray){ 406 return (byte[]) repStrToByteArray.get(repStr); 407 } 408 } 409 410 public static void setByteArray(String repStr, byte[] repStrBytes) { 411 synchronized (repStrToByteArray){ 412 repStrToByteArray.put(repStr, repStrBytes); 413 } 414 } 415 416 public final boolean isSequence() { 417 return isSequence; 418 } 419 420 public final boolean isSupportedFormat() { 421 return isSupportedFormat; 422 } 423 424 425 public final String getClassName() { 428 429 if (isRMIValueType) 430 return typeString; 431 else if (isIDLType) 432 return completeClassName; 433 else return null; 434 435 } 436 437 public final Class getAnyClassFromType() throws ClassNotFoundException { 441 try { 442 return getClassFromType(); 443 } catch (ClassNotFoundException cnfe) { 444 Class clz = (Class )repStrToClass.get(repId); 445 if (clz != null) 446 return clz; 447 else 448 throw cnfe; 449 } 450 } 451 452 public final Class getClassFromType() 453 throws ClassNotFoundException { 454 if (clazz != null) 455 return clazz; 456 457 Class specialCase = (Class )kSpecialCasesClasses.get(getClassName()); 458 459 if (specialCase != null){ 460 clazz = specialCase; 461 return specialCase; 462 } 463 else 464 { 465 try{ 466 return Util.loadClass(getClassName(), null, null); 467 } 468 catch(ClassNotFoundException cnfe){ 469 if (defaultServerURL != null) { 470 try{ 471 return getClassFromType(defaultServerURL); 472 } 473 catch(MalformedURLException mue){ 474 throw cnfe; 475 } 476 } 477 else throw cnfe; 478 } 479 } 480 481 } 482 483 public final Class getClassFromType(Class expectedType, String codebase) 484 throws ClassNotFoundException { 485 if (clazz != null) 486 return clazz; 487 488 Class specialCase = (Class )kSpecialCasesClasses.get(getClassName()); 489 490 if (specialCase != null){ 491 clazz = specialCase; 492 return specialCase; 493 } else { 494 ClassLoader expectedTypeClassLoader = (expectedType == null ? null : expectedType.getClassLoader()); 495 return loadClassOfType(getClassName(), 496 codebase, 497 expectedTypeClassLoader, 498 expectedType, 499 expectedTypeClassLoader); 500 } 501 502 } 503 504 public final Class getClassFromType(String url) 505 throws ClassNotFoundException , MalformedURLException { 506 return Util.loadClass(getClassName(), url, null); 507 } 508 509 public final String toString() { 510 return repId; 511 } 512 513 private static String createHashString(java.io.Serializable ser) { 514 515 return createHashString(ser.getClass()); 516 } 517 518 private static String createHashString(java.lang.Class clazz) { 519 520 if (clazz.isInterface() || !java.io.Serializable .class.isAssignableFrom(clazz)) 521 return kInterfaceHashCode; 522 523 524 long actualLong = ObjectStreamClassUtil_1_3.computeStructuralUID(false, clazz); 525 String hash = null; 526 if (actualLong == 0) 527 hash = kInterfaceOnlyHashStr; 528 else if (actualLong == 1) 529 hash = kExternalizableHashStr; 530 else 531 hash = Long.toHexString(actualLong).toUpperCase(); 532 while(hash.length() < 16){ 533 hash = "0" + hash; 534 } 535 536 long declaredLong = ObjectStreamClassUtil_1_3.computeSerialVersionUID(clazz); 537 String declared = null; 538 if (declaredLong == 0) 539 declared = kInterfaceOnlyHashStr; 540 else if (declaredLong == 1) 541 declared = kExternalizableHashStr; 542 else 543 declared = Long.toHexString(declaredLong).toUpperCase(); 544 while (declared.length() < 16){ 545 declared = "0" + declared; 546 } 547 hash = hash + ":" + declared; 548 549 return ":" + hash; 550 } 551 552 559 public static String createSequenceRepID(java.lang.Object ser){ 560 return createSequenceRepID(ser.getClass()); 561 } 562 563 569 public static String createSequenceRepID(java.lang.Class clazz){ 570 synchronized (classSeqToRepStr){ 571 572 String repid = (String )classSeqToRepStr.get(clazz); 573 if (repid != null) 574 return repid; 575 576 Class originalClazz = clazz; 577 578 Class type = null; 579 int numOfDims = 0; 580 581 while ((type = clazz.getComponentType()) != null) { 582 numOfDims++; 583 clazz = type; 584 } 585 586 if (clazz.isPrimitive()) 587 repid = kValuePrefix + originalClazz.getName() + kPrimitiveSequenceValueHash; 588 else { 589 StringBuffer buf = new StringBuffer (); 590 buf.append(kValuePrefix); 591 while(numOfDims-- > 0) { 592 buf.append("["); 593 } 594 buf.append("L"); 595 buf.append(convertToISOLatin1(clazz.getName())); 596 buf.append(";"); 597 buf.append(createHashString(clazz)); 598 repid = buf.toString(); 599 } 600 classSeqToRepStr.put(originalClazz,repid); 601 return repid; 602 } 603 604 } 605 606 607 public static String createForSpecialCase(java.lang.Class clazz){ 608 if (clazz.isArray()){ 609 return createSequenceRepID(clazz); 610 } 611 else { 612 return (String )kSpecialCasesRepIDs.get(clazz); 613 } 614 } 615 616 public static String createForSpecialCase(java.io.Serializable ser){ 617 Class clazz = ser.getClass(); 618 if (clazz.isArray()){ 619 return createSequenceRepID(ser); 620 } 621 else 622 return createForSpecialCase(clazz); 623 } 624 625 631 public static String createForJavaType(java.io.Serializable ser) 632 throws com.sun.corba.se.impl.io.TypeMismatchException 633 { 634 synchronized (classToRepStr) { 635 String repid = createForSpecialCase(ser); 636 if (repid != null) 637 return repid; 638 Class clazz = ser.getClass(); 639 repid = (String )classToRepStr.get(clazz); 640 641 if (repid != null) 642 return repid; 643 644 repid = kValuePrefix + convertToISOLatin1(clazz.getName()) + 645 createHashString(clazz); 646 647 classToRepStr.put(clazz, repid); 648 repStrToClass.put(repid, clazz); 649 return repid; 650 } 651 } 652 653 659 public static String createForJavaType(Class clz) 660 throws com.sun.corba.se.impl.io.TypeMismatchException 661 { 662 synchronized (classToRepStr){ 663 String repid = createForSpecialCase(clz); 664 if (repid != null) 665 return repid; 666 667 repid = (String )classToRepStr.get(clz); 668 if (repid != null) 669 return repid; 670 671 repid = kValuePrefix + convertToISOLatin1(clz.getName()) + 672 createHashString(clz); 673 674 classToRepStr.put(clz, repid); 675 repStrToClass.put(repid, clz); 676 return repid; 677 } 678 } 679 680 688 public static String createForIDLType(Class ser, int major, int minor) 689 throws com.sun.corba.se.impl.io.TypeMismatchException 690 { 691 synchronized (classIDLToRepStr){ 692 String repid = (String )classIDLToRepStr.get(ser); 693 if (repid != null) 694 return repid; 695 696 repid = kIDLPrefix + convertToISOLatin1(ser.getName()).replace('.','/') + 697 ":" + major + "." + minor; 698 classIDLToRepStr.put(ser, repid); 699 return repid; 700 } 701 } 702 703 private static String getIdFromHelper(Class clazz){ 704 try { 705 Class helperClazz = Utility.loadClassForClass(clazz.getName()+"Helper", null, 706 clazz.getClassLoader(), clazz, clazz.getClassLoader()); 707 Method idMethod = helperClazz.getDeclaredMethod("id", kNoParamTypes); 708 return (String )idMethod.invoke(null, kNoArgs); 709 } 710 catch(java.lang.ClassNotFoundException cnfe) 711 { 712 throw new org.omg.CORBA.MARSHAL (cnfe.toString()); 713 } 714 catch(java.lang.NoSuchMethodException nsme) 715 { 716 throw new org.omg.CORBA.MARSHAL (nsme.toString()); 717 } 718 catch(java.lang.reflect.InvocationTargetException ite) 719 { 720 throw new org.omg.CORBA.MARSHAL (ite.toString()); 721 } 722 catch(java.lang.IllegalAccessException iae) 723 { 724 throw new org.omg.CORBA.MARSHAL (iae.toString()); 725 } 726 } 727 728 734 public static String createForAnyType(Class type) { 735 try{ 736 if (type.isArray()) 737 return createSequenceRepID(type); 738 else if (IDLEntity .class.isAssignableFrom(type)) 739 { 740 try{ 741 return getIdFromHelper(type); 742 } 743 catch(Throwable t) { 744 return createForIDLType(type, 1, 0); 745 } 746 } 747 else return createForJavaType(type); 748 } 749 catch(com.sun.corba.se.impl.io.TypeMismatchException e){ 750 return null; 751 } 752 753 } 754 755 public static boolean isAbstractBase(Class clazz) { 756 return (clazz.isInterface() && 757 IDLEntity .class.isAssignableFrom(clazz) && 758 (!ValueBase .class.isAssignableFrom(clazz)) && 759 (!org.omg.CORBA.Object .class.isAssignableFrom(clazz))); 760 761 } 762 763 768 private static String convertToISOLatin1 (String name) { 769 770 int length = name.length(); 771 if (length == 0) { 772 return name; 773 } 774 StringBuffer buffer = null; 775 776 for (int i = 0; i < length; i++) { 777 778 char c = name.charAt(i); 779 780 if (c > 255 || IDL_IDENTIFIER_CHARS[c] == 0) { 781 782 784 if (buffer == null) { 785 786 788 buffer = new StringBuffer (name.substring(0,i)); 789 } 790 791 buffer.append( 793 "\\U" + 794 (char)ASCII_HEX[(c & 0xF000) >>> 12] + 795 (char)ASCII_HEX[(c & 0x0F00) >>> 8] + 796 (char)ASCII_HEX[(c & 0x00F0) >>> 4] + 797 (char)ASCII_HEX[(c & 0x000F)]); 798 799 } else { 800 if (buffer != null) { 801 buffer.append(c); 802 } 803 } 804 } 805 806 if (buffer != null) { 807 name = buffer.toString(); 808 } 809 810 return name; 811 } 812 813 818 private static String convertFromISOLatin1 (String name) { 819 820 int index = -1; 821 StringBuffer buf = new StringBuffer (name); 822 823 while ((index = buf.toString().indexOf("\\U")) != -1){ 824 String str = "0000" + buf.toString().substring(index+2, index+6); 825 826 byte[] buffer = new byte[(str.length() - 4) / 2]; 828 for (int i=4, j=0; i < str.length(); i +=2, j++) { 829 buffer[j] = (byte)((ORBUtility.hexOf(str.charAt(i)) << 4) & 0xF0); 830 buffer[j] |= (byte)((ORBUtility.hexOf(str.charAt(i+1)) << 0) & 0x0F); 831 } 832 buf = new StringBuffer (delete(buf.toString(), index, index+6)); 833 buf.insert(index, (char)buffer[1]); 834 } 835 836 return buf.toString(); 837 838 839 } 840 841 private static String delete(String str, int from, int to) 842 { 843 return str.substring(0, from) + str.substring(to, str.length()); 844 } 845 846 private static String replace(String target, String arg, String source) 847 { 848 int i = 0; 849 i = target.indexOf(arg); 850 851 while(i != -1) 852 { 853 String left = target.substring(0, i); 854 String right = target.substring(i+arg.length()); 855 target = new String (left+source+right); 856 i = target.indexOf(arg); 857 } 858 return target; 859 } 860 861 869 private Class loadClassOfType (String className, 870 String remoteCodebase, 871 ClassLoader loader, 872 Class expectedType, 873 ClassLoader expectedTypeClassLoader) 874 throws ClassNotFoundException { 875 876 Class loadedClass = null; 877 878 try { 879 try{ 881 if(!PackagePrefixChecker 888 .hasOffendingPrefix(PackagePrefixChecker 889 .withoutPackagePrefix(className))){ 890 loadedClass = Util.loadClass 891 (PackagePrefixChecker.withoutPackagePrefix(className), 892 remoteCodebase, 893 loader); 894 } else { 895 loadedClass = Util.loadClass 896 (className, 897 remoteCodebase, 898 loader); 899 } 900 } catch (ClassNotFoundException cnfe) { 901 loadedClass = Util.loadClass 902 (className, 903 remoteCodebase, 904 loader); 905 } 906 if (expectedType == null) 907 return loadedClass; 908 } catch (ClassNotFoundException cnfe) { 909 if (expectedType == null) 910 throw cnfe; 911 } 912 913 if (loadedClass == null || !expectedType.isAssignableFrom(loadedClass)) { 921 if (expectedType.getClassLoader() != expectedTypeClassLoader) 922 throw new IllegalArgumentException ("expectedTypeClassLoader not class loader of expectedType."); 923 924 if (expectedTypeClassLoader != null) 925 loadedClass = expectedTypeClassLoader.loadClass(className); 926 else 927 loadedClass = ORBClassLoader.loadClass(className); 928 } 929 930 return loadedClass; 931 } 932 933 938 public static boolean useFullValueDescription(Class clazz, String repositoryID) 939 throws IOException { 940 941 String clazzRepIDStr = createForAnyType(clazz); 942 943 if (clazzRepIDStr.equals(repositoryID)) 944 return false; 945 946 RepositoryId_1_3 targetRepid; 947 RepositoryId_1_3 clazzRepid; 948 949 synchronized(cache) { 950 954 targetRepid = cache.getId(repositoryID); 955 clazzRepid = cache.getId(clazzRepIDStr); 956 } 957 958 if ((targetRepid.isRMIValueType()) && (clazzRepid.isRMIValueType())){ 959 if (!targetRepid.getSerialVersionUID().equals(clazzRepid.getSerialVersionUID())) { 960 961 String mssg = "Mismatched serialization UIDs : Source (Rep. ID" + 962 clazzRepid + ") = " + 963 clazzRepid.getSerialVersionUID() + " whereas Target (Rep. ID " + repositoryID + 964 ") = " + targetRepid.getSerialVersionUID(); 965 throw new IOException (mssg); 966 } else { 967 return true; 968 } 969 } else { 970 971 throw new IOException ("The repository ID is not of an RMI value type (Expected ID = " + clazzRepIDStr + "; Received ID = " + repositoryID +")"); 972 } 973 } 974 } 975 976 | Popular Tags |