1 7 8 16 17 package com.sun.corba.se.impl.encoding; 18 19 import java.io.IOException ; 20 import java.io.Serializable ; 21 import java.io.ByteArrayInputStream ; 22 import java.io.ObjectInputStream ; 23 import java.io.IOException ; 24 import java.io.StreamCorruptedException ; 25 import java.io.OptionalDataException ; 26 import java.io.IOException ; 27 28 import java.util.Stack ; 29 30 import java.net.URL ; 31 import java.net.MalformedURLException ; 32 33 import java.nio.ByteBuffer ; 34 35 import java.lang.reflect.InvocationTargetException ; 36 import java.lang.reflect.Method ; 37 38 import java.math.BigDecimal ; 39 40 import java.rmi.Remote ; 41 import java.rmi.StubNotFoundException ; 42 43 import java.security.AccessController ; 44 import java.security.PrivilegedExceptionAction ; 45 import java.security.PrivilegedActionException ; 46 47 import org.omg.CORBA.SystemException ; 48 import org.omg.CORBA.Object ; 49 import org.omg.CORBA.Principal ; 50 import org.omg.CORBA.TypeCode ; 51 import org.omg.CORBA.Any ; 52 import org.omg.CORBA.portable.Delegate ; 53 import org.omg.CORBA.portable.ValueBase ; 54 import org.omg.CORBA.portable.IndirectionException ; 55 import org.omg.CORBA.CompletionStatus ; 56 import org.omg.CORBA.TCKind ; 57 import org.omg.CORBA.TypeCodePackage.BadKind ; 58 import org.omg.CORBA.CustomMarshal ; 59 import org.omg.CORBA.TypeCode ; 60 import org.omg.CORBA.Principal ; 61 import org.omg.CORBA.Any ; 62 import org.omg.CORBA.portable.BoxedValueHelper ; 63 import org.omg.CORBA.portable.ValueFactory ; 64 import org.omg.CORBA.portable.CustomValue ; 65 import org.omg.CORBA.portable.StreamableValue ; 66 import org.omg.CORBA.MARSHAL ; 67 import org.omg.CORBA.portable.IDLEntity ; 68 69 import javax.rmi.PortableRemoteObject ; 70 import javax.rmi.CORBA.Tie ; 71 import javax.rmi.CORBA.Util ; 72 import javax.rmi.CORBA.ValueHandler ; 73 74 import com.sun.corba.se.pept.protocol.MessageMediator; 75 import com.sun.corba.se.pept.transport.ByteBufferPool; 76 77 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry; 78 import com.sun.corba.se.spi.protocol.CorbaClientDelegate; 79 80 import com.sun.corba.se.spi.ior.IOR; 81 import com.sun.corba.se.spi.ior.IORFactories; 82 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 83 84 import com.sun.corba.se.spi.orb.ORB; 85 import com.sun.corba.se.spi.orb.ORBVersionFactory; 86 import com.sun.corba.se.spi.orb.ORBVersion; 87 88 import com.sun.corba.se.spi.protocol.CorbaMessageMediator; 89 90 import com.sun.corba.se.spi.logging.CORBALogDomains; 91 import com.sun.corba.se.spi.presentation.rmi.PresentationManager; 92 import com.sun.corba.se.spi.presentation.rmi.StubAdapter; 93 import com.sun.corba.se.spi.presentation.rmi.PresentationDefaults; 94 95 import com.sun.corba.se.impl.logging.ORBUtilSystemException; 96 import com.sun.corba.se.impl.logging.OMGSystemException; 97 98 import com.sun.corba.se.impl.corba.PrincipalImpl; 99 import com.sun.corba.se.impl.corba.TypeCodeImpl; 100 import com.sun.corba.se.impl.corba.CORBAObjectImpl; 101 102 import com.sun.corba.se.impl.encoding.CDROutputObject; 103 import com.sun.corba.se.impl.encoding.CodeSetConversion; 104 105 import com.sun.corba.se.impl.util.Utility; 106 import com.sun.corba.se.impl.util.RepositoryId; 107 108 import com.sun.corba.se.impl.orbutil.RepositoryIdStrings; 109 import com.sun.corba.se.impl.orbutil.RepositoryIdInterface; 110 import com.sun.corba.se.impl.orbutil.RepositoryIdUtility; 111 import com.sun.corba.se.impl.orbutil.RepositoryIdFactory; 112 113 import com.sun.corba.se.impl.orbutil.ORBUtility; 114 import com.sun.corba.se.impl.orbutil.CacheTable; 115 116 117 import com.sun.org.omg.CORBA.portable.ValueHelper; 118 119 import com.sun.org.omg.SendingContext.CodeBase; 120 121 public class CDRInputStream_1_0 extends CDRInputStreamBase 122 implements RestorableInputStream 123 { 124 private static final String kReadMethod = "read"; 125 private static final int maxBlockLength = 0x7fffff00; 126 127 protected BufferManagerRead bufferManagerRead; 128 protected ByteBufferWithInfo bbwi; 129 130 private boolean debug = false; 133 134 protected boolean littleEndian; 135 protected ORB orb; 136 protected ORBUtilSystemException wrapper ; 137 protected OMGSystemException omgWrapper ; 138 protected ValueHandler valueHandler = null; 139 140 private CacheTable valueCache = null; 142 143 private CacheTable repositoryIdCache = null; 145 146 private CacheTable codebaseCache = null; 148 149 152 protected int blockLength = maxBlockLength; 154 155 protected int end_flag = 0; 157 158 private int chunkedValueNestingLevel = 0; 164 165 168 171 174 protected int valueIndirection = 0; 177 178 protected int stringIndirection = 0; 181 182 protected boolean isChunked = false; 184 185 private RepositoryIdUtility repIdUtil; 187 private RepositoryIdStrings repIdStrs; 188 189 private CodeSetConversion.BTCConverter charConverter; 191 private CodeSetConversion.BTCConverter wcharConverter; 192 193 private boolean specialNoOptionalDataState = false; 201 202 public CDRInputStreamBase dup() 204 { 205 CDRInputStreamBase result = null ; 206 207 try { 208 result = (CDRInputStreamBase)this.getClass().newInstance(); 209 } catch (Exception e) { 210 throw wrapper.couldNotDuplicateCdrInputStream( e ) ; 211 } 212 result.init(this.orb, 213 this.bbwi.byteBuffer, 214 this.bbwi.buflen, 215 this.littleEndian, 216 this.bufferManagerRead); 217 218 ((CDRInputStream_1_0)result).bbwi.position(this.bbwi.position()); 219 ((CDRInputStream_1_0)result).bbwi.byteBuffer.limit(this.bbwi.buflen); 221 222 return result; 223 } 224 225 228 public void init(org.omg.CORBA.ORB orb, 229 ByteBuffer byteBuffer, 230 int size, 231 boolean littleEndian, 232 BufferManagerRead bufferManager) 233 { 234 this.orb = (ORB)orb; 235 this.wrapper = ORBUtilSystemException.get( (ORB)orb, 236 CORBALogDomains.RPC_ENCODING ) ; 237 this.omgWrapper = OMGSystemException.get( (ORB)orb, 238 CORBALogDomains.RPC_ENCODING ) ; 239 this.littleEndian = littleEndian; 240 this.bufferManagerRead = bufferManager; 241 this.bbwi = new ByteBufferWithInfo(orb,byteBuffer,0); 242 this.bbwi.buflen = size; 243 this.bbwi.byteBuffer.limit(bbwi.buflen); 244 this.markAndResetHandler = bufferManagerRead.getMarkAndResetHandler(); 245 246 debug = ((ORB)orb).transportDebugFlag; 247 } 248 249 void performORBVersionSpecificInit() { 251 createRepositoryIdHandlers(); 252 } 253 254 private final void createRepositoryIdHandlers() 255 { 256 repIdUtil = RepositoryIdFactory.getRepIdUtility(orb); 257 repIdStrs = RepositoryIdFactory.getRepIdStringsFactory(orb); 258 } 259 260 public GIOPVersion getGIOPVersion() { 261 return GIOPVersion.V1_0; 262 } 263 264 void setHeaderPadding(boolean headerPadding) { 267 throw wrapper.giopVersionError(); 268 } 269 270 protected final int computeAlignment(int index, int align) { 271 if (align > 1) { 272 int incr = index & (align - 1); 273 if (incr != 0) 274 return align - incr; 275 } 276 277 return 0; 278 } 279 280 public int getSize() 281 { 282 return bbwi.position(); 283 } 284 285 protected void checkBlockLength(int align, int dataSize) { 286 if (!isChunked) 291 return; 292 293 if (specialNoOptionalDataState) { 301 throw omgWrapper.rmiiiopOptionalDataIncompatible1() ; 302 } 303 304 boolean checkForEndTag = false; 305 306 if (blockLength == get_offset()) { 314 315 blockLength = maxBlockLength; 316 start_block(); 317 318 if (blockLength == maxBlockLength) 325 checkForEndTag = true; 326 327 } else 328 if (blockLength < get_offset()) { 329 throw wrapper.chunkOverflow() ; 332 } 333 334 int requiredNumBytes = 341 computeAlignment(bbwi.position(), align) + dataSize; 342 343 if (blockLength != maxBlockLength && 344 blockLength < get_offset() + requiredNumBytes) { 345 throw omgWrapper.rmiiiopOptionalDataIncompatible2() ; 346 } 347 348 if (checkForEndTag) { 354 int nextLong = read_long(); 355 bbwi.position(bbwi.position() - 4); 356 357 if (nextLong < 0) 361 throw omgWrapper.rmiiiopOptionalDataIncompatible3() ; 362 } 363 } 364 365 protected void alignAndCheck(int align, int n) { 366 367 checkBlockLength(align, n); 368 369 int alignResult = computeAlignment(bbwi.position(), align); 372 bbwi.position(bbwi.position() + alignResult); 373 374 if (bbwi.position() + n > bbwi.buflen) 375 grow(align, n); 376 } 377 378 protected void grow(int align, int n) { 382 383 bbwi.needed = n; 384 385 bbwi = bufferManagerRead.underflow(bbwi); 386 387 } 388 389 393 public final void consumeEndian() { 394 littleEndian = read_boolean(); 395 } 396 397 public final double read_longdouble() { 399 throw wrapper.longDoubleNotImplemented( CompletionStatus.COMPLETED_MAYBE); 400 } 401 402 public final boolean read_boolean() { 403 return (read_octet() != 0); 404 } 405 406 public final char read_char() { 407 alignAndCheck(1, 1); 408 409 return getConvertedChars(1, getCharConverter())[0]; 410 } 411 412 public char read_wchar() { 413 414 if (ORBUtility.isForeignORB((ORB)orb)) { 417 throw wrapper.wcharDataInGiop10( CompletionStatus.COMPLETED_MAYBE); 418 } 419 420 int b1, b2; 423 424 alignAndCheck(2, 2); 425 426 if (littleEndian) { 427 b2 = bbwi.byteBuffer.get(bbwi.position()) & 0x00FF; 428 bbwi.position(bbwi.position() + 1); 429 b1 = bbwi.byteBuffer.get(bbwi.position()) & 0x00FF; 430 bbwi.position(bbwi.position() + 1); 431 } else { 432 b1 = bbwi.byteBuffer.get(bbwi.position()) & 0x00FF; 433 bbwi.position(bbwi.position() + 1); 434 b2 = bbwi.byteBuffer.get(bbwi.position()) & 0x00FF; 435 bbwi.position(bbwi.position() + 1); 436 } 437 438 return (char)((b1 << 8) + (b2 << 0)); 439 } 440 441 public final byte read_octet() { 442 443 alignAndCheck(1, 1); 444 445 byte b = bbwi.byteBuffer.get(bbwi.position()); 446 bbwi.position(bbwi.position() + 1); 447 448 return b; 449 } 450 451 public final short read_short() { 452 int b1, b2; 453 454 alignAndCheck(2, 2); 455 456 if (littleEndian) { 457 b2 = (bbwi.byteBuffer.get(bbwi.position()) << 0) & 0x000000FF; 458 bbwi.position(bbwi.position() + 1); 459 b1 = (bbwi.byteBuffer.get(bbwi.position()) << 8) & 0x0000FF00; 460 bbwi.position(bbwi.position() + 1); 461 } else { 462 b1 = (bbwi.byteBuffer.get(bbwi.position()) << 8) & 0x0000FF00; 463 bbwi.position(bbwi.position() + 1); 464 b2 = (bbwi.byteBuffer.get(bbwi.position()) << 0) & 0x000000FF; 465 bbwi.position(bbwi.position() + 1); 466 } 467 468 return (short)(b1 | b2); 469 } 470 471 public final short read_ushort() { 472 return read_short(); 473 } 474 475 public final int read_long() { 476 int b1, b2, b3, b4; 477 478 alignAndCheck(4, 4); 479 480 int bufPos = bbwi.position(); 481 if (littleEndian) { 482 b4 = bbwi.byteBuffer.get(bufPos++) & 0xFF; 483 b3 = bbwi.byteBuffer.get(bufPos++) & 0xFF; 484 b2 = bbwi.byteBuffer.get(bufPos++) & 0xFF; 485 b1 = bbwi.byteBuffer.get(bufPos++) & 0xFF; 486 } else { 487 b1 = bbwi.byteBuffer.get(bufPos++) & 0xFF; 488 b2 = bbwi.byteBuffer.get(bufPos++) & 0xFF; 489 b3 = bbwi.byteBuffer.get(bufPos++) & 0xFF; 490 b4 = bbwi.byteBuffer.get(bufPos++) & 0xFF; 491 } 492 bbwi.position(bufPos); 493 494 return (b1 << 24) | (b2 << 16) | (b3 << 8) | b4; 495 } 496 497 public final int read_ulong() { 498 return read_long(); 499 } 500 501 public final long read_longlong() { 502 long i1, i2; 503 504 alignAndCheck(8, 8); 505 506 if (littleEndian) { 507 i2 = read_long() & 0xFFFFFFFFL; 508 i1 = (long)read_long() << 32; 509 } else { 510 i1 = (long)read_long() << 32; 511 i2 = read_long() & 0xFFFFFFFFL; 512 } 513 514 return (i1 | i2); 515 } 516 517 public final long read_ulonglong() { 518 return read_longlong(); 519 } 520 521 public final float read_float() { 522 return Float.intBitsToFloat(read_long()); 523 } 524 525 public final double read_double() { 526 return Double.longBitsToDouble(read_longlong()); 527 } 528 529 protected final void checkForNegativeLength(int length) { 530 if (length < 0) 531 throw wrapper.negativeStringLength( CompletionStatus.COMPLETED_MAYBE, 532 new Integer (length) ) ; 533 } 534 535 protected final String readStringOrIndirection(boolean allowIndirection) { 536 537 int len = read_long(); 538 539 if (allowIndirection) { 543 if (len == 0xffffffff) 544 return null; 545 else 546 stringIndirection = get_offset() - 4; 547 } 548 549 checkForNegativeLength(len); 550 551 if (orb != null && ORBUtility.isLegacyORB((ORB)orb)) 552 return legacyReadString(len); 553 else 554 return internalReadString(len); 555 } 556 557 private final String internalReadString(int len) { 558 if (len == 0) 565 return new String (""); 566 567 char[] result = getConvertedChars(len - 1, getCharConverter()); 568 569 read_octet(); 571 572 return new String (result, 0, getCharConverter().getNumChars()); 573 } 574 575 private final String legacyReadString(int len) { 576 577 if (len == 0) 586 return new String (""); 587 588 len--; 589 char[] c = new char[len]; 590 591 int n = 0; 592 while (n < len) { 593 int avail; 594 int bytes; 595 int wanted; 596 597 avail = bbwi.buflen - bbwi.position(); 598 if (avail <= 0) { 599 grow(1, 1); 600 avail = bbwi.buflen - bbwi.position(); 601 } 602 wanted = len - n; 603 bytes = (wanted < avail) ? wanted : avail; 604 for (int i=0; i<bytes; i++) { 607 c[n+i] = (char) (bbwi.byteBuffer.get(bbwi.position()+i) & 0xFF); 608 } 609 bbwi.position(bbwi.position() + bytes); 610 n += bytes; 611 } 612 613 if (bbwi.position() + 1 > bbwi.buflen) 617 alignAndCheck(1, 1); 618 bbwi.position(bbwi.position() + 1); 619 620 return new String (c); 621 } 622 623 public final String read_string() { 624 return readStringOrIndirection(false); 625 } 626 627 public String read_wstring() { 628 if (ORBUtility.isForeignORB((ORB)orb)) { 631 throw wrapper.wcharDataInGiop10( CompletionStatus.COMPLETED_MAYBE); 632 } 633 634 int len = read_long(); 635 636 if (len == 0) 645 return new String (""); 646 647 checkForNegativeLength(len); 648 649 len--; 650 char[] c = new char[len]; 651 652 for (int i = 0; i < len; i++) 653 c[i] = read_wchar(); 654 655 read_wchar(); 657 659 return new String (c); 660 } 661 662 public final void read_octet_array(byte[] b, int offset, int length) { 663 if ( b == null ) 664 throw wrapper.nullParam() ; 665 666 if (length == 0) 672 return; 673 674 alignAndCheck(1, 1); 675 676 int n = offset; 677 while (n < length+offset) { 678 int avail; 679 int bytes; 680 int wanted; 681 682 avail = bbwi.buflen - bbwi.position(); 683 if (avail <= 0) { 684 grow(1, 1); 685 avail = bbwi.buflen - bbwi.position(); 686 } 687 wanted = (length + offset) - n; 688 bytes = (wanted < avail) ? wanted : avail; 689 for (int i = 0; i < bytes; i++) { 692 b[n+i] = bbwi.byteBuffer.get(bbwi.position() + i); 693 } 694 695 bbwi.position(bbwi.position() + bytes); 696 697 n += bytes; 698 } 699 } 700 701 public Principal read_Principal() { 702 int len = read_long(); 703 byte[] pvalue = new byte[len]; 704 read_octet_array(pvalue,0,len); 705 706 Principal p = new PrincipalImpl(); 707 p.name(pvalue); 708 return p; 709 } 710 711 public TypeCode read_TypeCode() { 712 TypeCodeImpl tc = new TypeCodeImpl(orb); 713 tc.read_value(parent); 714 return tc; 715 } 716 717 public Any read_any() { 718 Any any = orb.create_any(); 719 TypeCodeImpl tc = new TypeCodeImpl(orb); 720 721 723 try { 730 tc.read_value(parent); 731 } catch (MARSHAL ex) { 732 if (tc.kind().value() != TCKind._tk_value) 733 throw ex; 734 dprintThrowable(ex); 737 } 738 any.read_value(parent, tc); 740 741 return any; 742 } 743 744 public org.omg.CORBA.Object read_Object() { 745 return read_Object(null); 746 } 747 748 750 public org.omg.CORBA.Object read_Object(Class clz) 764 { 765 IOR ior = IORFactories.makeIOR(parent) ; 767 if (ior.isNil()) 768 return null ; 769 770 PresentationManager.StubFactoryFactory sff = ORB.getStubFactoryFactory() ; 771 String codeBase = ior.getProfile().getCodebase() ; 772 PresentationManager.StubFactory stubFactory = null ; 773 774 if (clz == null) { 775 RepositoryId rid = RepositoryId.cache.getId( ior.getTypeId() ) ; 776 String className = rid.getClassName() ; 777 boolean isIDLInterface = rid.isIDLType() ; 778 779 if (className == null || className.equals( "" )) 780 stubFactory = null ; 781 else 782 try { 783 stubFactory = sff.createStubFactory( className, 784 isIDLInterface, codeBase, (Class )null, 785 (ClassLoader )null ); 786 } catch (Exception exc) { 787 stubFactory = null ; 792 } 793 } else if (StubAdapter.isStubClass( clz )) { 794 stubFactory = PresentationDefaults.makeStaticStubFactory( 795 clz ) ; 796 } else { 797 boolean isIDL = IDLEntity .class.isAssignableFrom( clz ) ; 799 800 stubFactory = sff.createStubFactory( clz.getName(), 801 isIDL, codeBase, clz, clz.getClassLoader() ) ; 802 } 803 804 return internalIORToObject( ior, stubFactory, orb ) ; 805 } 806 807 812 public static org.omg.CORBA.Object internalIORToObject( 813 IOR ior, PresentationManager.StubFactory stubFactory, ORB orb) 814 { 815 ORBUtilSystemException wrapper = ORBUtilSystemException.get( 816 (ORB)orb, CORBALogDomains.RPC_ENCODING ) ; 817 818 java.lang.Object servant = ior.getProfile().getServant() ; 819 if (servant != null ) { 820 if (servant instanceof Tie ) { 821 String codebase = ior.getProfile().getCodebase(); 822 org.omg.CORBA.Object objref = (org.omg.CORBA.Object ) 823 Utility.loadStub( (Tie )servant, stubFactory, codebase, 824 false); 825 826 if (objref != null) { 829 return objref; 830 } else { 831 throw wrapper.readObjectException() ; 832 } 833 } else if (servant instanceof org.omg.CORBA.Object ) { 834 if (!(servant instanceof 835 org.omg.CORBA.portable.InvokeHandler )) { 836 return (org.omg.CORBA.Object ) servant; 837 } 838 } else 839 throw wrapper.badServantReadObject() ; 840 } 841 842 CorbaClientDelegate del = ORBUtility.makeClientDelegate( ior ) ; 843 org.omg.CORBA.Object objref = null ; 844 try { 845 objref = stubFactory.makeStub() ; 846 } catch (Throwable e) { 847 wrapper.stubCreateError( e ) ; 848 849 if (e instanceof ThreadDeath ) { 850 throw (ThreadDeath ) e; 851 } 852 853 objref = new CORBAObjectImpl() ; 855 } 856 857 StubAdapter.setDelegate( objref, del ) ; 858 return objref; 859 } 860 861 public java.lang.Object read_abstract_interface() 862 { 863 return read_abstract_interface(null); 864 } 865 866 public java.lang.Object read_abstract_interface(java.lang.Class clz) 867 { 868 boolean object = read_boolean(); 869 870 if (object) { 871 return read_Object(clz); 872 } else { 873 return read_value(); 874 } 875 } 876 877 public Serializable read_value() 878 { 879 return read_value((Class )null); 880 } 881 882 private Serializable handleIndirection() { 883 int indirection = read_long() + get_offset() - 4; 884 if (valueCache != null && valueCache.containsVal(indirection)) { 885 886 java.io.Serializable cachedValue 887 = (java.io.Serializable )valueCache.getKey(indirection); 888 return cachedValue; 889 } else { 890 throw new IndirectionException (indirection); 895 } 896 } 897 898 private String readRepositoryIds(int valueTag, 899 Class expectedType, 900 String expectedTypeRepId) { 901 return readRepositoryIds(valueTag, expectedType, 902 expectedTypeRepId, null); 903 } 904 905 913 private String readRepositoryIds(int valueTag, 914 Class expectedType, 915 String expectedTypeRepId, 916 BoxedValueHelper factory) { 917 switch(repIdUtil.getTypeInfo(valueTag)) { 918 case RepositoryIdUtility.NO_TYPE_INFO : 919 if (expectedType == null) { 923 if (expectedTypeRepId != null) { 924 return expectedTypeRepId; 925 } else if (factory != null) { 926 return factory.get_id(); 927 } else { 928 throw wrapper.expectedTypeNullAndNoRepId( 929 CompletionStatus.COMPLETED_MAYBE); 930 } 931 } 932 return repIdStrs.createForAnyType(expectedType); 933 case RepositoryIdUtility.SINGLE_REP_TYPE_INFO : 934 return read_repositoryId(); 935 case RepositoryIdUtility.PARTIAL_LIST_TYPE_INFO : 936 return read_repositoryIds(); 937 default: 938 throw wrapper.badValueTag( CompletionStatus.COMPLETED_MAYBE, 939 Integer.toHexString(valueTag) ) ; 940 } 941 } 942 943 public Serializable read_value(Class expectedType) { 944 945 int vType = readValueTag(); 947 948 if (vType == 0) 950 return null; 951 952 if (vType == 0xffffffff) 955 return handleIndirection(); 956 957 int indirection = get_offset() - 4; 961 962 boolean saveIsChunked = isChunked; 965 966 isChunked = repIdUtil.isChunkedEncoding(vType); 967 968 java.lang.Object value = null; 969 970 String codebase_URL = null; 971 if (repIdUtil.isCodeBasePresent(vType)) { 972 codebase_URL = read_codebase_URL(); 973 } 974 975 String repositoryIDString 977 = readRepositoryIds(vType, expectedType, null); 978 979 start_block(); 982 983 end_flag--; 986 if (isChunked) 987 chunkedValueNestingLevel--; 988 989 if (repositoryIDString.equals(repIdStrs.getWStringValueRepId())) { 990 value = read_wstring(); 991 } else 992 if (repositoryIDString.equals(repIdStrs.getClassDescValueRepId())) { 993 value = readClass(); 996 } else { 997 998 Class valueClass = expectedType; 999 1000 if (expectedType == null || 1003 !repositoryIDString.equals(repIdStrs.createForAnyType(expectedType))) { 1004 1005 valueClass = getClassFromString(repositoryIDString, 1006 codebase_URL, 1007 expectedType); 1008 } 1009 1010 if (valueClass == null) { 1011 throw wrapper.couldNotFindClass( 1014 CompletionStatus.COMPLETED_MAYBE, 1015 new ClassNotFoundException ()); 1016 } 1017 1018 if (valueClass != null && 1019 org.omg.CORBA.portable.IDLEntity .class.isAssignableFrom(valueClass)) { 1020 1021 value = readIDLValue(indirection, 1022 repositoryIDString, 1023 valueClass, 1024 codebase_URL); 1025 1026 } else { 1027 1028 1030 try { 1031 if (valueHandler == null) 1032 valueHandler = ORBUtility.createValueHandler(orb); 1033 1034 value = valueHandler.readValue(parent, 1035 indirection, 1036 valueClass, 1037 repositoryIDString, 1038 getCodeBase()); 1039 1040 } catch(SystemException sysEx) { 1041 throw sysEx; 1044 } catch(Exception ex) { 1045 throw wrapper.valuehandlerReadException( 1046 CompletionStatus.COMPLETED_MAYBE, ex ) ; 1047 } catch(Error e) { 1048 throw wrapper.valuehandlerReadError( 1049 CompletionStatus.COMPLETED_MAYBE, e ) ; 1050 } 1051 } 1052 } 1053 1054 handleEndOfValue(); 1059 1060 readEndTag(); 1064 1065 if (valueCache == null) 1067 valueCache = new CacheTable(orb,false); 1068 valueCache.put(value, indirection); 1069 1070 isChunked = saveIsChunked; 1076 start_block(); 1077 1078 return (java.io.Serializable )value; 1079 } 1080 1081 public Serializable read_value(BoxedValueHelper factory) { 1082 1083 int vType = readValueTag(); 1085 1086 if (vType == 0) 1087 return null; else if (vType == 0xffffffff) { int indirection = read_long() + get_offset() - 4; 1090 if (valueCache != null && valueCache.containsVal(indirection)) 1091 { 1092 java.io.Serializable cachedValue = 1093 (java.io.Serializable )valueCache.getKey(indirection); 1094 return cachedValue; 1095 } 1096 else { 1097 throw new IndirectionException (indirection); 1098 } 1099 } 1100 else { 1101 int indirection = get_offset() - 4; 1102 1103 1105 boolean saveIsChunked = isChunked; 1106 isChunked = repIdUtil.isChunkedEncoding(vType); 1107 1108 java.lang.Object value = null; 1109 1110 String codebase_URL = null; 1111 if (repIdUtil.isCodeBasePresent(vType)){ 1112 codebase_URL = read_codebase_URL(); 1113 } 1114 1115 String repositoryIDString 1117 = readRepositoryIds(vType, null, null, factory); 1118 1119 if (!repositoryIDString.equals(factory.get_id())) 1121 factory = Utility.getHelper(null, codebase_URL, repositoryIDString); 1122 1123 start_block(); 1124 end_flag--; 1125 if (isChunked) 1126 chunkedValueNestingLevel--; 1127 1128 if (factory instanceof ValueHelper ) { 1129 value = readIDLValueWithHelper((ValueHelper )factory, indirection); 1130 } else { 1131 valueIndirection = indirection; value = factory.read_value(parent); 1133 } 1134 1135 handleEndOfValue(); 1136 readEndTag(); 1137 1138 if (valueCache == null) 1140 valueCache = new CacheTable(orb,false); 1141 valueCache.put(value, indirection); 1142 1143 isChunked = saveIsChunked; 1145 start_block(); 1146 1147 return (java.io.Serializable )value; 1148 } 1149 } 1150 1151 private boolean isCustomType(ValueHelper helper) { 1152 try{ 1153 TypeCode tc = helper.get_type(); 1154 int kind = tc.kind().value(); 1155 if (kind == TCKind._tk_value) { 1156 return (tc.type_modifier() == org.omg.CORBA.VM_CUSTOM.value); 1157 } 1158 } catch(BadKind ex) { 1159 throw wrapper.badKind(ex) ; 1160 } 1161 1162 return false; 1163 } 1164 1165 public java.io.Serializable read_value(java.io.Serializable value) { 1170 1171 if (valueCache == null) 1173 valueCache = new CacheTable(orb,false); 1174 valueCache.put(value, valueIndirection); 1175 1176 if (value instanceof StreamableValue ) 1177 ((StreamableValue )value)._read(parent); 1178 else if (value instanceof CustomValue ) 1179 ((CustomValue )value).unmarshal(parent); 1180 1181 return value; 1182 } 1183 1184 public java.io.Serializable read_value(java.lang.String repositoryId) { 1185 1186 1189 int vType = readValueTag(); 1191 1192 if (vType == 0) 1193 return null; else if (vType == 0xffffffff) { int indirection = read_long() + get_offset() - 4; 1196 if (valueCache != null && valueCache.containsVal(indirection)) 1197 { 1198 java.io.Serializable cachedValue = 1199 (java.io.Serializable )valueCache.getKey(indirection); 1200 return cachedValue; 1201 } 1202 else { 1203 throw new IndirectionException (indirection); 1204 } 1205 } 1206 else { 1207 int indirection = get_offset() - 4; 1208 1209 1211 boolean saveIsChunked = isChunked; 1212 isChunked = repIdUtil.isChunkedEncoding(vType); 1213 1214 java.lang.Object value = null; 1215 1216 String codebase_URL = null; 1217 if (repIdUtil.isCodeBasePresent(vType)){ 1218 codebase_URL = read_codebase_URL(); 1219 } 1220 1221 String repositoryIDString 1223 = readRepositoryIds(vType, null, repositoryId); 1224 1225 ValueFactory factory = 1226 Utility.getFactory(null, codebase_URL, orb, repositoryIDString); 1227 1228 start_block(); 1229 end_flag--; 1230 if (isChunked) 1231 chunkedValueNestingLevel--; 1232 1233 valueIndirection = indirection; value = factory.read_value(parent); 1235 1236 handleEndOfValue(); 1237 readEndTag(); 1238 1239 if (valueCache == null) 1241 valueCache = new CacheTable(orb,false); 1242 valueCache.put(value, indirection); 1243 1244 isChunked = saveIsChunked; 1246 start_block(); 1247 1248 return (java.io.Serializable )value; 1249 } 1250 } 1251 1252 private Class readClass() { 1253 1254 String codebases = null, classRepId = null; 1255 1256 if (orb == null || 1257 ORBVersionFactory.getFOREIGN().equals(orb.getORBVersion()) || 1258 ORBVersionFactory.getNEWER().compareTo(orb.getORBVersion()) <= 0) { 1259 1260 codebases = (String )read_value(java.lang.String .class); 1261 classRepId = (String )read_value(java.lang.String .class); 1262 } else { 1263 classRepId = (String )read_value(java.lang.String .class); 1266 codebases = (String )read_value(java.lang.String .class); 1267 } 1268 1269 if (debug) { 1270 dprint("readClass codebases: " 1271 + codebases 1272 + " rep Id: " 1273 + classRepId); 1274 } 1275 1276 Class cl = null; 1277 1278 RepositoryIdInterface repositoryID 1279 = repIdStrs.getFromString(classRepId); 1280 1281 try { 1282 cl = repositoryID.getClassFromType(codebases); 1283 } catch(ClassNotFoundException cnfe) { 1284 throw wrapper.cnfeReadClass( CompletionStatus.COMPLETED_MAYBE, 1285 cnfe, repositoryID.getClassName() ) ; 1286 } catch(MalformedURLException me) { 1287 throw wrapper.malformedUrl( CompletionStatus.COMPLETED_MAYBE, 1288 me, repositoryID.getClassName(), codebases ) ; 1289 } 1290 1291 return cl; 1292 } 1293 1294 private java.lang.Object readIDLValueWithHelper(ValueHelper helper, int indirection) 1295 { 1296 Method readMethod; 1298 try { 1299 Class argTypes[] = {org.omg.CORBA.portable.InputStream .class, helper.get_class()}; 1300 readMethod = helper.getClass().getDeclaredMethod(kReadMethod, argTypes); 1301 } 1302 catch(NoSuchMethodException nsme) { java.lang.Object result = helper.read_value(parent); 1304 return result; 1305 } 1306 1307 java.lang.Object val = null; 1310 try { 1311 val = helper.get_class().newInstance(); 1312 } catch(java.lang.InstantiationException ie) { 1313 throw wrapper.couldNotInstantiateHelper( ie, 1314 helper.get_class() ) ; 1315 } catch(IllegalAccessException iae){ 1316 return helper.read_value(parent); 1323 } 1324 1325 if (valueCache == null) 1327 valueCache = new CacheTable(orb,false); 1328 valueCache.put(val, indirection); 1329 1330 if (val instanceof CustomMarshal && isCustomType(helper)) { 1332 ((CustomMarshal )val).unmarshal(parent); 1333 return val; 1334 } 1335 1336 try { 1338 java.lang.Object args[] = {parent, val}; 1339 readMethod.invoke(helper, args); 1340 return val; 1341 } catch(IllegalAccessException iae2) { 1342 throw wrapper.couldNotInvokeHelperReadMethod( iae2, helper.get_class() ) ; 1343 } catch(InvocationTargetException ite){ 1344 throw wrapper.couldNotInvokeHelperReadMethod( ite, helper.get_class() ) ; 1345 } 1346 } 1347 1348 private java.lang.Object readBoxedIDLEntity(Class clazz, String codebase) 1349 { 1350 Class cls = null ; 1351 1352 try { 1353 ClassLoader clazzLoader = (clazz == null ? null : clazz.getClassLoader()); 1354 1355 cls = Utility.loadClassForClass(clazz.getName()+"Helper", codebase, 1356 clazzLoader, clazz, clazzLoader); 1357 final Class helperClass = cls ; 1358 1359 final Class argTypes[] = {org.omg.CORBA.portable.InputStream .class}; 1360 1361 Method readMethod = null; 1364 try { 1365 readMethod = (Method )AccessController.doPrivileged( 1366 new PrivilegedExceptionAction () { 1367 public java.lang.Object run() throws NoSuchMethodException { 1368 return helperClass.getDeclaredMethod(kReadMethod, argTypes); 1369 } 1370 } 1371 ); 1372 } catch (PrivilegedActionException pae) { 1373 throw (NoSuchMethodException )pae.getException(); 1375 } 1376 1377 java.lang.Object args[] = {parent}; 1378 return readMethod.invoke(null, args); 1379 1380 } catch (ClassNotFoundException cnfe) { 1381 throw wrapper.couldNotInvokeHelperReadMethod( cnfe, cls ) ; 1382 } catch(NoSuchMethodException nsme) { 1383 throw wrapper.couldNotInvokeHelperReadMethod( nsme, cls ) ; 1384 } catch(IllegalAccessException iae) { 1385 throw wrapper.couldNotInvokeHelperReadMethod( iae, cls ) ; 1386 } catch(InvocationTargetException ite) { 1387 throw wrapper.couldNotInvokeHelperReadMethod( ite, cls ) ; 1388 } 1389 } 1390 1391 private java.lang.Object readIDLValue(int indirection, String repId, 1392 Class clazz, String codebase) 1393 { 1394 ValueFactory factory ; 1395 1396 try { 1405 factory = Utility.getFactory(clazz, codebase, orb, repId); 1407 } catch (MARSHAL marshal) { 1408 1410 if (!StreamableValue .class.isAssignableFrom(clazz) && 1412 !CustomValue .class.isAssignableFrom(clazz) && 1413 ValueBase .class.isAssignableFrom(clazz)) { 1414 BoxedValueHelper helper = Utility.getHelper(clazz, codebase, repId); 1416 if (helper instanceof ValueHelper ) 1417 return readIDLValueWithHelper((ValueHelper )helper, indirection); 1418 else 1419 return helper.read_value(parent); 1420 } else { 1421 return readBoxedIDLEntity(clazz, codebase); 1424 } 1425 } 1426 1427 valueIndirection = indirection; return factory.read_value(parent); 1430 } 1431 1432 1442 private void readEndTag() { 1443 if (isChunked) { 1444 1445 int anEndTag = read_long(); 1447 1448 if (anEndTag >= 0) { 1454 throw wrapper.positiveEndTag( CompletionStatus.COMPLETED_MAYBE, 1455 new Integer (anEndTag), new Integer ( get_offset() - 4 ) ) ; 1456 } 1457 1458 if (orb == null || 1463 ORBVersionFactory.getFOREIGN().equals(orb.getORBVersion()) || 1464 ORBVersionFactory.getNEWER().compareTo(orb.getORBVersion()) <= 0) { 1465 1466 if (anEndTag < chunkedValueNestingLevel) 1470 throw wrapper.unexpectedEnclosingValuetype( 1471 CompletionStatus.COMPLETED_MAYBE, new Integer ( anEndTag ), 1472 new Integer ( chunkedValueNestingLevel ) ) ; 1473 1474 if (anEndTag != chunkedValueNestingLevel) { 1481 bbwi.position(bbwi.position() - 4); 1482 } 1483 1484 } else { 1485 1486 if (anEndTag != end_flag) { 1491 bbwi.position(bbwi.position() - 4); 1492 } 1493 } 1494 1495 chunkedValueNestingLevel++; 1498 } 1499 1500 end_flag++; 1502 } 1503 1504 protected int get_offset() { 1505 return bbwi.position(); 1506 } 1507 1508 private void start_block() { 1509 1510 if (!isChunked) 1512 return; 1513 1514 blockLength = maxBlockLength; 1517 1518 blockLength = read_long(); 1519 1520 1523 if (blockLength > 0 && blockLength < maxBlockLength) { 1524 blockLength += get_offset(); 1526 } else { 1528 1529 1531 blockLength = maxBlockLength; 1533 1534 bbwi.position(bbwi.position() - 4); 1535 } 1536 } 1537 1538 private void handleEndOfValue() { 1545 1546 if (!isChunked) 1549 return; 1550 1551 while (blockLength != maxBlockLength) { 1553 end_block(); 1554 start_block(); 1555 } 1556 1557 1559 int nextLong = read_long(); 1565 bbwi.position(bbwi.position() - 4); 1566 1567 if (nextLong < 0) 1573 return; 1574 1575 if (nextLong == 0 || nextLong >= maxBlockLength) { 1576 1577 read_value(); 1589 handleEndOfValue(); 1590 } else { 1591 throw wrapper.couldNotSkipBytes( CompletionStatus.COMPLETED_MAYBE, 1596 new Integer ( nextLong ), new Integer ( get_offset() ) ) ; 1597 } 1598 } 1599 1600 private void end_block() { 1601 1602 if (blockLength != maxBlockLength) { 1604 if (blockLength == get_offset()) { 1605 blockLength = maxBlockLength; 1607 } else { 1608 if (blockLength > get_offset()) { 1611 skipToOffset(blockLength); 1612 } else { 1613 throw wrapper.badChunkLength( new Integer ( blockLength ), 1614 new Integer ( get_offset() ) ) ; 1615 } 1616 } 1617 } 1618 } 1619 1620 private int readValueTag(){ 1621 return read_long(); 1623 } 1624 1625 public org.omg.CORBA.ORB orb() { 1626 return orb; 1627 } 1628 1629 1631 public final void read_boolean_array(boolean[] value, int offset, int length) { 1632 for(int i=0; i < length; i++) { 1633 value[i+offset] = read_boolean(); 1634 } 1635 } 1636 1637 public final void read_char_array(char[] value, int offset, int length) { 1638 for(int i=0; i < length; i++) { 1639 value[i+offset] = read_char(); 1640 } 1641 } 1642 1643 public final void read_wchar_array(char[] value, int offset, int length) { 1644 for(int i=0; i < length; i++) { 1645 value[i+offset] = read_wchar(); 1646 } 1647 } 1648 1649 public final void read_short_array(short[] value, int offset, int length) { 1650 for(int i=0; i < length; i++) { 1651 value[i+offset] = read_short(); 1652 } 1653 } 1654 1655 public final void read_ushort_array(short[] value, int offset, int length) { 1656 read_short_array(value, offset, length); 1657 } 1658 1659 public final void read_long_array(int[] value, int offset, int length) { 1660 for(int i=0; i < length; i++) { 1661 value[i+offset] = read_long(); 1662 } 1663 } 1664 1665 public final void read_ulong_array(int[] value, int offset, int length) { 1666 read_long_array(value, offset, length); 1667 } 1668 1669 public final void read_longlong_array(long[] value, int offset, int length) { 1670 for(int i=0; i < length; i++) { 1671 value[i+offset] = read_longlong(); 1672 } 1673 } 1674 1675 public final void read_ulonglong_array(long[] value, int offset, int length) { 1676 read_longlong_array(value, offset, length); 1677 } 1678 1679 public final void read_float_array(float[] value, int offset, int length) { 1680 for(int i=0; i < length; i++) { 1681 value[i+offset] = read_float(); 1682 } 1683 } 1684 1685 public final void read_double_array(double[] value, int offset, int length) { 1686 for(int i=0; i < length; i++) { 1687 value[i+offset] = read_double(); 1688 } 1689 } 1690 1691 public final void read_any_array(org.omg.CORBA.Any [] value, int offset, int length) { 1692 for(int i=0; i < length; i++) { 1693 value[i+offset] = read_any(); 1694 } 1695 } 1696 1697 1701 1704 1708 1712 private String read_repositoryIds() { 1713 1714 int numRepIds = read_long(); 1716 if (numRepIds == 0xffffffff) { 1717 int indirection = read_long() + get_offset() - 4; 1718 if (repositoryIdCache != null && repositoryIdCache.containsOrderedVal(indirection)) 1719 return (String )repositoryIdCache.getKey(indirection); 1720 else 1721 throw wrapper.unableToLocateRepIdArray( new Integer ( indirection ) ) ; 1722 } else { 1723 1724 int indirection = get_offset(); 1726 String repID = read_repositoryId(); 1727 if (repositoryIdCache == null) 1728 repositoryIdCache = new CacheTable(orb,false); 1729 repositoryIdCache.put(repID, indirection); 1730 1731 for (int i = 1; i < numRepIds; i++) { 1734 read_repositoryId(); 1735 } 1736 1737 return repID; 1738 } 1739 } 1740 1741 private final String read_repositoryId() 1742 { 1743 String result = readStringOrIndirection(true); 1744 1745 if (result == null) { int indirection = read_long() + get_offset() - 4; 1747 1748 if (repositoryIdCache != null && repositoryIdCache.containsOrderedVal(indirection)) 1749 return (String )repositoryIdCache.getKey(indirection); 1750 else 1751 throw wrapper.badRepIdIndirection( CompletionStatus.COMPLETED_MAYBE, 1752 new Integer (bbwi.position()) ) ; 1753 } else { 1754 if (repositoryIdCache == null) 1755 repositoryIdCache = new CacheTable(orb,false); 1756 repositoryIdCache.put(result, stringIndirection); 1757 } 1758 1759 return result ; 1760 } 1761 1762 private final String read_codebase_URL() 1763 { 1764 String result = readStringOrIndirection(true); 1765 1766 if (result == null) { int indirection = read_long() + get_offset() - 4; 1768 1769 if (codebaseCache != null && codebaseCache.containsVal(indirection)) 1770 return (String )codebaseCache.getKey(indirection); 1771 else 1772 throw wrapper.badCodebaseIndirection( 1773 CompletionStatus.COMPLETED_MAYBE, 1774 new Integer (bbwi.position()) ) ; 1775 } else { 1776 if (codebaseCache == null) 1777 codebaseCache = new CacheTable(orb,false); 1778 codebaseCache.put(result, stringIndirection); 1779 } 1780 1781 return result; 1782 } 1783 1784 1785 1786 public java.lang.Object read_Abstract () { 1787 return read_abstract_interface(); 1788 } 1789 1790 public java.io.Serializable read_Value () { 1791 return read_value(); 1792 } 1793 1794 public void read_any_array (org.omg.CORBA.AnySeqHolder seq, int offset, int length) { 1795 read_any_array(seq.value, offset, length); 1796 } 1797 1798 public void read_boolean_array (org.omg.CORBA.BooleanSeqHolder seq, int offset, int length) { 1799 read_boolean_array(seq.value, offset, length); 1800 } 1801 1802 public void read_char_array (org.omg.CORBA.CharSeqHolder seq, int offset, int length) { 1803 read_char_array(seq.value, offset, length); 1804 } 1805 1806 public void read_wchar_array (org.omg.CORBA.WCharSeqHolder seq, int offset, int length) { 1807 read_wchar_array(seq.value, offset, length); 1808 } 1809 1810 public void read_octet_array (org.omg.CORBA.OctetSeqHolder seq, int offset, int length) { 1811 read_octet_array(seq.value, offset, length); 1812 } 1813 1814 public void read_short_array (org.omg.CORBA.ShortSeqHolder seq, int offset, int length) { 1815 read_short_array(seq.value, offset, length); 1816 } 1817 1818 public void read_ushort_array (org.omg.CORBA.UShortSeqHolder seq, int offset, int length) { 1819 read_ushort_array(seq.value, offset, length); 1820 } 1821 1822 public void read_long_array (org.omg.CORBA.LongSeqHolder seq, int offset, int length) { 1823 read_long_array(seq.value, offset, length); 1824 } 1825 1826 public void read_ulong_array (org.omg.CORBA.ULongSeqHolder seq, int offset, int length) { 1827 read_ulong_array(seq.value, offset, length); 1828 } 1829 1830 public void read_ulonglong_array (org.omg.CORBA.ULongLongSeqHolder seq, int offset, int length) { 1831 read_ulonglong_array(seq.value, offset, length); 1832 } 1833 1834 public void read_longlong_array (org.omg.CORBA.LongLongSeqHolder seq, int offset, int length) { 1835 read_longlong_array(seq.value, offset, length); 1836 } 1837 1838 public void read_float_array (org.omg.CORBA.FloatSeqHolder seq, int offset, int length) { 1839 read_float_array(seq.value, offset, length); 1840 } 1841 1842 public void read_double_array (org.omg.CORBA.DoubleSeqHolder seq, int offset, int length) { 1843 read_double_array(seq.value, offset, length); 1844 } 1845 1846 public java.math.BigDecimal read_fixed(short digits, short scale) { 1847 StringBuffer buffer = read_fixed_buffer(); 1849 if (digits != buffer.length()) 1850 throw wrapper.badFixed( new Integer (digits), 1851 new Integer (buffer.length()) ) ; 1852 buffer.insert(digits - scale, '.'); 1853 return new BigDecimal (buffer.toString()); 1854 } 1855 1856 public java.math.BigDecimal read_fixed() { 1858 return new BigDecimal (read_fixed_buffer().toString()); 1859 } 1860 1861 private StringBuffer read_fixed_buffer() { 1869 StringBuffer buffer = new StringBuffer (64); 1870 byte doubleDigit; 1871 int firstDigit; 1872 int secondDigit; 1873 boolean wroteFirstDigit = false; 1874 boolean more = true; 1875 while (more) { 1876 doubleDigit = this.read_octet(); 1877 firstDigit = (int)((doubleDigit & 0xf0) >> 4); 1878 secondDigit = (int)(doubleDigit & 0x0f); 1879 if (wroteFirstDigit || firstDigit != 0) { 1880 buffer.append(Character.forDigit(firstDigit, 10)); 1881 wroteFirstDigit = true; 1882 } 1883 if (secondDigit == 12) { 1884 if ( ! wroteFirstDigit) { 1886 return new StringBuffer ("0.0"); 1888 } else { 1889 } 1892 more = false; 1893 } else if (secondDigit == 13) { 1894 buffer.insert(0, '-'); 1896 more = false; 1897 } else { 1898 buffer.append(Character.forDigit(secondDigit, 10)); 1899 wroteFirstDigit = true; 1900 } 1901 } 1902 return buffer; 1903 } 1904 1905 private final static String _id = "IDL:omg.org/CORBA/DataInputStream:1.0"; 1906 private final static String [] _ids = { _id }; 1907 1908 public String [] _truncatable_ids() { 1909 if (_ids == null) 1910 return null; 1911 1912 return (String [])_ids.clone(); 1913 } 1914 1915 1916 1917 public void printBuffer() { 1918 CDRInputStream_1_0.printBuffer(this.bbwi); 1919 } 1920 1921 public static void printBuffer(ByteBufferWithInfo bbwi) { 1922 1923 System.out.println("----- Input Buffer -----"); 1924 System.out.println(); 1925 System.out.println("Current position: " + bbwi.position()); 1926 System.out.println("Total length : " + bbwi.buflen); 1927 System.out.println(); 1928 1929 try { 1930 1931 char[] charBuf = new char[16]; 1932 1933 for (int i = 0; i < bbwi.buflen; i += 16) { 1934 1935 int j = 0; 1936 1937 while (j < 16 && j + i < bbwi.buflen) { 1942 int k = bbwi.byteBuffer.get(i + j); 1943 if (k < 0) 1944 k = 256 + k; 1945 String hex = Integer.toHexString(k); 1946 if (hex.length() == 1) 1947 hex = "0" + hex; 1948 System.out.print(hex + " "); 1949 j++; 1950 } 1951 1952 while (j < 16) { 1956 System.out.print(" "); 1957 j++; 1958 } 1959 1960 int x = 0; 1963 while (x < 16 && x + i < bbwi.buflen) { 1964 if (ORBUtility.isPrintable((char)bbwi.byteBuffer.get(i + x))) 1965 charBuf[x] = (char)bbwi.byteBuffer.get(i + x); 1966 else 1967 charBuf[x] = '.'; 1968 x++; 1969 } 1970 System.out.println(new String (charBuf, 0, x)); 1971 } 1972 1973 } catch (Throwable t) { 1974 t.printStackTrace(); 1975 } 1976 1977 System.out.println("------------------------"); 1978 } 1979 1980 public ByteBuffer getByteBuffer() { 1981 ByteBuffer result = null; 1982 if (bbwi != null) { 1983 result = bbwi.byteBuffer; 1984 } 1985 return result; 1986 } 1987 1988 public int getBufferLength() { 1989 return bbwi.buflen; 1990 } 1991 1992 public void setBufferLength(int value) { 1993 bbwi.buflen = value; 1994 bbwi.byteBuffer.limit(bbwi.buflen); 1995 } 1996 1997 public void setByteBufferWithInfo(ByteBufferWithInfo bbwi) { 1998 this.bbwi = bbwi; 1999 } 2000 2001 public void setByteBuffer(ByteBuffer byteBuffer) { 2002 bbwi.byteBuffer = byteBuffer; 2003 } 2004 2005 public int getIndex() { 2006 return bbwi.position(); 2007 } 2008 2009 public void setIndex(int value) { 2010 bbwi.position(value); 2011 } 2012 2013 public boolean isLittleEndian() { 2014 return littleEndian; 2015 } 2016 2017 public void orb(org.omg.CORBA.ORB orb) { 2018 this.orb = (ORB)orb; 2019 } 2020 2021 public BufferManagerRead getBufferManager() { 2022 return bufferManagerRead; 2023 } 2024 2025 private void skipToOffset(int offset) { 2026 2027 int len = offset - get_offset(); 2029 2030 int n = 0; 2031 2032 while (n < len) { 2033 int avail; 2034 int bytes; 2035 int wanted; 2036 2037 avail = bbwi.buflen - bbwi.position(); 2038 if (avail <= 0) { 2039 grow(1, 1); 2040 avail = bbwi.buflen - bbwi.position(); 2041 } 2042 2043 wanted = len - n; 2044 bytes = (wanted < avail) ? wanted : avail; 2045 bbwi.position(bbwi.position() + bytes); 2046 n += bytes; 2047 } 2048 } 2049 2050 2051 2053 protected MarkAndResetHandler markAndResetHandler = null; 2054 2055 protected class StreamMemento 2056 { 2057 private int blockLength_; 2060 private int end_flag_; 2061 private int chunkedValueNestingLevel_; 2062 private int valueIndirection_; 2063 private int stringIndirection_; 2064 private boolean isChunked_; 2065 private javax.rmi.CORBA.ValueHandler valueHandler_; 2066 private ByteBufferWithInfo bbwi_; 2067 private boolean specialNoOptionalDataState_; 2068 2069 public StreamMemento() 2070 { 2071 blockLength_ = blockLength; 2072 end_flag_ = end_flag; 2073 chunkedValueNestingLevel_ = chunkedValueNestingLevel; 2074 valueIndirection_ = valueIndirection; 2075 stringIndirection_ = stringIndirection; 2076 isChunked_ = isChunked; 2077 valueHandler_ = valueHandler; 2078 specialNoOptionalDataState_ = specialNoOptionalDataState; 2079 bbwi_ = new ByteBufferWithInfo(bbwi); 2080 } 2081 } 2082 2083 public java.lang.Object createStreamMemento() { 2084 return new StreamMemento(); 2085 } 2086 2087 public void restoreInternalState(java.lang.Object streamMemento) { 2088 2089 StreamMemento mem = (StreamMemento)streamMemento; 2090 2091 blockLength = mem.blockLength_; 2092 end_flag = mem.end_flag_; 2093 chunkedValueNestingLevel = mem.chunkedValueNestingLevel_; 2094 valueIndirection = mem.valueIndirection_; 2095 stringIndirection = mem.stringIndirection_; 2096 isChunked = mem.isChunked_; 2097 valueHandler = mem.valueHandler_; 2098 specialNoOptionalDataState = mem.specialNoOptionalDataState_; 2099 bbwi = mem.bbwi_; 2100 } 2101 2102 public int getPosition() { 2103 return get_offset(); 2104 } 2105 2106 public void mark(int readlimit) { 2107 markAndResetHandler.mark(this); 2108 } 2109 2110 public void reset() { 2111 markAndResetHandler.reset(); 2112 } 2113 2114 2116 CodeBase getCodeBase() { 2121 return parent.getCodeBase(); 2122 } 2123 2124 2131 private Class getClassFromString(String repositoryIDString, 2132 String codebaseURL, 2133 Class expectedType) 2134 { 2135 RepositoryIdInterface repositoryID 2136 = repIdStrs.getFromString(repositoryIDString); 2137 2138 try { 2139 try { 2140 return repositoryID.getClassFromType(expectedType, 2143 codebaseURL); 2144 } catch (ClassNotFoundException cnfeOuter) { 2145 2146 try { 2147 2148 if (getCodeBase() == null) { 2149 return null; } 2151 2152 codebaseURL = getCodeBase().implementation(repositoryIDString); 2154 2155 if (codebaseURL == null) 2158 return null; 2159 2160 return repositoryID.getClassFromType(expectedType, 2161 codebaseURL); 2162 } catch (ClassNotFoundException cnfeInner) { 2163 dprintThrowable(cnfeInner); 2164 return null; 2166 } 2167 } 2168 } catch (MalformedURLException mue) { 2169 throw wrapper.malformedUrl( CompletionStatus.COMPLETED_MAYBE, 2171 mue, repositoryIDString, codebaseURL ) ; 2172 } 2173 } 2174 2175 2181 private Class getClassFromString(String repositoryIDString, 2182 String codebaseURL) 2183 { 2184 RepositoryIdInterface repositoryID 2185 = repIdStrs.getFromString(repositoryIDString); 2186 2187 for (int i = 0; i < 3; i++) { 2188 2189 try { 2190 2191 switch (i) 2192 { 2193 case 0: 2194 return repositoryID.getClassFromType(); 2196 case 1: 2197 break; 2200 case 2: 2201 codebaseURL = getCodeBase().implementation(repositoryIDString); 2204 break; 2205 } 2206 2207 if (codebaseURL == null) 2209 continue; 2210 2211 return repositoryID.getClassFromType(codebaseURL); 2212 2213 } catch(ClassNotFoundException cnfe) { 2214 } catch (MalformedURLException mue) { 2217 throw wrapper.malformedUrl( CompletionStatus.COMPLETED_MAYBE, 2218 mue, repositoryIDString, codebaseURL ) ; 2219 } 2220 } 2221 2222 dprint("getClassFromString failed with rep id " 2224 + repositoryIDString 2225 + " and codebase " 2226 + codebaseURL); 2227 2228 return null; 2229 } 2230 2231 char[] getConvertedChars(int numBytes, 2233 CodeSetConversion.BTCConverter converter) { 2234 2235 2239 if (bbwi.buflen - bbwi.position() >= numBytes) { 2241 byte[] tmpBuf; 2245 if (bbwi.byteBuffer.hasArray()) 2246 { 2247 tmpBuf = bbwi.byteBuffer.array(); 2248 } 2249 else 2250 { 2251 tmpBuf = new byte[bbwi.buflen]; 2252 for (int i = 0; i < bbwi.buflen; i++) 2255 tmpBuf[i] = bbwi.byteBuffer.get(i); 2256 } 2257 char[] result = converter.getChars(tmpBuf,bbwi.position(),numBytes); 2258 2259 bbwi.position(bbwi.position() + numBytes); 2260 return result; 2261 } else { 2262 byte[] bytes = new byte[numBytes]; 2266 read_octet_array(bytes, 0, bytes.length); 2267 2268 return converter.getChars(bytes, 0, numBytes); 2269 } 2270 } 2271 2272 protected CodeSetConversion.BTCConverter getCharConverter() { 2273 if (charConverter == null) 2274 charConverter = parent.createCharBTCConverter(); 2275 2276 return charConverter; 2277 } 2278 2279 protected CodeSetConversion.BTCConverter getWCharConverter() { 2280 if (wcharConverter == null) 2281 wcharConverter = parent.createWCharBTCConverter(); 2282 2283 return wcharConverter; 2284 } 2285 2286 protected void dprintThrowable(Throwable t) { 2287 if (debug && t != null) 2288 t.printStackTrace(); 2289 } 2290 2291 protected void dprint(String msg) { 2292 if (debug) { 2293 ORBUtility.dprint(this, msg); 2294 } 2295 } 2296 2297 2303 2304 void alignOnBoundary(int octetBoundary) { 2305 int needed = computeAlignment(bbwi.position(), octetBoundary); 2306 2307 if (bbwi.position() + needed <= bbwi.buflen) 2308 { 2309 bbwi.position(bbwi.position() + needed); 2310 } 2311 } 2312 2313 public void resetCodeSetConverters() { 2314 charConverter = null; 2315 wcharConverter = null; 2316 } 2317 2318 public void start_value() { 2319 int vType = readValueTag(); 2321 2322 if (vType == 0) { 2323 specialNoOptionalDataState = true; 2331 2332 return; 2333 } 2334 2335 if (vType == 0xffffffff) { 2336 throw wrapper.customWrapperIndirection( 2338 CompletionStatus.COMPLETED_MAYBE); 2339 } 2340 2341 if (repIdUtil.isCodeBasePresent(vType)) { 2342 throw wrapper.customWrapperWithCodebase( 2343 CompletionStatus.COMPLETED_MAYBE); 2344 } 2345 2346 if (repIdUtil.getTypeInfo(vType) 2347 != RepositoryIdUtility.SINGLE_REP_TYPE_INFO) { 2348 throw wrapper.customWrapperNotSingleRepid( 2349 CompletionStatus.COMPLETED_MAYBE); 2350 } 2351 2352 2353 read_repositoryId(); 2356 2357 2361 start_block(); 2362 end_flag--; 2363 chunkedValueNestingLevel--; 2364 } 2365 2366 public void end_value() { 2367 2368 if (specialNoOptionalDataState) { 2369 specialNoOptionalDataState = false; 2370 return; 2371 } 2372 2373 handleEndOfValue(); 2374 readEndTag(); 2375 2376 2381 start_block(); 2383 } 2384 2385 public void close() throws IOException 2386 { 2387 2388 getBufferManager().close(bbwi); 2390 2391 2397 if (bbwi != null && getByteBuffer() != null) 2398 { 2399 int bbHash = System.identityHashCode(bbwi.byteBuffer); 2400 MessageMediator messageMediator = parent.getMessageMediator(); 2401 if (messageMediator != null) 2402 { 2403 CDROutputObject outputObj = 2404 (CDROutputObject)messageMediator.getOutputObject(); 2405 if (outputObj != null) 2406 { 2407 ByteBuffer outputBb = outputObj.getByteBuffer(); 2408 2409 int oBbHash = 0; 2410 if (outputBb != null) 2411 { 2412 oBbHash = System.identityHashCode(outputBb); 2413 if (bbHash == oBbHash) { 2415 outputObj.setByteBuffer(null); 2418 outputObj.setByteBufferWithInfo(null); 2419 } 2420 } 2421 } 2422 } 2423 2424 ByteBufferPool byteBufferPool = orb.getByteBufferPool(); 2426 if (debug) 2427 { 2428 int bbAddress = System.identityHashCode(bbwi.byteBuffer); 2430 StringBuffer sb = new StringBuffer (80); 2431 sb.append(".close - releasing ByteBuffer id ("); 2432 sb.append(bbAddress).append(") to ByteBufferPool."); 2433 String msg = sb.toString(); 2434 dprint(msg); 2435 } 2436 byteBufferPool.releaseByteBuffer(bbwi.byteBuffer); 2437 bbwi.byteBuffer = null; 2438 bbwi = null; 2439 } 2440 } 2441} 2442 | Popular Tags |