1 5 6 9 package com.sun.corba.se.impl.orbutil; 10 11 import java.util.StringTokenizer ; 12 import java.util.Hashtable ; 13 import java.io.IOException ; 14 import java.lang.reflect.Method ; 15 import java.net.MalformedURLException ; 16 import org.omg.CORBA.portable.ValueBase ; 17 import org.omg.CORBA.portable.IDLEntity ; 18 19 import com.sun.corba.se.impl.util.JDKBridge; 23 import com.sun.corba.se.impl.util.Utility; 24 import com.sun.corba.se.impl.util.PackagePrefixChecker; 25 import com.sun.corba.se.impl.util.IdentityHashtable; 26 27 import javax.rmi.CORBA.Util ; 28 29 38 public class RepositoryId_1_3_1 { 39 40 47 public static final byte[] IDL_IDENTIFIER_CHARS = { 48 49 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, }; 67 68 69 private static final long serialVersionUID = 123456789L; 70 71 private static String defaultServerURL = null; 72 private static boolean useCodebaseOnly = false; 73 74 static { 75 if (defaultServerURL == null) 76 defaultServerURL = (String )JDKBridge.getLocalCodebase(); 77 useCodebaseOnly = JDKBridge.useCodebaseOnly(); 78 79 } 80 81 private static IdentityHashtable classToRepStr = new IdentityHashtable(); 82 private static IdentityHashtable classIDLToRepStr = new IdentityHashtable(); 83 private static IdentityHashtable classSeqToRepStr = new IdentityHashtable(); 84 85 private static IdentityHashtable repStrToByteArray = new IdentityHashtable(); 86 private static Hashtable repStrToClass = new Hashtable (); 87 88 private String repId = null; 89 private boolean isSupportedFormat = true; 90 private String typeString = null; 91 private String versionString = null; 92 private boolean isSequence = false; 93 private boolean isRMIValueType = false; 94 private boolean isIDLType = false; 95 private String completeClassName = null; 96 private String unqualifiedName = null; 97 private String definedInId = null; 98 private Class clazz = null; 99 private String suid = null, actualSuid = null; 100 private long suidLong = ObjectStreamClass_1_3_1.kDefaultUID, actualSuidLong = ObjectStreamClass_1_3_1.kDefaultUID; 101 102 private static final String kSequenceKeyword = "seq"; 104 private static final String kValuePrefix = "RMI:"; 105 private static final String kIDLPrefix = "IDL:"; 106 private static final String kIDLNamePrefix = "omg.org/"; 107 private static final String kIDLClassnamePrefix = "org.omg."; 108 private static final String kSequencePrefix = "["; 109 private static final String kCORBAPrefix = "CORBA/"; 110 private static final String kArrayPrefix = kValuePrefix + kSequencePrefix + kCORBAPrefix; 111 private static final int kValuePrefixLength = kValuePrefix.length(); 112 private static final int kIDLPrefixLength = kIDLPrefix.length(); 113 private static final int kSequencePrefixLength = kSequencePrefix.length(); 114 private static final String kInterfaceHashCode = ":0000000000000000"; 115 private static final String kInterfaceOnlyHashStr = "0000000000000000"; 116 private static final String kExternalizableHashStr = "0000000000000001"; 117 118 public static final int kInitialValueTag= 0x7fffff00; 120 public static final int kNoTypeInfo = 0; 121 public static final int kSingleRepTypeInfo = 0x02; 122 public static final int kPartialListTypeInfo = 0x06; 123 public static final int kChunkedMask = 0x08; 124 public static final int kPreComputed_StandardRMIUnchunked = RepositoryId_1_3_1.computeValueTag(false, RepositoryId_1_3_1.kSingleRepTypeInfo, false); 125 public static final int kPreComputed_CodeBaseRMIUnchunked = RepositoryId_1_3_1.computeValueTag(true, RepositoryId_1_3_1.kSingleRepTypeInfo, false); 126 public static final int kPreComputed_StandardRMIChunked = RepositoryId_1_3_1.computeValueTag(false, RepositoryId_1_3_1.kSingleRepTypeInfo, true); 127 public static final int kPreComputed_CodeBaseRMIChunked = RepositoryId_1_3_1.computeValueTag(true, RepositoryId_1_3_1.kSingleRepTypeInfo, true); 128 129 public static final int kPreComputed_StandardRMIUnchunked_NoRep = RepositoryId_1_3_1.computeValueTag(false, RepositoryId_1_3_1.kNoTypeInfo, false); 130 public static final int kPreComputed_CodeBaseRMIUnchunked_NoRep = RepositoryId_1_3_1.computeValueTag(true, RepositoryId_1_3_1.kNoTypeInfo, false); 131 public static final int kPreComputed_StandardRMIChunked_NoRep = RepositoryId_1_3_1.computeValueTag(false, RepositoryId_1_3_1.kNoTypeInfo, true); 132 public static final int kPreComputed_CodeBaseRMIChunked_NoRep = RepositoryId_1_3_1.computeValueTag(true, RepositoryId_1_3_1.kNoTypeInfo, true); 133 134 136 139 public static final String kWStringValueVersion = "1.0"; 141 public static final String kWStringValueHash = ":"+kWStringValueVersion; 142 public static final String kWStringStubValue = "WStringValue"; 143 public static final String kWStringTypeStr = "omg.org/CORBA/"+kWStringStubValue; 144 public static final String kWStringValueRepID = kIDLPrefix + kWStringTypeStr + kWStringValueHash; 145 146 public static final String kAnyRepID = kIDLPrefix + "omg.org/CORBA/Any"; 148 149 public static final String kClassDescValueHash = ":" + 152 Long.toHexString( 153 ObjectStreamClass_1_3_1.getActualSerialVersionUID(javax.rmi.CORBA.ClassDesc .class)).toUpperCase() + ":" + 154 Long.toHexString( 155 ObjectStreamClass_1_3_1.getSerialVersionUID(javax.rmi.CORBA.ClassDesc .class)).toUpperCase(); 156 public static final String kClassDescStubValue = "ClassDesc"; 157 public static final String kClassDescTypeStr = "javax.rmi.CORBA."+kClassDescStubValue; 158 public static final String kClassDescValueRepID = kValuePrefix + kClassDescTypeStr + kClassDescValueHash; 159 160 public static final String kObjectValueHash = ":1.0"; 162 public static final String kObjectStubValue = "Object"; 163 164 public static final String kSequenceValueHash = ":1.0"; 166 public static final String kPrimitiveSequenceValueHash = ":0000000000000000"; 167 168 public static final String kSerializableValueHash = ":1.0"; 170 public static final String kSerializableStubValue = "Serializable"; 171 172 public static final String kExternalizableValueHash = ":1.0"; 174 public static final String kExternalizableStubValue = "Externalizable"; 175 176 public static final String kRemoteValueHash = ""; 178 public static final String kRemoteStubValue = ""; 179 public static final String kRemoteTypeStr = ""; 180 public static final String kRemoteValueRepID = ""; 181 182 public static final Hashtable kSpecialArrayTypeStrings = new Hashtable (); 183 184 static { 185 kSpecialArrayTypeStrings.put("CORBA.WStringValue", new StringBuffer (java.lang.String .class.getName())); 186 kSpecialArrayTypeStrings.put("javax.rmi.CORBA.ClassDesc", new StringBuffer (java.lang.Class .class.getName())); 187 kSpecialArrayTypeStrings.put("CORBA.Object", new StringBuffer (java.rmi.Remote .class.getName())); 188 189 } 190 191 public static final Hashtable kSpecialCasesRepIDs = new Hashtable (); 192 193 static { 194 kSpecialCasesRepIDs.put(java.lang.String .class, kWStringValueRepID); 195 kSpecialCasesRepIDs.put(java.lang.Class .class, kClassDescValueRepID); 196 kSpecialCasesRepIDs.put(java.rmi.Remote .class, kRemoteValueRepID); 197 } 198 199 public static final Hashtable kSpecialCasesStubValues = new Hashtable (); 200 201 static { 202 kSpecialCasesStubValues.put(java.lang.String .class, kWStringStubValue); 203 kSpecialCasesStubValues.put(java.lang.Class .class, kClassDescStubValue); 204 kSpecialCasesStubValues.put(java.lang.Object .class, kObjectStubValue); 205 kSpecialCasesStubValues.put(java.io.Serializable .class, kSerializableStubValue); 206 kSpecialCasesStubValues.put(java.io.Externalizable .class, kExternalizableStubValue); 207 kSpecialCasesStubValues.put(java.rmi.Remote .class, kRemoteStubValue); 208 } 209 210 211 public static final Hashtable kSpecialCasesVersions = new Hashtable (); 212 213 static { 214 kSpecialCasesVersions.put(java.lang.String .class, kWStringValueHash); 215 kSpecialCasesVersions.put(java.lang.Class .class, kClassDescValueHash); 216 kSpecialCasesVersions.put(java.lang.Object .class, kObjectValueHash); 217 kSpecialCasesVersions.put(java.io.Serializable .class, kSerializableValueHash); 218 kSpecialCasesVersions.put(java.io.Externalizable .class, kExternalizableValueHash); 219 kSpecialCasesVersions.put(java.rmi.Remote .class, kRemoteValueHash); 220 } 221 222 public static final Hashtable kSpecialCasesClasses = new Hashtable (); 223 224 static { 225 kSpecialCasesClasses.put(kWStringTypeStr, java.lang.String .class); 226 kSpecialCasesClasses.put(kClassDescTypeStr, java.lang.Class .class); 227 kSpecialCasesClasses.put(kRemoteTypeStr, java.rmi.Remote .class); 228 229 kSpecialCasesClasses.put("org.omg.CORBA.WStringValue", java.lang.String .class); 230 kSpecialCasesClasses.put("javax.rmi.CORBA.ClassDesc", java.lang.Class .class); 231 } 233 234 public static final Hashtable kSpecialCasesArrayPrefix = new Hashtable (); 235 236 static { 237 kSpecialCasesArrayPrefix.put(java.lang.String .class, kValuePrefix + kSequencePrefix + kCORBAPrefix); 238 kSpecialCasesArrayPrefix.put(java.lang.Class .class, kValuePrefix + kSequencePrefix + "javax/rmi/CORBA/"); 239 kSpecialCasesArrayPrefix.put(java.lang.Object .class, kValuePrefix + kSequencePrefix + "java/lang/"); 240 kSpecialCasesArrayPrefix.put(java.io.Serializable .class, kValuePrefix + kSequencePrefix + "java/io/"); 241 kSpecialCasesArrayPrefix.put(java.io.Externalizable .class, kValuePrefix + kSequencePrefix + "java/io/"); 242 kSpecialCasesArrayPrefix.put(java.rmi.Remote .class, kValuePrefix + kSequencePrefix + kCORBAPrefix); 243 } 244 245 public static final Hashtable kSpecialPrimitives = new Hashtable (); 246 247 static { 248 kSpecialPrimitives.put("int","long"); 249 kSpecialPrimitives.put("long","longlong"); 250 kSpecialPrimitives.put("byte","octet"); 251 } 252 253 256 private static final byte ASCII_HEX[] = { 257 (byte)'0', 258 (byte)'1', 259 (byte)'2', 260 (byte)'3', 261 (byte)'4', 262 (byte)'5', 263 (byte)'6', 264 (byte)'7', 265 (byte)'8', 266 (byte)'9', 267 (byte)'A', 268 (byte)'B', 269 (byte)'C', 270 (byte)'D', 271 (byte)'E', 272 (byte)'F', 273 }; 274 275 276 public static final RepositoryIdCache_1_3_1 cache = new RepositoryIdCache_1_3_1(); 279 280 public static final String kjava_rmi_Remote = createForAnyType(java.rmi.Remote .class); 282 public static final String korg_omg_CORBA_Object = createForAnyType(org.omg.CORBA.Object .class); 283 284 public static final Class kNoParamTypes[] ={}; 286 public static final Object kNoArgs[] = {}; 287 288 289 292 RepositoryId_1_3_1(){} 293 294 RepositoryId_1_3_1(String aRepId){ 295 init(aRepId); 296 } 297 298 RepositoryId_1_3_1 init(String aRepId){ 299 300 this.repId = aRepId; 301 302 if (aRepId.length() == 0) { 304 clazz = java.rmi.Remote .class; 305 typeString = ""; 306 isRMIValueType = true; 307 suid = kInterfaceOnlyHashStr; 308 return this; 309 } 310 else if (aRepId.equals(kWStringValueRepID)) { 311 clazz = java.lang.String .class; 312 typeString = kWStringTypeStr; 313 isIDLType = true; 314 completeClassName = "java.lang.String"; 317 versionString = kWStringValueVersion; 318 return this; 319 } 320 else { 321 322 String repId = convertFromISOLatin1(aRepId); 323 324 versionString = repId.substring(repId.indexOf(':', repId.indexOf(':')+1)); 325 if (repId.startsWith(kIDLPrefix)) { 326 typeString = 327 repId.substring(kIDLPrefixLength, repId.indexOf(':', kIDLPrefixLength)); 328 isIDLType = true; 329 if (typeString.startsWith(kIDLNamePrefix)) 330 completeClassName = kIDLClassnamePrefix + 331 typeString.substring(kIDLNamePrefix.length()).replace('/','.'); 332 else completeClassName = typeString.replace('/','.'); 333 334 } 335 else if (repId.startsWith(kValuePrefix)) { 336 typeString = 337 repId.substring(kValuePrefixLength, repId.indexOf(':', kValuePrefixLength)); 338 isRMIValueType = true; 339 340 if (versionString.indexOf('.') == -1) { 341 actualSuid = versionString.substring(1); 342 suid = actualSuid; 344 if (actualSuid.indexOf(':') != -1){ 345 int pos = actualSuid.indexOf(':')+1; 347 suid = actualSuid.substring(pos); 350 actualSuid = actualSuid.substring(0, pos-1); 351 } 352 353 } 354 else { 355 } 357 } 358 else isSupportedFormat = false; 359 360 if (typeString.startsWith(kSequencePrefix)) { 361 isSequence = true; 362 } 363 364 365 return this; 366 } 367 } 368 369 public final String getUnqualifiedName() { 370 if (unqualifiedName == null){ 371 String className = getClassName(); 372 int index = className.lastIndexOf('.'); 373 if (index == -1){ 374 unqualifiedName = className; 375 definedInId = "IDL::1.0"; 376 } 377 else { 378 unqualifiedName = className.substring(index); 379 definedInId = "IDL:" + className.substring(0, index).replace('.','/') + ":1.0"; 380 } 381 } 382 383 return unqualifiedName; 384 } 385 386 public final String getDefinedInId() { 387 if (definedInId == null){ 388 getUnqualifiedName(); 389 } 390 391 return definedInId; 392 } 393 394 public final String getTypeString() { 395 return typeString; 396 } 397 398 public final String getVersionString() { 399 return versionString; 400 } 401 402 public final String getSerialVersionUID() { 403 return suid; 404 } 405 406 public final String getActualSerialVersionUID() { 407 return actualSuid; 408 } 409 public final long getSerialVersionUIDAsLong() { 410 return suidLong; 411 } 412 413 public final long getActualSerialVersionUIDAsLong() { 414 return actualSuidLong; 415 } 416 417 public final boolean isRMIValueType() { 418 return isRMIValueType; 419 } 420 421 public final boolean isIDLType() { 422 return isIDLType; 423 } 424 425 public final String getRepositoryId() { 426 return repId; 427 } 428 429 public static byte[] getByteArray(String repStr) { 430 synchronized (repStrToByteArray){ 431 return (byte[]) repStrToByteArray.get(repStr); 432 } 433 } 434 435 public static void setByteArray(String repStr, byte[] repStrBytes) { 436 synchronized (repStrToByteArray){ 437 repStrToByteArray.put(repStr, repStrBytes); 438 } 439 } 440 441 public final boolean isSequence() { 442 return isSequence; 443 } 444 445 public final boolean isSupportedFormat() { 446 return isSupportedFormat; 447 } 448 449 450 public final String getClassName() { 453 454 if (isRMIValueType) 455 return typeString; 456 else if (isIDLType) 457 return completeClassName; 458 else return null; 459 460 } 461 462 public final Class getAnyClassFromType() throws ClassNotFoundException { 466 try { 467 return getClassFromType(); 468 } catch (ClassNotFoundException cnfe) { 469 Class clz = (Class )repStrToClass.get(repId); 470 if (clz != null) 471 return clz; 472 else 473 throw cnfe; 474 } 475 } 476 477 public final Class getClassFromType() 478 throws ClassNotFoundException { 479 if (clazz != null) 480 return clazz; 481 482 Class specialCase = (Class )kSpecialCasesClasses.get(getClassName()); 483 484 if (specialCase != null){ 485 clazz = specialCase; 486 return specialCase; 487 } 488 else 489 { 490 try{ 491 return Util.loadClass(getClassName(), null, null); 492 } 493 catch(ClassNotFoundException cnfe){ 494 if (defaultServerURL != null) { 495 try{ 496 return getClassFromType(defaultServerURL); 497 } 498 catch(MalformedURLException mue){ 499 throw cnfe; 500 } 501 } 502 else throw cnfe; 503 } 504 } 505 506 } 507 508 public final Class getClassFromType(Class expectedType, String codebase) 509 throws ClassNotFoundException { 510 if (clazz != null) 511 return clazz; 512 513 Class specialCase = (Class )kSpecialCasesClasses.get(getClassName()); 514 515 if (specialCase != null){ 516 clazz = specialCase; 517 return specialCase; 518 } else { 519 ClassLoader expectedTypeClassLoader = (expectedType == null ? null : expectedType.getClassLoader()); 520 return loadClassOfType(getClassName(), 521 codebase, 522 expectedTypeClassLoader, 523 expectedType, 524 expectedTypeClassLoader); 525 } 526 527 } 528 529 public final Class getClassFromType(String url) 530 throws ClassNotFoundException , MalformedURLException { 531 return Util.loadClass(getClassName(), url, null); 532 } 533 534 public final String toString() { 535 return repId; 536 } 537 538 543 public static boolean useFullValueDescription(Class clazz, String repositoryID) 544 throws IOException { 545 546 String clazzRepIDStr = createForAnyType(clazz); 547 548 if (clazzRepIDStr.equals(repositoryID)) 549 return false; 550 551 RepositoryId_1_3_1 targetRepid; 552 RepositoryId_1_3_1 clazzRepid; 553 554 synchronized(cache) { 555 559 targetRepid = cache.getId(repositoryID); 560 clazzRepid = cache.getId(clazzRepIDStr); 561 } 562 564 if ((targetRepid.isRMIValueType()) && (clazzRepid.isRMIValueType())){ 565 if (!targetRepid.getSerialVersionUID().equals(clazzRepid.getSerialVersionUID())) { 566 567 String mssg = "Mismatched serialization UIDs : Source (Rep. ID" + 568 clazzRepid + ") = " + 569 clazzRepid.getSerialVersionUID() + " whereas Target (Rep. ID " + repositoryID + 570 ") = " + targetRepid.getSerialVersionUID(); 571 throw new IOException (mssg); 573 } 574 else { 575 return true; 576 } 577 } 578 else { 579 580 throw new IOException ("The repository ID is not of an RMI value type (Expected ID = " + clazzRepIDStr + "; Received ID = " + repositoryID +")"); 581 } 582 } 583 584 private static String createHashString(java.io.Serializable ser) { 585 586 return createHashString(ser.getClass()); 587 } 588 589 private static String createHashString(java.lang.Class clazz) { 590 591 if (clazz.isInterface() || !java.io.Serializable .class.isAssignableFrom(clazz)) 592 return kInterfaceHashCode; 593 594 596 long actualLong = ObjectStreamClass_1_3_1.getActualSerialVersionUID(clazz); 597 String hash = null; 598 if (actualLong == 0) 599 hash = kInterfaceOnlyHashStr; 600 else if (actualLong == 1) 601 hash = kExternalizableHashStr; 602 else 603 hash = Long.toHexString(actualLong).toUpperCase(); 604 while(hash.length() < 16){ 605 hash = "0" + hash; 606 } 607 608 long declaredLong = ObjectStreamClass_1_3_1.getSerialVersionUID(clazz); 609 String declared = null; 610 if (declaredLong == 0) 611 declared = kInterfaceOnlyHashStr; 612 else if (declaredLong == 1) 613 declared = kExternalizableHashStr; 614 else 615 declared = Long.toHexString(declaredLong).toUpperCase(); 616 while (declared.length() < 16){ 617 declared = "0" + declared; 618 } 619 hash = hash + ":" + declared; 620 621 return ":" + hash; 622 } 623 624 631 public static String createSequenceRepID(java.lang.Object ser){ 632 return createSequenceRepID(ser.getClass()); 633 } 634 635 641 public static String createSequenceRepID(java.lang.Class clazz){ 642 synchronized (classSeqToRepStr){ 643 644 String repid = (String )classSeqToRepStr.get(clazz); 645 if (repid != null) 646 return repid; 647 648 Class originalClazz = clazz; 649 650 Class type = null; 651 int numOfDims = 0; 652 653 while ((type = clazz.getComponentType()) != null) { 654 numOfDims++; 655 clazz = type; 656 } 657 658 if (clazz.isPrimitive()) 659 repid = kValuePrefix + originalClazz.getName() + kPrimitiveSequenceValueHash; 660 else { 661 StringBuffer buf = new StringBuffer (); 662 buf.append(kValuePrefix); 663 while(numOfDims-- > 0) { 664 buf.append("["); 665 } 666 buf.append("L"); 667 buf.append(convertToISOLatin1(clazz.getName())); 668 buf.append(";"); 669 buf.append(createHashString(clazz)); 670 repid = buf.toString(); 671 } 672 classSeqToRepStr.put(originalClazz,repid); 673 return repid; 674 } 675 676 } 677 678 679 public static String createForSpecialCase(java.lang.Class clazz){ 680 if (clazz.isArray()){ 681 return createSequenceRepID(clazz); 682 } 683 else { 684 return (String )kSpecialCasesRepIDs.get(clazz); 685 } 686 } 687 688 public static String createForSpecialCase(java.io.Serializable ser){ 689 Class clazz = ser.getClass(); 690 if (clazz.isArray()){ 691 return createSequenceRepID(ser); 692 } 693 else 694 return createForSpecialCase(clazz); 695 } 696 697 703 public static String createForJavaType(java.io.Serializable ser) 704 throws com.sun.corba.se.impl.io.TypeMismatchException 705 { 706 synchronized (classToRepStr) { 707 String repid = createForSpecialCase(ser); 708 if (repid != null) 709 return repid; 710 Class clazz = ser.getClass(); 711 repid = (String )classToRepStr.get(clazz); 712 713 if (repid != null) 714 return repid; 715 716 repid = kValuePrefix + convertToISOLatin1(clazz.getName()) + 717 createHashString(clazz); 718 719 classToRepStr.put(clazz, repid); 720 repStrToClass.put(repid, clazz); 721 return repid; 722 } 723 } 724 725 731 public static String createForJavaType(Class clz) 732 throws com.sun.corba.se.impl.io.TypeMismatchException 733 { 734 synchronized (classToRepStr){ 735 String repid = createForSpecialCase(clz); 736 if (repid != null) 737 return repid; 738 739 repid = (String )classToRepStr.get(clz); 740 if (repid != null) 741 return repid; 742 743 repid = kValuePrefix + convertToISOLatin1(clz.getName()) + 744 createHashString(clz); 745 746 classToRepStr.put(clz, repid); 747 repStrToClass.put(repid, clz); 748 return repid; 749 } 750 } 751 752 760 public static String createForIDLType(Class ser, int major, int minor) 761 throws com.sun.corba.se.impl.io.TypeMismatchException 762 { 763 synchronized (classIDLToRepStr){ 764 String repid = (String )classIDLToRepStr.get(ser); 765 if (repid != null) 766 return repid; 767 768 repid = kIDLPrefix + convertToISOLatin1(ser.getName()).replace('.','/') + 769 ":" + major + "." + minor; 770 classIDLToRepStr.put(ser, repid); 771 return repid; 772 } 773 } 774 775 private static String getIdFromHelper(Class clazz){ 776 try { 777 Class helperClazz = Utility.loadClassForClass(clazz.getName()+"Helper", null, 778 clazz.getClassLoader(), clazz, clazz.getClassLoader()); 779 Method idMethod = helperClazz.getDeclaredMethod("id", kNoParamTypes); 780 return (String )idMethod.invoke(null, kNoArgs); 781 } 782 catch(java.lang.ClassNotFoundException cnfe) 783 { 784 throw new org.omg.CORBA.MARSHAL (cnfe.toString()); 785 } 786 catch(java.lang.NoSuchMethodException nsme) 787 { 788 throw new org.omg.CORBA.MARSHAL (nsme.toString()); 789 } 790 catch(java.lang.reflect.InvocationTargetException ite) 791 { 792 throw new org.omg.CORBA.MARSHAL (ite.toString()); 793 } 794 catch(java.lang.IllegalAccessException iae) 795 { 796 throw new org.omg.CORBA.MARSHAL (iae.toString()); 797 } 798 } 799 800 806 public static String createForAnyType(Class type) { 807 try{ 808 if (type.isArray()) 809 return createSequenceRepID(type); 810 else if (IDLEntity .class.isAssignableFrom(type)) 811 { 812 try{ 813 return getIdFromHelper(type); 814 } 815 catch(Throwable t) { 816 return createForIDLType(type, 1, 0); 817 } 818 } 819 else return createForJavaType(type); 820 } 821 catch(com.sun.corba.se.impl.io.TypeMismatchException e){ 822 return null; 823 } 824 825 } 826 827 public static boolean isAbstractBase(Class clazz) { 828 return (clazz.isInterface() && 829 IDLEntity .class.isAssignableFrom(clazz) && 830 (!ValueBase .class.isAssignableFrom(clazz)) && 831 (!org.omg.CORBA.Object .class.isAssignableFrom(clazz))); 832 833 } 834 835 public static boolean isAnyRequired(Class clazz) { 836 return ((clazz == java.lang.Object .class) || 837 (clazz == java.io.Serializable .class) || 838 (clazz == java.io.Externalizable .class)); 839 } 840 841 public static long fromHex(String hexNumber) { 842 if (hexNumber.startsWith("0x")) 843 return Long.valueOf(hexNumber.substring(2), 16).longValue(); 844 else return Long.valueOf(hexNumber, 16).longValue(); 845 } 846 847 852 private static String convertToISOLatin1 (String name) { 853 854 int length = name.length(); 855 if (length == 0) { 856 return name; 857 } 858 StringBuffer buffer = null; 859 860 for (int i = 0; i < length; i++) { 861 862 char c = name.charAt(i); 863 864 if (c > 255 || IDL_IDENTIFIER_CHARS[c] == 0) { 865 866 868 if (buffer == null) { 869 870 872 buffer = new StringBuffer (name.substring(0,i)); 873 } 874 875 buffer.append( 877 "\\U" + 878 (char)ASCII_HEX[(c & 0xF000) >>> 12] + 879 (char)ASCII_HEX[(c & 0x0F00) >>> 8] + 880 (char)ASCII_HEX[(c & 0x00F0) >>> 4] + 881 (char)ASCII_HEX[(c & 0x000F)]); 882 883 } else { 884 if (buffer != null) { 885 buffer.append(c); 886 } 887 } 888 } 889 890 if (buffer != null) { 891 name = buffer.toString(); 892 } 893 894 return name; 895 } 896 897 902 private static String convertFromISOLatin1 (String name) { 903 904 int index = -1; 905 StringBuffer buf = new StringBuffer (name); 906 907 while ((index = buf.toString().indexOf("\\U")) != -1){ 908 String str = "0000" + buf.toString().substring(index+2, index+6); 909 910 byte[] buffer = new byte[(str.length() - 4) / 2]; 912 for (int i=4, j=0; i < str.length(); i +=2, j++) { 913 buffer[j] = (byte)((ORBUtility.hexOf(str.charAt(i)) << 4) & 0xF0); 914 buffer[j] |= (byte)((ORBUtility.hexOf(str.charAt(i+1)) << 0) & 0x0F); 915 } 916 buf = new StringBuffer (delete(buf.toString(), index, index+6)); 917 buf.insert(index, (char)buffer[1]); 918 } 919 920 return buf.toString(); 921 922 923 } 924 925 private static String delete(String str, int from, int to) 926 { 927 return str.substring(0, from) + str.substring(to, str.length()); 928 } 929 930 private static String replace(String target, String arg, String source) 931 { 932 int i = 0; 933 i = target.indexOf(arg); 934 935 while(i != -1) 936 { 937 String left = target.substring(0, i); 938 String right = target.substring(i+arg.length()); 939 target = new String (left+source+right); 940 i = target.indexOf(arg); 941 } 942 return target; 943 } 944 945 public static int computeValueTag(boolean codeBasePresent, int typeInfo, boolean chunkedEncoding){ 946 int value_tag = kInitialValueTag; 947 948 if (codeBasePresent) 949 value_tag = value_tag | 0x00000001; 950 951 value_tag = value_tag | typeInfo; 952 953 if (chunkedEncoding) 954 value_tag = value_tag | kChunkedMask; 955 956 return value_tag; 957 } 958 959 public static boolean isCodeBasePresent(int value_tag){ 960 return ((value_tag & 0x00000001) == 1); 961 } 962 963 public static int getTypeInfo(int value_tag){ 964 return (value_tag & 0x00000006); 965 } 966 967 public static boolean isChunkedEncoding(int value_tag){ 968 return ((value_tag & kChunkedMask) != 0); 969 } 970 971 public static String getServerURL(){ 972 return defaultServerURL; 973 } 974 975 983 private Class loadClassOfType (String className, 984 String remoteCodebase, 985 ClassLoader loader, 986 Class expectedType, 987 ClassLoader expectedTypeClassLoader) 988 throws ClassNotFoundException { 989 990 Class loadedClass = null; 991 992 try { 993 try{ 995 if(!PackagePrefixChecker 1002 .hasOffendingPrefix(PackagePrefixChecker 1003 .withoutPackagePrefix(className))){ 1004 loadedClass = Util.loadClass 1005 (PackagePrefixChecker.withoutPackagePrefix(className), 1006 remoteCodebase, 1007 loader); 1008 } else { 1009 loadedClass = Util.loadClass 1010 (className, 1011 remoteCodebase, 1012 loader); 1013 } 1014 } catch (ClassNotFoundException cnfe) { 1015 loadedClass = Util.loadClass 1016 (className, 1017 remoteCodebase, 1018 loader); 1019 } 1020 if (expectedType == null) 1021 return loadedClass; 1022 } catch (ClassNotFoundException cnfe) { 1023 if (expectedType == null) 1024 throw cnfe; 1025 } 1026 1027 if (loadedClass == null || !expectedType.isAssignableFrom(loadedClass)) { 1035 if (expectedType.getClassLoader() != expectedTypeClassLoader) 1036 throw new IllegalArgumentException ("expectedTypeClassLoader not class loader of expectedType."); 1037 1038 if (expectedTypeClassLoader != null) 1039 loadedClass = expectedTypeClassLoader.loadClass(className); 1040 else 1041 loadedClass = Class.forName(className); 1042 } 1043 1044 return loadedClass; 1045 } 1046} 1047 1048 | Popular Tags |