1 7 15 16 package com.sun.corba.se.impl.util; 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.io.ObjectStreamClass; 32 33 import javax.rmi.CORBA.Util ; 34 import sun.misc.SoftCache; 35 import java.util.WeakHashMap ; 36 37 public class RepositoryId { 38 39 46 public static final byte[] IDL_IDENTIFIER_CHARS = { 47 48 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, }; 66 67 68 private static final long serialVersionUID = 123456789L; 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 WeakHashMap classToRepStr = new WeakHashMap (); 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 SoftCache repStrToClass = new SoftCache(); 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 kSequenceKeyword = "seq"; 103 private static final String kValuePrefix = "RMI:"; 104 private static final String kIDLPrefix = "IDL:"; 105 private static final String kIDLNamePrefix = "omg.org/"; 106 private static final String kIDLClassnamePrefix = "org.omg."; 107 private static final String kSequencePrefix = "["; 108 private static final String kCORBAPrefix = "CORBA/"; 109 private static final String kArrayPrefix = kValuePrefix + kSequencePrefix + kCORBAPrefix; 110 private static final int kValuePrefixLength = kValuePrefix.length(); 111 private static final int kIDLPrefixLength = kIDLPrefix.length(); 112 private static final int kSequencePrefixLength = kSequencePrefix.length(); 113 private static final String kInterfaceHashCode = ":0000000000000000"; 114 private static final String kInterfaceOnlyHashStr = "0000000000000000"; 115 private static final String kExternalizableHashStr = "0000000000000001"; 116 117 public static final int kInitialValueTag= 0x7fffff00; 119 public static final int kNoTypeInfo = 0; 120 public static final int kSingleRepTypeInfo = 0x02; 121 public static final int kPartialListTypeInfo = 0x06; 122 public static final int kChunkedMask = 0x08; 123 public static final int kPreComputed_StandardRMIUnchunked = RepositoryId.computeValueTag(false, RepositoryId.kSingleRepTypeInfo, false); 124 public static final int kPreComputed_CodeBaseRMIUnchunked = RepositoryId.computeValueTag(true, RepositoryId.kSingleRepTypeInfo, false); 125 public static final int kPreComputed_StandardRMIChunked = RepositoryId.computeValueTag(false, RepositoryId.kSingleRepTypeInfo, true); 126 public static final int kPreComputed_CodeBaseRMIChunked = RepositoryId.computeValueTag(true, RepositoryId.kSingleRepTypeInfo, true); 127 128 public static final int kPreComputed_StandardRMIUnchunked_NoRep = RepositoryId.computeValueTag(false, RepositoryId.kNoTypeInfo, false); 129 public static final int kPreComputed_CodeBaseRMIUnchunked_NoRep = RepositoryId.computeValueTag(true, RepositoryId.kNoTypeInfo, false); 130 public static final int kPreComputed_StandardRMIChunked_NoRep = RepositoryId.computeValueTag(false, RepositoryId.kNoTypeInfo, true); 131 public static final int kPreComputed_CodeBaseRMIChunked_NoRep = RepositoryId.computeValueTag(true, RepositoryId.kNoTypeInfo, true); 132 133 135 138 public static final String kWStringValueVersion = "1.0"; 140 public static final String kWStringValueHash = ":"+kWStringValueVersion; 141 public static final String kWStringStubValue = "WStringValue"; 142 public static final String kWStringTypeStr = "omg.org/CORBA/"+kWStringStubValue; 143 public static final String kWStringValueRepID = kIDLPrefix + kWStringTypeStr + kWStringValueHash; 144 145 public static final String kAnyRepID = kIDLPrefix + "omg.org/CORBA/Any"; 147 148 public static final String kClassDescValueHash = ":" + 151 Long.toHexString( 152 ObjectStreamClass.getActualSerialVersionUID(javax.rmi.CORBA.ClassDesc .class)).toUpperCase() + ":" + 153 Long.toHexString( 154 ObjectStreamClass.getSerialVersionUID(javax.rmi.CORBA.ClassDesc .class)).toUpperCase(); 155 public static final String kClassDescStubValue = "ClassDesc"; 156 public static final String kClassDescTypeStr = "javax.rmi.CORBA."+kClassDescStubValue; 157 public static final String kClassDescValueRepID = kValuePrefix + kClassDescTypeStr + kClassDescValueHash; 158 159 public static final String kObjectValueHash = ":1.0"; 161 public static final String kObjectStubValue = "Object"; 162 163 public static final String kSequenceValueHash = ":1.0"; 165 public static final String kPrimitiveSequenceValueHash = ":0000000000000000"; 166 167 public static final String kSerializableValueHash = ":1.0"; 169 public static final String kSerializableStubValue = "Serializable"; 170 171 public static final String kExternalizableValueHash = ":1.0"; 173 public static final String kExternalizableStubValue = "Externalizable"; 174 175 public static final String kRemoteValueHash = ""; 177 public static final String kRemoteStubValue = ""; 178 public static final String kRemoteTypeStr = ""; 179 public static final String kRemoteValueRepID = ""; 180 181 public static final Hashtable kSpecialArrayTypeStrings = new Hashtable (); 182 183 static { 184 kSpecialArrayTypeStrings.put("CORBA.WStringValue", new StringBuffer (java.lang.String .class.getName())); 185 kSpecialArrayTypeStrings.put("javax.rmi.CORBA.ClassDesc", new StringBuffer (java.lang.Class .class.getName())); 186 kSpecialArrayTypeStrings.put("CORBA.Object", new StringBuffer (java.rmi.Remote .class.getName())); 187 188 } 189 190 public static final Hashtable kSpecialCasesRepIDs = new Hashtable (); 191 192 static { 193 kSpecialCasesRepIDs.put(java.lang.String .class, kWStringValueRepID); 194 kSpecialCasesRepIDs.put(java.lang.Class .class, kClassDescValueRepID); 195 kSpecialCasesRepIDs.put(java.rmi.Remote .class, kRemoteValueRepID); 196 } 197 198 public static final Hashtable kSpecialCasesStubValues = new Hashtable (); 199 200 static { 201 kSpecialCasesStubValues.put(java.lang.String .class, kWStringStubValue); 202 kSpecialCasesStubValues.put(java.lang.Class .class, kClassDescStubValue); 203 kSpecialCasesStubValues.put(java.lang.Object .class, kObjectStubValue); 204 kSpecialCasesStubValues.put(java.io.Serializable .class, kSerializableStubValue); 205 kSpecialCasesStubValues.put(java.io.Externalizable .class, kExternalizableStubValue); 206 kSpecialCasesStubValues.put(java.rmi.Remote .class, kRemoteStubValue); 207 } 208 209 210 public static final Hashtable kSpecialCasesVersions = new Hashtable (); 211 212 static { 213 kSpecialCasesVersions.put(java.lang.String .class, kWStringValueHash); 214 kSpecialCasesVersions.put(java.lang.Class .class, kClassDescValueHash); 215 kSpecialCasesVersions.put(java.lang.Object .class, kObjectValueHash); 216 kSpecialCasesVersions.put(java.io.Serializable .class, kSerializableValueHash); 217 kSpecialCasesVersions.put(java.io.Externalizable .class, kExternalizableValueHash); 218 kSpecialCasesVersions.put(java.rmi.Remote .class, kRemoteValueHash); 219 } 220 221 public static final Hashtable kSpecialCasesClasses = new Hashtable (); 222 223 static { 224 kSpecialCasesClasses.put(kWStringTypeStr, java.lang.String .class); 225 kSpecialCasesClasses.put(kClassDescTypeStr, java.lang.Class .class); 226 kSpecialCasesClasses.put(kRemoteTypeStr, java.rmi.Remote .class); 227 228 kSpecialCasesClasses.put("org.omg.CORBA.WStringValue", java.lang.String .class); 229 kSpecialCasesClasses.put("javax.rmi.CORBA.ClassDesc", java.lang.Class .class); 230 } 232 233 public static final Hashtable kSpecialCasesArrayPrefix = new Hashtable (); 234 235 static { 236 kSpecialCasesArrayPrefix.put(java.lang.String .class, kValuePrefix + kSequencePrefix + kCORBAPrefix); 237 kSpecialCasesArrayPrefix.put(java.lang.Class .class, kValuePrefix + kSequencePrefix + "javax/rmi/CORBA/"); 238 kSpecialCasesArrayPrefix.put(java.lang.Object .class, kValuePrefix + kSequencePrefix + "java/lang/"); 239 kSpecialCasesArrayPrefix.put(java.io.Serializable .class, kValuePrefix + kSequencePrefix + "java/io/"); 240 kSpecialCasesArrayPrefix.put(java.io.Externalizable .class, kValuePrefix + kSequencePrefix + "java/io/"); 241 kSpecialCasesArrayPrefix.put(java.rmi.Remote .class, kValuePrefix + kSequencePrefix + kCORBAPrefix); 242 } 243 244 public static final Hashtable kSpecialPrimitives = new Hashtable (); 245 246 static { 247 kSpecialPrimitives.put("int","long"); 248 kSpecialPrimitives.put("long","longlong"); 249 kSpecialPrimitives.put("byte","octet"); 250 } 251 252 255 private static final byte ASCII_HEX[] = { 256 (byte)'0', 257 (byte)'1', 258 (byte)'2', 259 (byte)'3', 260 (byte)'4', 261 (byte)'5', 262 (byte)'6', 263 (byte)'7', 264 (byte)'8', 265 (byte)'9', 266 (byte)'A', 267 (byte)'B', 268 (byte)'C', 269 (byte)'D', 270 (byte)'E', 271 (byte)'F', 272 }; 273 274 275 public static final RepositoryIdCache cache = new RepositoryIdCache(); 278 279 public static final String kjava_rmi_Remote = createForAnyType(java.rmi.Remote .class); 281 public static final String korg_omg_CORBA_Object = createForAnyType(org.omg.CORBA.Object .class); 282 283 public static final Class kNoParamTypes[] ={}; 285 public static final Object kNoArgs[] = {}; 286 287 288 291 RepositoryId(){} 292 293 RepositoryId(String aRepId){ 294 init(aRepId); 295 } 296 297 RepositoryId init(String aRepId) 298 { 299 this.repId = aRepId; 300 301 if (aRepId.length() == 0) { 303 clazz = java.rmi.Remote .class; 304 typeString = ""; 305 isRMIValueType = true; 306 suid = kInterfaceOnlyHashStr; 307 return this; 308 } else if (aRepId.equals(kWStringValueRepID)) { 309 clazz = java.lang.String .class; 310 typeString = kWStringTypeStr; 311 isIDLType = true; 312 completeClassName = "java.lang.String"; 315 versionString = kWStringValueVersion; 316 return this; 317 } else { 318 String repId = convertFromISOLatin1(aRepId); 319 320 int firstIndex = repId.indexOf(':') ; 321 if (firstIndex == -1) 322 throw new IllegalArgumentException ( "RepsitoryId must have the form <type>:<body>" ) ; 323 int secondIndex = repId.indexOf( ':', firstIndex + 1 ) ; 324 325 if (secondIndex == -1) 326 versionString = "" ; 327 else 328 versionString = repId.substring(secondIndex) ; 329 330 if (repId.startsWith(kIDLPrefix)) { 331 typeString = 332 repId.substring(kIDLPrefixLength, repId.indexOf(':', kIDLPrefixLength)); 333 isIDLType = true; 334 335 if (typeString.startsWith(kIDLNamePrefix)) 336 completeClassName = kIDLClassnamePrefix + 337 typeString.substring(kIDLNamePrefix.length()).replace('/','.'); 338 else 339 completeClassName = typeString.replace('/','.'); 340 341 } else if (repId.startsWith(kValuePrefix)) { 342 typeString = 343 repId.substring(kValuePrefixLength, repId.indexOf(':', kValuePrefixLength)); 344 isRMIValueType = true; 345 346 if (versionString.indexOf('.') == -1) { 347 actualSuid = versionString.substring(1); 348 suid = actualSuid; 350 if (actualSuid.indexOf(':') != -1){ 351 int pos = actualSuid.indexOf(':')+1; 353 suid = actualSuid.substring(pos); 356 actualSuid = actualSuid.substring(0, pos-1); 357 } 358 } else { 359 } 361 } else { 362 isSupportedFormat = false; 363 typeString = "" ; 364 } 365 366 if (typeString.startsWith(kSequencePrefix)) { 367 isSequence = true; 368 } 369 370 return this; 371 } 372 } 373 374 public final String getUnqualifiedName() { 375 if (unqualifiedName == null){ 376 String className = getClassName(); 377 int index = className.lastIndexOf('.'); 378 if (index == -1){ 379 unqualifiedName = className; 380 definedInId = "IDL::1.0"; 381 } 382 else { 383 unqualifiedName = className.substring(index); 384 definedInId = "IDL:" + className.substring(0, index).replace('.','/') + ":1.0"; 385 } 386 } 387 388 return unqualifiedName; 389 } 390 391 public final String getDefinedInId() { 392 if (definedInId == null){ 393 getUnqualifiedName(); 394 } 395 396 return definedInId; 397 } 398 399 public final String getTypeString() { 400 return typeString; 401 } 402 403 public final String getVersionString() { 404 return versionString; 405 } 406 407 public final String getSerialVersionUID() { 408 return suid; 409 } 410 411 public final String getActualSerialVersionUID() { 412 return actualSuid; 413 } 414 public final long getSerialVersionUIDAsLong() { 415 return suidLong; 416 } 417 418 public final long getActualSerialVersionUIDAsLong() { 419 return actualSuidLong; 420 } 421 422 public final boolean isRMIValueType() { 423 return isRMIValueType; 424 } 425 426 public final boolean isIDLType() { 427 return isIDLType; 428 } 429 430 public final String getRepositoryId() { 431 return repId; 432 } 433 434 public static byte[] getByteArray(String repStr) { 435 synchronized (repStrToByteArray){ 436 return (byte[]) repStrToByteArray.get(repStr); 437 } 438 } 439 440 public static void setByteArray(String repStr, byte[] repStrBytes) { 441 synchronized (repStrToByteArray){ 442 repStrToByteArray.put(repStr, repStrBytes); 443 } 444 } 445 446 public final boolean isSequence() { 447 return isSequence; 448 } 449 450 public final boolean isSupportedFormat() { 451 return isSupportedFormat; 452 } 453 454 455 public final String getClassName() { 458 459 if (isRMIValueType) 460 return typeString; 461 else if (isIDLType) 462 return completeClassName; 463 else return null; 464 465 } 466 467 public final Class getAnyClassFromType() throws ClassNotFoundException { 471 try { 472 return getClassFromType(); 473 } catch (ClassNotFoundException cnfe) { 474 Class clz = (Class )repStrToClass.get(repId); 475 if (clz != null) 476 return clz; 477 else 478 throw cnfe; 479 } 480 } 481 482 public final Class getClassFromType() 483 throws ClassNotFoundException { 484 if (clazz != null) 485 return clazz; 486 487 Class specialCase = (Class )kSpecialCasesClasses.get(getClassName()); 488 489 if (specialCase != null){ 490 clazz = specialCase; 491 return specialCase; 492 } 493 else 494 { 495 try{ 496 return Util.loadClass(getClassName(), null, null); 497 } 498 catch(ClassNotFoundException cnfe){ 499 if (defaultServerURL != null) { 500 try{ 501 return getClassFromType(defaultServerURL); 502 } 503 catch(MalformedURLException mue){ 504 throw cnfe; 505 } 506 } 507 else throw cnfe; 508 } 509 } 510 511 } 512 513 public final Class getClassFromType(Class expectedType, String codebase) 514 throws ClassNotFoundException { 515 if (clazz != null) 516 return clazz; 517 518 Class specialCase = (Class )kSpecialCasesClasses.get(getClassName()); 519 520 if (specialCase != null){ 521 clazz = specialCase; 522 return specialCase; 523 } else { 524 ClassLoader expectedTypeClassLoader = (expectedType == null ? null : expectedType.getClassLoader()); 525 return Utility.loadClassOfType(getClassName(), 526 codebase, 527 expectedTypeClassLoader, 528 expectedType, 529 expectedTypeClassLoader); 530 } 531 532 } 533 534 public final Class getClassFromType(String url) 535 throws ClassNotFoundException , MalformedURLException { 536 return Util.loadClass(getClassName(), url, null); 537 } 538 539 public final String toString() { 540 return repId; 541 } 542 543 548 public static boolean useFullValueDescription(Class clazz, String repositoryID) 549 throws IOException { 550 551 String clazzRepIDStr = createForAnyType(clazz); 552 553 if (clazzRepIDStr.equals(repositoryID)) 554 return false; 555 556 RepositoryId targetRepid; 557 RepositoryId clazzRepid; 558 559 synchronized(cache) { 560 564 targetRepid = cache.getId(repositoryID); 565 clazzRepid = cache.getId(clazzRepIDStr); 566 } 567 569 if ((targetRepid.isRMIValueType()) && (clazzRepid.isRMIValueType())){ 570 if (!targetRepid.getSerialVersionUID().equals(clazzRepid.getSerialVersionUID())) { 571 572 String mssg = "Mismatched serialization UIDs : Source (Rep. ID" + 573 clazzRepid + ") = " + 574 clazzRepid.getSerialVersionUID() + " whereas Target (Rep. ID " + repositoryID + 575 ") = " + targetRepid.getSerialVersionUID(); 576 throw new IOException (mssg); 578 } 579 else { 580 return true; 581 } 582 } 583 else { 584 585 throw new IOException ("The repository ID is not of an RMI value type (Expected ID = " + clazzRepIDStr + "; Received ID = " + repositoryID +")"); 586 } 587 } 588 589 private static String createHashString(java.io.Serializable ser) { 590 591 return createHashString(ser.getClass()); 592 } 593 594 private static String createHashString(java.lang.Class clazz) { 595 596 if (clazz.isInterface() || !java.io.Serializable .class.isAssignableFrom(clazz)) 597 return kInterfaceHashCode; 598 599 601 long actualLong = ObjectStreamClass.getActualSerialVersionUID(clazz); 602 String hash = null; 603 if (actualLong == 0) 604 hash = kInterfaceOnlyHashStr; 605 else if (actualLong == 1) 606 hash = kExternalizableHashStr; 607 else 608 hash = Long.toHexString(actualLong).toUpperCase(); 609 while(hash.length() < 16){ 610 hash = "0" + hash; 611 } 612 613 long declaredLong = ObjectStreamClass.getSerialVersionUID(clazz); 614 String declared = null; 615 if (declaredLong == 0) 616 declared = kInterfaceOnlyHashStr; 617 else if (declaredLong == 1) 618 declared = kExternalizableHashStr; 619 else 620 declared = Long.toHexString(declaredLong).toUpperCase(); 621 while (declared.length() < 16){ 622 declared = "0" + declared; 623 } 624 hash = hash + ":" + declared; 625 626 return ":" + hash; 627 } 628 629 636 public static String createSequenceRepID(java.lang.Object ser){ 637 return createSequenceRepID(ser.getClass()); 638 } 639 640 646 public static String createSequenceRepID(java.lang.Class clazz){ 647 synchronized (classSeqToRepStr){ 648 649 String repid = (String )classSeqToRepStr.get(clazz); 650 if (repid != null) 651 return repid; 652 653 Class originalClazz = clazz; 654 655 Class type = null; 656 int numOfDims = 0; 657 658 while ((type = clazz.getComponentType()) != null) { 659 numOfDims++; 660 clazz = type; 661 } 662 663 if (clazz.isPrimitive()) 664 repid = kValuePrefix + originalClazz.getName() + kPrimitiveSequenceValueHash; 665 else { 666 StringBuffer buf = new StringBuffer (); 667 buf.append(kValuePrefix); 668 while(numOfDims-- > 0) { 669 buf.append("["); 670 } 671 buf.append("L"); 672 buf.append(convertToISOLatin1(clazz.getName())); 673 buf.append(";"); 674 buf.append(createHashString(clazz)); 675 repid = buf.toString(); 676 } 677 classSeqToRepStr.put(originalClazz,repid); 678 return repid; 679 } 680 681 } 682 683 684 public static String createForSpecialCase(java.lang.Class clazz){ 685 if (clazz.isArray()){ 686 return createSequenceRepID(clazz); 687 } 688 else { 689 return (String )kSpecialCasesRepIDs.get(clazz); 690 } 691 } 692 693 public static String createForSpecialCase(java.io.Serializable ser){ 694 Class clazz = ser.getClass(); 695 if (clazz.isArray()){ 696 return createSequenceRepID(ser); 697 } 698 else 699 return createForSpecialCase(clazz); 700 } 701 702 708 public static String createForJavaType(java.io.Serializable ser) 709 throws com.sun.corba.se.impl.io.TypeMismatchException 710 { 711 synchronized (classToRepStr) { 712 String repid = createForSpecialCase(ser); 713 if (repid != null) 714 return repid; 715 Class clazz = ser.getClass(); 716 repid = (String )classToRepStr.get(clazz); 717 718 if (repid != null) 719 return repid; 720 721 repid = kValuePrefix + convertToISOLatin1(clazz.getName()) + 722 createHashString(clazz); 723 724 classToRepStr.put(clazz, repid); 725 repStrToClass.put(repid, clazz); 726 return repid; 727 } 728 } 729 730 736 public static String createForJavaType(Class clz) 737 throws com.sun.corba.se.impl.io.TypeMismatchException 738 { 739 synchronized (classToRepStr){ 740 String repid = createForSpecialCase(clz); 741 if (repid != null) 742 return repid; 743 744 repid = (String )classToRepStr.get(clz); 745 if (repid != null) 746 return repid; 747 748 repid = kValuePrefix + convertToISOLatin1(clz.getName()) + 749 createHashString(clz); 750 751 classToRepStr.put(clz, repid); 752 repStrToClass.put(repid, clz); 753 return repid; 754 } 755 } 756 757 765 public static String createForIDLType(Class ser, int major, int minor) 766 throws com.sun.corba.se.impl.io.TypeMismatchException 767 { 768 synchronized (classIDLToRepStr){ 769 String repid = (String )classIDLToRepStr.get(ser); 770 if (repid != null) 771 return repid; 772 773 repid = kIDLPrefix + convertToISOLatin1(ser.getName()).replace('.','/') + 774 ":" + major + "." + minor; 775 classIDLToRepStr.put(ser, repid); 776 return repid; 777 } 778 } 779 780 private static String getIdFromHelper(Class clazz){ 781 try { 782 Class helperClazz = Utility.loadClassForClass(clazz.getName()+"Helper", null, 783 clazz.getClassLoader(), clazz, clazz.getClassLoader()); 784 Method idMethod = helperClazz.getDeclaredMethod("id", kNoParamTypes); 785 return (String )idMethod.invoke(null, kNoArgs); 786 } 787 catch(java.lang.ClassNotFoundException cnfe) 788 { 789 throw new org.omg.CORBA.MARSHAL (cnfe.toString()); 790 } 791 catch(java.lang.NoSuchMethodException nsme) 792 { 793 throw new org.omg.CORBA.MARSHAL (nsme.toString()); 794 } 795 catch(java.lang.reflect.InvocationTargetException ite) 796 { 797 throw new org.omg.CORBA.MARSHAL (ite.toString()); 798 } 799 catch(java.lang.IllegalAccessException iae) 800 { 801 throw new org.omg.CORBA.MARSHAL (iae.toString()); 802 } 803 } 804 805 811 public static String createForAnyType(Class type) { 812 try{ 813 if (type.isArray()) 814 return createSequenceRepID(type); 815 else if (IDLEntity .class.isAssignableFrom(type)) 816 { 817 try{ 818 return getIdFromHelper(type); 819 } 820 catch(Throwable t) { 821 return createForIDLType(type, 1, 0); 822 } 823 } 824 else return createForJavaType(type); 825 } 826 catch(com.sun.corba.se.impl.io.TypeMismatchException e){ 827 return null; 828 } 829 830 } 831 832 public static boolean isAbstractBase(Class clazz) { 833 return (clazz.isInterface() && 834 IDLEntity .class.isAssignableFrom(clazz) && 835 (!ValueBase .class.isAssignableFrom(clazz)) && 836 (!org.omg.CORBA.Object .class.isAssignableFrom(clazz))); 837 838 } 839 840 public static boolean isAnyRequired(Class clazz) { 841 return ((clazz == java.lang.Object .class) || 842 (clazz == java.io.Serializable .class) || 843 (clazz == java.io.Externalizable .class)); 844 } 845 846 public static long fromHex(String hexNumber) { 847 if (hexNumber.startsWith("0x")) 848 return Long.valueOf(hexNumber.substring(2), 16).longValue(); 849 else return Long.valueOf(hexNumber, 16).longValue(); 850 } 851 852 857 public static String convertToISOLatin1 (String name) { 858 859 int length = name.length(); 860 if (length == 0) { 861 return name; 862 } 863 StringBuffer buffer = null; 864 865 for (int i = 0; i < length; i++) { 866 867 char c = name.charAt(i); 868 869 if (c > 255 || IDL_IDENTIFIER_CHARS[c] == 0) { 870 871 873 if (buffer == null) { 874 875 877 buffer = new StringBuffer (name.substring(0,i)); 878 } 879 880 buffer.append( 882 "\\U" + 883 (char)ASCII_HEX[(c & 0xF000) >>> 12] + 884 (char)ASCII_HEX[(c & 0x0F00) >>> 8] + 885 (char)ASCII_HEX[(c & 0x00F0) >>> 4] + 886 (char)ASCII_HEX[(c & 0x000F)]); 887 888 } else { 889 if (buffer != null) { 890 buffer.append(c); 891 } 892 } 893 } 894 895 if (buffer != null) { 896 name = buffer.toString(); 897 } 898 899 return name; 900 } 901 902 907 private static String convertFromISOLatin1 (String name) { 908 909 int index = -1; 910 StringBuffer buf = new StringBuffer (name); 911 912 while ((index = buf.toString().indexOf("\\U")) != -1){ 913 String str = "0000" + buf.toString().substring(index+2, index+6); 914 915 byte[] buffer = new byte[(str.length() - 4) / 2]; 917 for (int i=4, j=0; i < str.length(); i +=2, j++) { 918 buffer[j] = (byte)((Utility.hexOf(str.charAt(i)) << 4) & 0xF0); 919 buffer[j] |= (byte)((Utility.hexOf(str.charAt(i+1)) << 0) & 0x0F); 920 } 921 buf = new StringBuffer (delete(buf.toString(), index, index+6)); 922 buf.insert(index, (char)buffer[1]); 923 } 924 925 return buf.toString(); 926 927 928 } 929 930 private static String delete(String str, int from, int to) 931 { 932 return str.substring(0, from) + str.substring(to, str.length()); 933 } 934 935 private static String replace(String target, String arg, String source) 936 { 937 int i = 0; 938 i = target.indexOf(arg); 939 940 while(i != -1) 941 { 942 String left = target.substring(0, i); 943 String right = target.substring(i+arg.length()); 944 target = new String (left+source+right); 945 i = target.indexOf(arg); 946 } 947 return target; 948 } 949 950 public static int computeValueTag(boolean codeBasePresent, int typeInfo, boolean chunkedEncoding){ 951 int value_tag = kInitialValueTag; 952 953 if (codeBasePresent) 954 value_tag = value_tag | 0x00000001; 955 956 value_tag = value_tag | typeInfo; 957 958 if (chunkedEncoding) 959 value_tag = value_tag | kChunkedMask; 960 961 return value_tag; 962 } 963 964 public static boolean isCodeBasePresent(int value_tag){ 965 return ((value_tag & 0x00000001) == 1); 966 } 967 968 public static int getTypeInfo(int value_tag){ 969 return (value_tag & 0x00000006); 970 } 971 972 public static boolean isChunkedEncoding(int value_tag){ 973 return ((value_tag & kChunkedMask) != 0); 974 } 975 976 public static String getServerURL(){ 977 return defaultServerURL; 978 } 979 } 980 981 | Popular Tags |