1 19 package gcc.rmi.iiop; 20 21 import gcc.*; 22 import gcc.rmi.*; 23 import gcc.rmi.iiop.client.*; 24 import gcc.util.*; 25 import gcc.org.omg.IOP.*; 26 import gcc.org.omg.GIOP.*; 27 import org.omg.CORBA.TCKind; 28 import java.io.*; 29 30 33 public class CdrInputStream extends org.omg.CORBA_2_3.portable.InputStream 34 { 35 public static CdrInputStream getInstance() 36 { 37 CdrInputStream input = new CdrInputStream(); 38 input.init(new byte[64], 0, DEFAULT_BUFFER_LENGTH, false); 39 return input; 40 } 41 42 public static CdrInputStream getInstance(byte[] buffer) 43 { 44 CdrInputStream input = new CdrInputStream(); 45 input.init(buffer, 0, buffer.length, false); 46 return input; 47 } 48 49 public static CdrInputStream getInstance(byte[] buffer, int offset, int length, boolean little) 50 { 51 CdrInputStream input = new CdrInputStream(); 52 input.init(buffer, offset, length, little); 53 return input; 54 } 55 56 public static CdrInputStream getInstanceForEncapsulation() 57 { 58 return getInstance(); 59 } 60 61 public static CdrInputStream getPooledInstance() 62 { 63 CdrInputStream input = null; if (input == null) 65 { 66 input = getInstance(); 67 } 68 return input; 69 } 70 71 75 private static final int DEFAULT_BUFFER_LENGTH = 64; 76 77 private static final int MAXIMUM_POOLED_BUFFER_LENGTH = 1024; 78 79 private static boolean RMI_TRACE = true; 81 private static final byte[] EMPTY_BYTE_ARRAY = {}; 82 83 85 private GiopMessage _giopMessage; 86 87 private ClientNamingContext _namingContext; 88 89 private boolean _unaligned; 90 91 private byte[] _pooledBuffer; 92 93 97 byte[] _buffer; 98 99 int _offset; 100 101 int _length; 102 103 boolean _little; 104 105 109 public void init(byte[] buffer, int offset, int length, boolean little) 110 { 111 _buffer = buffer; 112 _offset = offset; 113 _length = length; 114 _little = little; 115 } 116 117 public void recycle() 118 { 119 reset(); 120 } 122 123 public void reset() 124 { 125 _offset = 0; 126 if (_buffer.length > MAXIMUM_POOLED_BUFFER_LENGTH) 127 { 128 _buffer = _pooledBuffer; 129 _pooledBuffer = null; 130 if (_buffer == null) 131 { 132 _buffer = new byte[DEFAULT_BUFFER_LENGTH]; 133 } 134 } 135 _length = _buffer.length; 136 _little = false; 137 _namingContext = null; 138 } 139 140 public void setUnaligned() 141 { 142 _unaligned = true; 143 } 144 145 public byte[] getBytes() 146 { 147 return ArrayUtil.getBytes(_buffer, 0, _length); 148 } 149 150 public byte[] getBuffer() 151 { 152 return _buffer; 153 } 154 155 public int getOffset() 156 { 157 return _offset; 158 } 159 160 public int getGiopVersion() 161 { 162 GiopMessage message = _giopMessage; 163 if (message == null) 164 { 165 throw new IllegalStateException(); 166 } 167 return message.giopVersion; 168 } 169 170 public void setLength(int length) 171 { 172 if (_buffer.length < length) 173 { 174 byte[] newBuffer = new byte[length]; 175 System.arraycopy(_buffer, 0, newBuffer, 0, 12); 176 pool(_buffer); 177 _buffer = newBuffer; 178 } 179 _length = length; 180 } 181 182 public void setNamingContext(ClientNamingContext namingContext) 183 { 184 _namingContext = namingContext; 185 } 186 187 public void setEncapsulation(byte[] data) 188 { 189 _buffer = data; 190 _offset = 0; 191 _length = data.length; 192 _little = read_boolean(); 193 } 194 195 public boolean hasMoreData() 196 { 197 return _offset < _length; 198 } 199 200 208 public final void read_align(int alignment, int size) 209 { 210 if (_unaligned) 211 { 212 alignment = 1; 213 } 214 int mask = alignment - 1; 215 _offset += (alignment - (_offset & mask)) & mask; 216 if (_offset + size <= _length) 217 { 218 return; 219 } 220 else 221 { 222 throw new org.omg.CORBA.MARSHAL("offset (" + _offset + ") + size (" 223 + size + ") > buffer length (" + _length + ")"); 224 } 225 } 226 227 230 public byte[] read_octet_sequence() 231 { 232 int n = read_long(); 233 if (n == 0) 234 { 235 return EMPTY_BYTE_ARRAY; 236 } 237 byte[] bytes = new byte[n]; 238 read_octet_array(bytes, 0, n); 239 return bytes; 240 } 241 242 public GiopMessage read_message() 243 { 244 return receive_message(null, null); 245 } 246 247 public GiopMessage receive_message(java.io.InputStream input, String host) 248 { 249 GiopMessage message = _giopMessage; 250 if (message == null) 251 { 252 message = _giopMessage = new GiopMessage(); 253 } 254 if (input != null) 255 { 256 read(input, _buffer, 0, 12); 257 } 258 int m1 = read_octet(); 259 int m2 = read_octet(); 260 int m3 = read_octet(); 261 int m4 = read_octet(); 262 if (m1 != 'G' || m2 != 'I' || m3 != 'O' || m4 != 'P') 263 { 264 throw new BadMagicException(m1 + "," + m2 + "," + m3 + "," + m4); 265 } 266 int v1 = read_octet(); 267 int v2 = read_octet(); 268 if (v1 != 1 || (v2 < 0 || v2 > 2)) { 270 throw new UnsupportedProtocolVersionException(v1 + "." + v2); 271 } 272 int giopVersion; 273 message.giopVersion = giopVersion = v2; 274 int flags = read_octet(); 275 _little = (flags & 1) != 0; 276 boolean fragmented = (flags & 2) != 0; 277 int messageType = message.type = read_octet(); 278 int messageSize = message.size = read_ulong(); 279 if (fragmented && messageSize % 8 != 0) 280 { 281 throw new org.omg.CORBA.MARSHAL("GIOP Fragment: bad message size (not divisible by 8) = " + messageSize); 282 } 283 _length = 12 + messageSize; 284 if (messageSize > 0 && input != null) 285 { 286 if (_buffer.length < _length) 287 { 288 byte[] newBuffer = new byte[_length]; 289 System.arraycopy(_buffer, 0, newBuffer, 0, 12); 290 pool(_buffer); 291 _buffer = newBuffer; 292 } 293 read(input, _buffer, 12, _length); 294 } 295 if (RMI_TRACE && host != null) 296 { 297 byte[] data = new byte[_length]; 298 System.arraycopy(_buffer, 0, data, 0, _length); 299 RmiTrace.receive(host, data); 300 } 301 switch (messageType) 302 { 303 case MsgType_1_1._Request: 304 switch (giopVersion) 305 { 306 case GiopVersion.VERSION_1_0: 307 { 308 RequestHeader_1_0 req10 = RequestHeader_1_0Helper.read(this); 309 RequestHeader_1_2 req12 = new RequestHeader_1_2(); 310 req12.service_context = req10.service_context; 311 req12.request_id = req10.request_id; 312 req12.response_flags = (byte)(req10.response_expected ? 3 : 0); 313 req12.operation = req10.operation; 314 (req12.target = new TargetAddress()).object_key(req10.object_key); 315 message.request = req12; 316 } 317 break; 318 case GiopVersion.VERSION_1_1: 319 { 320 RequestHeader_1_1 req11 = RequestHeader_1_1Helper.read(this); 321 RequestHeader_1_2 req12 = new RequestHeader_1_2(); 322 req12.service_context = req11.service_context; 323 req12.request_id = req11.request_id; 324 req12.response_flags = (byte)(req11.response_expected ? 3 : 0); 325 req12.operation = req11.operation; 326 (req12.target = new TargetAddress()).object_key(req11.object_key); 327 message.request = req12; 328 } 329 break; 330 case GiopVersion.VERSION_1_2: 331 message.request = RequestHeader_1_2Helper.read(this); 332 if (_length > _offset) 333 { 334 read_align(8, 0); } 336 break; 337 } 338 break; 339 case MsgType_1_1._Reply: 340 message.reply = ReplyHeader_1_2Helper.read(this); 341 if (giopVersion >= GiopVersion.VERSION_1_2) 342 { 343 if (_length > _offset) 344 { 345 read_align(8, 0); } 347 } 348 break; 349 case MsgType_1_1._LocateRequest: 350 switch (giopVersion) 351 { 352 case GiopVersion.VERSION_1_0: 353 case GiopVersion.VERSION_1_1: 354 { 355 LocateRequestHeader_1_0 req10 = LocateRequestHeader_1_0Helper.read(this); 356 LocateRequestHeader_1_2 req12 = new LocateRequestHeader_1_2(); 357 req12.request_id = req10.request_id; 358 (req12.target = new TargetAddress()).object_key(req10.object_key); 359 message.locateRequest = req12; 360 } 361 break; 362 default: 363 message.locateRequest = LocateRequestHeader_1_2Helper.read(this); 364 } 365 break; 366 case MsgType_1_1._LocateReply: 367 throw new org.omg.CORBA.MARSHAL("GIOP LocateReply: unexpected"); 369 default: 371 throw new org.omg.CORBA.NO_IMPLEMENT("TODO: message type = " + messageType); 372 } 373 return message; 374 } 375 376 380 public boolean read_boolean() 381 { 382 read_align(1, 1); 383 int b = _buffer[_offset++]; 384 if (b == 0) 385 { 386 return false; 387 } 388 else if (b == 1) 389 { 390 return true; 391 } 392 else 393 { 394 throw new org.omg.CORBA.MARSHAL("read_boolean: value = " + b); 395 } 396 } 397 398 public char read_char() 399 { 400 read_align(1, 1); 401 return (char)_buffer[_offset++]; 402 } 403 404 public char read_wchar() 405 { 406 read_align(1, 3); 407 int size = (int)read_wchar_size(); 408 int value = (char)read_ushort_no_align_big_endian(); 409 boolean littleEndian = ((value & 0xffff) == 0xFFFE); 410 boolean bigEndian = ((value & 0xffff) == 0xFEFF); 411 boolean bomPresent = (littleEndian || bigEndian); 412 if ((bomPresent && size != 4) || (! bomPresent && size != 2)) 413 { 414 throw new org.omg.CORBA.MARSHAL("wchar size = " + size 415 + (bomPresent ? " (BOM present)" : " (BOM absent)")); 416 } 417 if (littleEndian) 418 { 419 read_align(1, 2); 420 return (char)read_ushort_no_align_little_endian(); 421 } 422 else if (bigEndian) 423 { 424 read_align(1, 2); 425 return (char)read_ushort_no_align_big_endian(); 426 } 427 else 428 { 429 return (char)value; 431 } 432 } 433 434 public byte read_octet() 435 { 436 read_align(1, 1); 437 return _buffer[_offset++]; 438 } 439 440 public short read_short() 441 { 442 read_align(2, 2); 443 int oldOffset = _offset; 444 _offset += 2; 445 if (_little) 446 { 447 return LittleEndian.getShort(_buffer, oldOffset); 448 } 449 else 450 { 451 return BigEndian.getShort(_buffer, oldOffset); 452 } 453 } 454 455 public short read_ushort() 456 { 457 return read_short(); 458 } 459 460 public int read_long() 461 { 462 read_align(4, 4); 463 int oldOffset = _offset; 464 _offset += 4; 465 if (_little) 466 { 467 return LittleEndian.getInt(_buffer, oldOffset); 468 } 469 else 470 { 471 return BigEndian.getInt(_buffer, oldOffset); 472 } 473 } 474 475 public int read_ulong() 476 { 477 return read_long(); 478 } 479 480 public long read_longlong() 481 { 482 read_align(8, 8); 483 int oldOffset = _offset; 484 _offset += 8; 485 if (_little) 486 { 487 return LittleEndian.getLong(_buffer, oldOffset); 488 } 489 else 490 { 491 return BigEndian.getLong(_buffer, oldOffset); 492 } 493 } 494 495 public long read_ulonglong() 496 { 497 return read_longlong(); 498 } 499 500 public float read_float() 501 { 502 return Float.intBitsToFloat(read_ulong()); 503 } 504 505 public double read_double() 506 { 507 return Double.longBitsToDouble(read_ulonglong()); 508 } 509 510 public java.lang.String read_string() 511 { 512 int size = read_ulong(); 513 if (size < 1) { 515 throw new org.omg.CORBA.MARSHAL("read_string: size = " + size); 516 } 517 read_align(1, size); 518 size--; 519 if (_buffer[_offset + size] != 0) 520 { 521 throw new org.omg.CORBA.MARSHAL("read_string: missing NUL"); 522 } 523 String value = UTF8.toString(_buffer, _offset, size); 525 _offset += size + 1; return value; 527 } 528 529 public java.lang.String read_wstring() 530 { 531 int size = read_long(); 532 if (size == 0) 533 { 534 return ""; 535 } 536 read_align(2, size); 537 int numChars = size / 2; 538 boolean littleEndian = false; 539 read_align(1, 2); 540 int firstChar = (char)read_ushort_no_align_big_endian(); 541 _offset+=2; 542 char[] result; 543 int index = 0; 544 if (firstChar == 0xFEFF) 545 { 546 result = new char[--numChars]; 548 } 549 else if (firstChar == 0xFFFE) 550 { 551 result = new char[--numChars]; 553 littleEndian = true; 554 } 555 else 556 { 557 result = new char[numChars--]; 559 result[index++] = (char)firstChar; 560 } 561 read_align(1, 2 * numChars); 562 if (littleEndian) 563 { 564 for (int i = 0; i < numChars; i++) 565 { 566 result[index++] = (char)read_ushort_no_align_little_endian(); 567 _offset+=2; 568 } 569 } 570 else 571 { 572 for (int i = 0; i < numChars; i++) 573 { 574 result[index++] = (char)read_ushort_no_align_big_endian(); 575 _offset+=2; 576 } 577 } 578 return new String(result); 579 } 580 581 public void read_boolean_array(boolean[] value, int offset, int length) 582 { 583 for (int i = 0; i < length; i++) 584 { 585 value[offset + i] = read_boolean(); 586 } 587 } 588 589 public void read_char_array(char[] value, int offset, int length) 590 { 591 for (int i = 0; i < length; i++) 592 { 593 value[i] = read_char(); 594 } 595 } 596 597 public void read_wchar_array(char[] value, int offset, int length) 598 { 599 for (int i = 0; i < length; i++) 600 { 601 value[offset + i] = read_wchar(); 602 } 603 } 604 605 public void read_octet_array(byte[] value, int offset, int length) 606 { 607 read_align(1, length); 608 System.arraycopy(_buffer, _offset, value, offset, length); 609 _offset += length; 610 } 611 612 public void read_short_array(short[] value, int offset, int length) 613 { 614 for (int i = 0; i < length; i++) 615 { 616 value[offset + i] = read_short(); 617 } 618 } 619 620 public void read_ushort_array(short[] value, int offset, int length) 621 { 622 for (int i = 0; i < length; i++) 623 { 624 value[offset + i] = read_ushort(); 625 } 626 } 627 628 public void read_long_array(int[] value, int offset, int length) 629 { 630 for (int i = 0; i < length; i++) 631 { 632 value[offset + i] = read_long(); 633 } 634 } 635 636 public void read_ulong_array(int[] value, int offset, int length) 637 { 638 for (int i = 0; i < length; i++) 639 { 640 value[offset + i] = read_ulong(); 641 } 642 } 643 644 public void read_longlong_array(long[] value, int offset, int length) 645 { 646 for (int i = 0; i < length; i++) 647 { 648 value[offset + i] = read_longlong(); 649 } 650 } 651 652 public void read_ulonglong_array(long[] value, int offset, int length) 653 { 654 for (int i = 0; i < length; i++) 655 { 656 value[offset + i] = read_ulonglong(); 657 } 658 } 659 660 public void read_float_array(float[] value, int offset, int length) 661 { 662 for (int i = 0; i < length; i++) 663 { 664 value[offset + i] = read_float(); 665 } 666 } 667 668 public void read_double_array(double[] value, int offset, int length) 669 { 670 for (int i = 0; i < length; i++) 671 { 672 value[offset + i] = read_double(); 673 } 674 } 675 676 public org.omg.CORBA.Object read_Object() 677 { 678 IOR ior = IORHelper.read(this); 679 if (ior.profiles.length == 0) 680 { 681 return null; 682 } 683 ObjectRef stub = null; 684 if (ior.type_id.length() != 0) 685 { 686 if (ior.type_id.startsWith("RMI:") && ior.type_id.endsWith(":0000000000000000")) 688 { 689 String interfaceName = ior.type_id.substring(4, ior.type_id.length() - 17); 690 691 System.out.println( "TODO: CdrInputStream.read_Object(): NYI: interfaceName = " + interfaceName + ", ior = " + ior.type_id ); 692 stub = null; 693 694 } 697 if (ior.type_id.startsWith("IDL:") && ior.type_id.endsWith(":1.0")) 698 { 699 String interfaceName = ior.type_id.substring(4, ior.type_id.length() - 4).replace('/', '.'); 700 701 System.out.println( "TODO: CdrInputStream.read_Object(): NYI: interfaceName = " + interfaceName + ", ior = " + ior.type_id ); 702 stub = null; 703 704 } 707 } 708 if (stub == null) 709 { 710 stub = new ObjectRef(); 711 } 712 stub.$setIOR(ior); 713 stub.$setNamingContext(_namingContext); 714 return stub; 715 } 716 717 public org.omg.CORBA.TypeCode read_TypeCode() 718 { 719 return read_TypeCode(new java.util.HashMap()); 720 } 721 722 private org.omg.CORBA.TypeCode read_TypeCode(java.util.HashMap table) 723 { 724 int beforeKindOffset = _offset; 725 int tk = read_ulong(); 726 int afterKindOffset = _offset; 727 gcc.rmi.iiop.TypeCode tc; 728 if (tk == 0xffffffff) 729 { 730 int offset = read_long(); 732 Integer key = new Integer(afterKindOffset + offset); 733 org.omg.CORBA.TypeCode ref = (org.omg.CORBA.TypeCode)table.get(key); 734 if (ref == null) 735 { 736 throw new org.omg.CORBA.MARSHAL("read_TypeCode: bad indirection: offset = " + offset); 737 } 738 tc = new gcc.rmi.iiop.TypeCode(TCKind.tk_null); 739 tc.indirection(ref); 740 return tc; 741 } 742 tc = new gcc.rmi.iiop.TypeCode(TCKind.from_int(tk)); 743 table.put(new Integer(beforeKindOffset), tc); 744 switch (tk) 745 { 746 case TCKind._tk_null: 747 case TCKind._tk_void: 748 case TCKind._tk_TypeCode: 749 case TCKind._tk_any: 750 case TCKind._tk_boolean: 751 case TCKind._tk_char: 752 case TCKind._tk_wchar: 753 case TCKind._tk_octet: 754 case TCKind._tk_short: 755 case TCKind._tk_ushort: 756 case TCKind._tk_long: 757 case TCKind._tk_ulong: 758 case TCKind._tk_longlong: 759 case TCKind._tk_ulonglong: 760 case TCKind._tk_float: 761 case TCKind._tk_double: 762 case TCKind._tk_longdouble: 763 break; 765 case TCKind._tk_fixed: 766 tc.fixed_digits(read_ushort()); 767 tc.fixed_scale(read_short()); 768 break; 769 case TCKind._tk_string: 770 case TCKind._tk_wstring: 771 tc.length(read_ulong()); 772 break; 773 case TCKind._tk_objref: 774 case TCKind._tk_native: 775 case TCKind._tk_abstract_interface: 776 { 777 boolean saveLittle = begin(); 778 tc.id(read_string()); 779 tc.name(read_string()); 780 end(saveLittle); 781 } 782 break; 783 case TCKind._tk_alias: 784 case TCKind._tk_value_box: 786 { 788 boolean saveLittle = begin(); 789 tc.id(read_string()); 790 tc.name(read_string()); 791 tc.content_type(read_TypeCode(table)); 792 end(saveLittle); 793 } 794 break; 795 case TCKind._tk_sequence: 796 case TCKind._tk_array: 797 { 798 boolean saveLittle = begin(); 799 tc.content_type(read_TypeCode(table)); 800 tc.length(read_ulong()); 801 end(saveLittle); 802 } 803 break; 804 case TCKind._tk_enum: 805 { 806 boolean saveLittle = begin(); 807 tc.id(read_string()); 808 tc.name(read_string()); 809 int count = read_ulong(); 810 tc.member_count(count); 811 for (int i = 0; i < count; i++) 812 { 813 tc.member_name(i, read_string()); 814 } 815 end(saveLittle); 816 } 817 break; 818 case TCKind._tk_struct: 819 case TCKind._tk_except: 820 { 821 boolean saveLittle = begin(); 822 tc.id(read_string()); 823 tc.name(read_string()); 824 int count = read_ulong(); 825 tc.member_count(count); 826 for (int i = 0; i < count; i++) 827 { 828 tc.member_name(i, read_string()); 829 tc.member_type(i, read_TypeCode(table)); 830 } 831 end(saveLittle); 832 } 833 break; 834 case TCKind._tk_union: 835 { 836 boolean saveLittle = begin(); 837 tc.id(read_string()); 838 tc.name(read_string()); 839 org.omg.CORBA.TypeCode dt = read_TypeCode(table); 840 tc.discriminator_type(dt); 841 int di = read_ulong(); 842 int count = read_ulong(); 843 tc.member_count(count); 844 for (int i = 0; i < count; i++) 845 { 846 org.omg.CORBA.Any label = new gcc.rmi.iiop.Any(); 847 read_Any(label.create_output_stream(), dt); 848 label.read_value(null, dt); 849 tc.member_label(i, label); 850 tc.member_name(i, read_string()); 851 tc.member_type(i, read_TypeCode(table)); 852 } 853 tc.default_index(di); end(saveLittle); 855 } 856 break; 857 case TCKind._tk_value: 858 { 859 boolean saveLittle = begin(); 860 tc.id(read_string()); 861 tc.name(read_string()); 862 tc.type_modifier(read_short()); 863 tc.concrete_base_type(read_TypeCode(table)); 864 int count = read_ulong(); 865 tc.member_count(count); 866 for (int i = 0; i < count; i++) 867 { 868 tc.member_name(i, read_string()); 869 tc.member_type(i, read_TypeCode(table)); 870 tc.member_visibility(i, read_short()); 871 } 872 end(saveLittle); 873 } 874 break; 875 default: 876 throw new org.omg.CORBA.MARSHAL("read_TypeCode: kind = " + tk); 877 } 878 return tc; 879 } 880 881 public org.omg.CORBA.Any read_Any() 882 { 883 org.omg.CORBA.TypeCode tc = read_TypeCode(); 884 org.omg.CORBA.Any value = new gcc.rmi.iiop.Any(); 885 org.omg.CORBA.portable.OutputStream os = value.create_output_stream(); 886 read_Any(os, tc); 887 value.read_value(os.create_input_stream(), tc); 888 return value; 889 } 890 891 public void read_Any(org.omg.CORBA.portable.OutputStream os, org.omg.CORBA.TypeCode tc) 893 { 894 try 895 { 896 int tk = tc.kind().value(); 897 switch (tk) 898 { 899 case TCKind._tk_null: 900 case TCKind._tk_void: 901 break; 902 case TCKind._tk_TypeCode: 903 os.write_TypeCode(read_TypeCode()); 904 break; 905 case TCKind._tk_any: 906 os.write_any(read_Any()); 907 break; 908 case TCKind._tk_boolean: 909 os.write_boolean(read_boolean()); 910 break; 911 case TCKind._tk_char: 912 os.write_char(read_char()); 913 break; 914 case TCKind._tk_wchar: 915 os.write_wchar(read_wchar()); 916 break; 917 case TCKind._tk_octet: 918 os.write_octet(read_octet()); 919 break; 920 case TCKind._tk_short: 921 os.write_short(read_short()); 922 break; 923 case TCKind._tk_ushort: 924 os.write_ushort(read_ushort()); 925 break; 926 case TCKind._tk_long: 927 os.write_long(read_long()); 928 break; 929 case TCKind._tk_ulong: 930 case TCKind._tk_enum: 931 os.write_ulong(read_ulong()); 932 break; 933 case TCKind._tk_longlong: 934 os.write_longlong(read_longlong()); 935 break; 936 case TCKind._tk_ulonglong: 937 os.write_ulonglong(read_ulonglong()); 938 break; 939 case TCKind._tk_float: 940 os.write_float(read_float()); 941 break; 942 case TCKind._tk_double: 943 os.write_double(read_double()); 944 break; 945 case TCKind._tk_string: 946 os.write_string(read_string()); 947 break; 948 case TCKind._tk_wstring: 949 os.write_wstring(read_wstring()); 950 break; 951 case TCKind._tk_objref: 952 os.write_Object(read_Object()); 953 break; 954 case TCKind._tk_alias: 955 read_Any(os, tc.content_type()); 956 break; 957 case TCKind._tk_array: 958 { 959 int n = tc.length(); 960 org.omg.CORBA.TypeCode c = tc.content_type(); 961 for (int i = 0; i < n; i++) 962 { 963 read_Any(os, c); 964 } 965 } 966 break; 967 case TCKind._tk_sequence: 968 { 969 int n = read_ulong(); 970 os.write_ulong(n); 971 org.omg.CORBA.TypeCode c = tc.content_type(); 972 for (int i = 0; i < n; i++) 973 { 974 read_Any(os, c); 975 } 976 } 977 break; 978 case TCKind._tk_struct: 979 case TCKind._tk_except: 980 { 981 int n = tc.member_count(); 982 for (int i = 0; i < n; i++) 983 { 984 read_Any(os, tc.member_type(i)); 985 } 986 } 987 break; 988 case TCKind._tk_union: 989 { 990 org.omg.CORBA.TypeCode dt = tc.discriminator_type(); 991 org.omg.CORBA.Any disc = new gcc.rmi.iiop.Any(); 992 read_Any(disc.create_output_stream(), dt); 993 disc.read_value(null, dt); 994 write_disc(disc, os, dt); 995 int di = tc.default_index(); 996 int i, n = tc.member_count(); 997 for (i = 0; i < n; i++) 998 { 999 org.omg.CORBA.Any label = tc.member_label(i); 1000 if (label.equal(disc)) 1001 { 1002 read_Any(os, tc.member_type(i)); 1003 break; 1004 } 1005 } 1006 if (i == n && di >= 0) 1007 { 1008 read_Any(os, tc.member_type(di)); 1009 } 1010 } 1011 break; 1012 case TCKind._tk_fixed: case TCKind._tk_value: default: 1015 throw new org.omg.CORBA.MARSHAL("read_Any: type = " + tc); 1016 } 1017 } 1018 catch (org.omg.CORBA.TypeCodePackage.BadKind ex) 1019 { 1020 throw new org.omg.CORBA.MARSHAL("read_Any: " + ex.toString()); 1021 } 1022 catch (org.omg.CORBA.TypeCodePackage.Bounds ex) 1023 { 1024 throw new org.omg.CORBA.MARSHAL("read_Any: " + ex.toString()); 1025 } 1026 } 1027 1028 public org.omg.CORBA.Any read_any() 1029 { 1030 throw new org.omg.CORBA.NO_IMPLEMENT("read_any: NOT YET IMPLMENTED"); 1031 } 1032 1033 public org.omg.CORBA.Principal read_Principal() 1034 { 1035 throw new org.omg.CORBA.NO_IMPLEMENT("read_Principal: NOT YET IMPLMENTED"); 1036 } 1037 1038 public int read() throws java.io.IOException 1039 { 1040 throw new org.omg.CORBA.NO_IMPLEMENT("read: NOT YET IMPLMENTED"); 1041 } 1042 1043 public java.math.BigDecimal read_fixed() 1044 { 1045 throw new org.omg.CORBA.NO_IMPLEMENT("read_fixed: NOT YET IMPLMENTED"); 1046 } 1047 1048 public org.omg.CORBA.Context read_Context() 1049 { 1050 throw new org.omg.CORBA.NO_IMPLEMENT("read_Context: NOT YET IMPLMENTED"); 1051 } 1052 1053 public org.omg.CORBA.Object read_Object(Class _class) 1054 { 1055 throw new org.omg.CORBA.NO_IMPLEMENT("read_Object: NOT YET IMPLMENTED"); 1056 } 1057 1058 public org.omg.CORBA.ORB orb() 1059 { 1060 throw new org.omg.CORBA.NO_IMPLEMENT("orb: NOT YET IMPLMENTED"); 1061 } 1062 1063 1064 1068 public java.io.Serializable read_value() 1069 { 1070 throw new org.omg.CORBA.NO_IMPLEMENT("read_value: NOT YET IMPLMENTED"); 1071 } 1072 1073 public java.io.Serializable read_value(Class _class) 1074 { 1075 throw new org.omg.CORBA.NO_IMPLEMENT("read_value: NOT YET IMPLMENTED"); 1076 } 1077 1078 public java.io.Serializable read_value(org.omg.CORBA.portable.BoxedValueHelper helper) 1079 { 1080 throw new org.omg.CORBA.NO_IMPLEMENT("read_value: NOT YET IMPLMENTED"); 1081 } 1082 1083 public java.io.Serializable read_value(java.lang.String id) 1084 { 1085 throw new org.omg.CORBA.NO_IMPLEMENT("read_value: NOT YET IMPLMENTED"); 1086 } 1087 1088 public java.io.Serializable read_value(java.io.Serializable todo) 1089 { 1090 throw new org.omg.CORBA.NO_IMPLEMENT("read_value: NOT YET IMPLMENTED"); 1091 } 1092 1093 public java.lang.Object read_abstract_interface() 1094 { 1095 throw new org.omg.CORBA.NO_IMPLEMENT("read_abstract_interface: NOT YET IMPLMENTED"); 1096 } 1097 1098 public java.lang.Object read_abstract_interface(Class _class) 1099 { 1100 throw new org.omg.CORBA.NO_IMPLEMENT("read_abstract_interface: NOT YET IMPLMENTED"); 1101 } 1102 1103 1104 1108 protected void pool(byte[] oldBuffer) 1109 { 1110 if (oldBuffer.length <= MAXIMUM_POOLED_BUFFER_LENGTH) 1111 { 1112 _pooledBuffer = oldBuffer; 1113 } 1114 } 1115 1116 protected int read_ushort_no_align_big_endian() 1117 { 1118 return UnsignedShort.intValue(BigEndian.getShort(_buffer, _offset)); 1119 } 1120 1121 protected int read_ushort_no_align_little_endian() 1122 { 1123 return UnsignedShort.intValue(LittleEndian.getShort(_buffer, _offset)); 1124 } 1125 1126 protected int read_wchar_size() 1127 { 1128 read_align(1, 1); 1129 int size = _buffer[_offset++]; 1130 if (size < 2) 1131 { 1132 throw new org.omg.CORBA.MARSHAL("wchar size = " + size); 1133 } 1134 return size; 1135 } 1136 1137 protected void read(java.io.InputStream input, byte[] buffer, int offset, int length) 1138 { 1139 try 1140 { 1141 while (offset < length) 1142 { 1143 int needLength = length - offset; 1144 int readLength = input.read(buffer, offset, needLength); 1145 if (readLength == -1) 1146 { 1147 throw new org.omg.CORBA.MARSHAL("read: EOF"); 1148 } 1149 offset += readLength; 1150 } 1151 } 1152 catch (java.io.IOException ex) 1153 { 1154 throw new org.omg.CORBA.COMM_FAILURE(ex.toString()); 1155 } 1156 } 1157 1158 public boolean begin() 1159 { 1160 int length = read_ulong(); boolean saveLittle = _little; 1162 _little = read_boolean(); 1163 return saveLittle; 1164 } 1165 1166 public void end(boolean saveLittle) 1167 { 1168 _little = saveLittle; 1169 } 1170 1171 private void write_disc(org.omg.CORBA.Any disc, org.omg.CORBA.portable.OutputStream os, org.omg.CORBA.TypeCode dt) 1172 { 1173 int tk = dt.kind().value(); 1174 if (tk == TCKind._tk_alias) 1175 { 1176 try 1177 { 1178 write_disc(disc, os, dt.content_type()); 1179 } 1180 catch (org.omg.CORBA.TypeCodePackage.BadKind ex) 1181 { 1182 throw new org.omg.CORBA.MARSHAL("write_disc: " + ex.toString()); 1183 } 1184 } 1185 switch (tk) 1186 { 1187 case TCKind._tk_boolean: 1188 os.write_boolean(disc.extract_boolean()); 1189 break; 1190 case TCKind._tk_octet: 1191 os.write_octet(disc.extract_octet()); 1192 break; 1193 case TCKind._tk_short: 1194 os.write_short(disc.extract_short()); 1195 break; 1196 case TCKind._tk_ushort: 1197 os.write_ushort(disc.extract_ushort()); 1198 break; 1199 case TCKind._tk_long: 1200 os.write_long(disc.extract_long()); 1201 break; 1202 case TCKind._tk_ulong: 1203 case TCKind._tk_enum: 1204 os.write_ulong(disc.extract_ulong()); 1205 break; 1206 case TCKind._tk_longlong: 1207 os.write_longlong(disc.extract_longlong()); 1208 break; 1209 case TCKind._tk_ulonglong: 1210 os.write_ulonglong(disc.extract_ulonglong()); 1211 break; 1212 default: 1213 throw new org.omg.CORBA.MARSHAL("write_disc: type = " + dt); 1214 } 1215 } 1216 1217} 1218 | Popular Tags |