1 7 8 package com.sun.corba.se.impl.corba; 9 10 import java.util.HashMap ; 11 import java.util.Map ; 12 import java.util.Iterator ; 13 import java.util.List ; 14 import java.util.Collections ; 15 import java.util.ArrayList ; 16 import java.io.IOException ; 17 import java.io.PrintStream ; 18 import java.io.ByteArrayOutputStream ; 19 import java.math.BigDecimal ; 20 import java.math.BigInteger ; 21 22 import org.omg.CORBA.TypeCode ; 23 import org.omg.CORBA.StructMember ; 24 import org.omg.CORBA.UnionMember ; 25 import org.omg.CORBA.ValueMember ; 26 import org.omg.CORBA.TCKind ; 27 import org.omg.CORBA.Any ; 28 import org.omg.CORBA.Principal ; 29 import org.omg.CORBA.BAD_TYPECODE ; 30 import org.omg.CORBA.BAD_PARAM ; 31 import org.omg.CORBA.BAD_OPERATION ; 32 import org.omg.CORBA.INTERNAL ; 33 import org.omg.CORBA.MARSHAL ; 34 import org.omg.CORBA.TypeCodePackage.BadKind ; 35 import org.omg.CORBA_2_3.portable.InputStream ; 36 import org.omg.CORBA_2_3.portable.OutputStream ; 37 38 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 39 import com.sun.corba.se.spi.orb.ORB; 40 import com.sun.corba.se.spi.logging.CORBALogDomains; 41 42 import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry; 43 import com.sun.corba.se.impl.encoding.MarshalInputStream; 44 import com.sun.corba.se.impl.encoding.CodeSetConversion; 45 import com.sun.corba.se.impl.encoding.CDRInputStream; 46 import com.sun.corba.se.impl.encoding.CDROutputStream; 47 import com.sun.corba.se.impl.encoding.TypeCodeInputStream; 48 import com.sun.corba.se.impl.encoding.TypeCodeOutputStream; 49 import com.sun.corba.se.impl.encoding.TypeCodeReader; 50 import com.sun.corba.se.impl.encoding.WrapperInputStream; 51 52 import com.sun.corba.se.impl.logging.ORBUtilSystemException; 53 54 public final class TypeCodeImpl extends TypeCode 56 { 57 59 protected static final int tk_indirect = 0xFFFFFFFF; 61 62 65 private static final int EMPTY = 0; private static final int SIMPLE = 1; private static final int COMPLEX = 2; 71 73 private static final int typeTable[] = { 74 EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, COMPLEX, COMPLEX, COMPLEX, COMPLEX, SIMPLE, COMPLEX, COMPLEX, COMPLEX, COMPLEX, EMPTY, EMPTY, EMPTY, EMPTY, SIMPLE, SIMPLE, COMPLEX, COMPLEX, COMPLEX, COMPLEX }; 108 109 static final String [] kindNames = { 112 "null", 113 "void", 114 "short", 115 "long", 116 "ushort", 117 "ulong", 118 "float", 119 "double", 120 "boolean", 121 "char", 122 "octet", 123 "any", 124 "typecode", 125 "principal", 126 "objref", 127 "struct", 128 "union", 129 "enum", 130 "string", 131 "sequence", 132 "array", 133 "alias", 134 "exception", 135 "longlong", 136 "ulonglong", 137 "longdouble", 138 "wchar", 139 "wstring", 140 "fixed", 141 "value", 142 "valueBox", 143 "native", 144 "abstractInterface" 145 }; 146 147 private int _kind = 0; 149 private String _id = ""; private String _name = ""; private int _memberCount = 0; private String _memberNames[] = null; private TypeCodeImpl _memberTypes[] = null; private AnyImpl _unionLabels[] = null; private TypeCodeImpl _discriminator = null; private int _defaultIndex = -1; private int _length = 0; private TypeCodeImpl _contentType = null; private short _digits = 0; 162 private short _scale = 0; 163 private short _type_modifier = -1; private TypeCodeImpl _concrete_base = null; private short _memberAccess[] = null; private TypeCodeImpl _parent = null; private int _parentOffset = 0; private TypeCodeImpl _indirectType = null; 176 177 private byte[] outBuffer = null; 179 private boolean cachingEnabled = false; 181 182 private ORB _orb; 184 private ORBUtilSystemException wrapper ; 185 186 189 public TypeCodeImpl(ORB orb) 190 { 191 _orb = orb; 193 wrapper = ORBUtilSystemException.get( 194 (com.sun.corba.se.spi.orb.ORB)orb, CORBALogDomains.RPC_PRESENTATION ) ; 195 } 196 197 public TypeCodeImpl(ORB orb, TypeCode tc) 198 { 201 this(orb) ; 202 203 if (tc instanceof TypeCodeImpl) { 208 TypeCodeImpl tci = (TypeCodeImpl)tc; 209 if (tci._kind == tk_indirect) 210 throw wrapper.badRemoteTypecode() ; 211 if (tci._kind == TCKind._tk_sequence && tci._contentType == null) 212 throw wrapper.badRemoteTypecode() ; 213 } 214 215 _kind = tc.kind().value(); 217 218 try { 219 switch (_kind) { 221 case TCKind._tk_value: 222 _type_modifier = tc.type_modifier(); 223 TypeCode tccb = tc.concrete_base_type(); 225 if (tccb != null) { 226 _concrete_base = convertToNative(_orb, tccb); 227 } else { 228 _concrete_base = null; 229 } 230 _memberAccess = new short[tc.member_count()]; 233 for (int i=0; i < tc.member_count(); i++) { 234 _memberAccess[i] = tc.member_visibility(i); 235 } 236 case TCKind._tk_except: 237 case TCKind._tk_struct: 238 case TCKind._tk_union: 239 _memberTypes = new TypeCodeImpl[tc.member_count()]; 241 for (int i=0; i < tc.member_count(); i++) { 242 _memberTypes[i] = convertToNative(_orb, tc.member_type(i)); 243 _memberTypes[i].setParent(this); 244 } 245 case TCKind._tk_enum: 246 _memberNames = new String [tc.member_count()]; 248 for (int i=0; i < tc.member_count(); i++) { 249 _memberNames[i] = tc.member_name(i); 250 } 251 _memberCount = tc.member_count(); 253 case TCKind._tk_objref: 254 case TCKind._tk_alias: 255 case TCKind._tk_value_box: 256 case TCKind._tk_native: 257 case TCKind._tk_abstract_interface: 258 setId(tc.id()); 259 _name = tc.name(); 260 break; 261 } 262 263 switch (_kind) { 265 case TCKind._tk_union: 266 _discriminator = convertToNative(_orb, tc.discriminator_type()); 267 _defaultIndex = tc.default_index(); 268 _unionLabels = new AnyImpl[_memberCount]; 269 for (int i=0; i < _memberCount; i++) 270 _unionLabels[i] = new AnyImpl(_orb, tc.member_label(i)); 271 break; 272 } 273 274 switch (_kind) { 276 case TCKind._tk_string: 277 case TCKind._tk_wstring: 278 case TCKind._tk_sequence: 279 case TCKind._tk_array: 280 _length = tc.length(); 281 } 282 283 switch (_kind) { 285 case TCKind._tk_sequence: 286 case TCKind._tk_array: 287 case TCKind._tk_alias: 288 case TCKind._tk_value_box: 289 _contentType = convertToNative(_orb, tc.content_type()); 290 } 291 } catch (org.omg.CORBA.TypeCodePackage.Bounds e) {} catch (BadKind e) {} 292 } 295 296 public TypeCodeImpl(ORB orb, int creationKind) 297 { 299 this(orb); 300 301 304 _kind = creationKind; 305 306 switch (_kind) { 308 case TCKind._tk_objref: 309 { 310 setId("IDL:omg.org/CORBA/Object:1.0"); 312 _name = "Object"; 313 break; 314 } 315 316 case TCKind._tk_string: 317 case TCKind._tk_wstring: 318 { 319 _length =0; 320 break; 321 } 322 323 case TCKind._tk_value: 324 { 325 _concrete_base = null; 326 break; 327 } 328 } 329 } 330 331 public TypeCodeImpl(ORB orb, 332 int creationKind, 333 String id, 334 String name, 335 StructMember [] members) 336 { 338 this(orb); 339 340 if ((creationKind == TCKind._tk_struct) || (creationKind == TCKind._tk_except)) { 341 _kind = creationKind; 342 setId(id); 343 _name = name; 344 _memberCount = members.length; 345 346 _memberNames = new String [_memberCount]; 347 _memberTypes = new TypeCodeImpl[_memberCount]; 348 349 for (int i = 0 ; i < _memberCount ; i++) { 350 _memberNames[i] = members[i].name; 351 _memberTypes[i] = convertToNative(_orb, members[i].type); 352 _memberTypes[i].setParent(this); 353 } 354 } } 356 357 public TypeCodeImpl(ORB orb, 358 int creationKind, 359 String id, 360 String name, 361 TypeCode discriminator_type, 362 UnionMember [] members) 363 { 365 this(orb) ; 366 367 if (creationKind == TCKind._tk_union) { 368 _kind = creationKind; 369 setId(id); 370 _name = name; 371 _memberCount = members.length; 372 _discriminator = convertToNative(_orb, discriminator_type); 373 374 _memberNames = new String [_memberCount]; 375 _memberTypes = new TypeCodeImpl[_memberCount]; 376 _unionLabels = new AnyImpl[_memberCount]; 377 378 for (int i = 0 ; i < _memberCount ; i++) { 379 _memberNames[i] = members[i].name; 380 _memberTypes[i] = convertToNative(_orb, members[i].type); 381 _memberTypes[i].setParent(this); 382 _unionLabels[i] = new AnyImpl(_orb, members[i].label); 383 if (_unionLabels[i].type().kind() == TCKind.tk_octet) { 385 if (_unionLabels[i].extract_octet() == (byte)0) { 386 _defaultIndex = i; 387 } 388 } 389 } 390 } } 392 393 public TypeCodeImpl(ORB orb, 394 int creationKind, 395 String id, 396 String name, 397 short type_modifier, 398 TypeCode concrete_base, 399 ValueMember [] members) 400 { 402 this(orb) ; 403 404 if (creationKind == TCKind._tk_value) { 405 _kind = creationKind; 406 setId(id); 407 _name = name; 408 _type_modifier = type_modifier; 409 if (_concrete_base != null) { 410 _concrete_base = convertToNative(_orb, concrete_base); 411 } 412 _memberCount = members.length; 413 414 _memberNames = new String [_memberCount]; 415 _memberTypes = new TypeCodeImpl[_memberCount]; 416 _memberAccess = new short[_memberCount]; 417 418 for (int i = 0 ; i < _memberCount ; i++) { 419 _memberNames[i] = members[i].name; 420 _memberTypes[i] = convertToNative(_orb, members[i].type); 421 _memberTypes[i].setParent(this); 422 _memberAccess[i] = members[i].access; 423 } 424 } } 426 427 428 public TypeCodeImpl(ORB orb, 429 int creationKind, 430 String id, 431 String name, 432 String [] members) 433 { 435 this(orb) ; 436 437 if (creationKind == TCKind._tk_enum) 438 { 439 _kind = creationKind; 440 setId(id); 441 _name = name; 442 _memberCount = members.length; 443 444 _memberNames = new String [_memberCount]; 445 446 for (int i = 0 ; i < _memberCount ; i++) 447 _memberNames[i] = members[i]; 448 } } 450 451 public TypeCodeImpl(ORB orb, 452 int creationKind, 453 String id, 454 String name, 455 TypeCode original_type) 456 { 458 this(orb) ; 459 460 if ( creationKind == TCKind._tk_alias || creationKind == TCKind._tk_value_box ) 461 { 462 _kind = creationKind; 463 setId(id); 464 _name = name; 465 _contentType = convertToNative(_orb, original_type); 466 } 467 469 } 470 471 public TypeCodeImpl(ORB orb, 472 int creationKind, 473 String id, 474 String name) 475 { 476 this(orb) ; 477 478 if (creationKind == TCKind._tk_objref || 479 creationKind == TCKind._tk_native || 480 creationKind == TCKind._tk_abstract_interface) 481 { 482 _kind = creationKind; 483 setId(id); 484 _name = name; 485 } } 487 488 489 public TypeCodeImpl(ORB orb, 490 int creationKind, 491 int bound) 492 { 494 this(orb) ; 495 496 if (bound < 0) 497 throw wrapper.negativeBounds() ; 498 499 if ((creationKind == TCKind._tk_string) || (creationKind == TCKind._tk_wstring)) { 500 _kind = creationKind; 501 _length = bound; 502 } } 504 505 public TypeCodeImpl(ORB orb, 506 int creationKind, 507 int bound, 508 TypeCode element_type) 509 { 511 this(orb) ; 512 513 if ( creationKind == TCKind._tk_sequence || creationKind == TCKind._tk_array ) { 514 _kind = creationKind; 515 _length = bound; 516 _contentType = convertToNative(_orb, element_type); 517 } } 519 520 public TypeCodeImpl(ORB orb, 521 int creationKind, 522 int bound, 523 int offset) 524 { 526 this(orb) ; 527 528 if (creationKind == TCKind._tk_sequence) { 529 _kind = creationKind; 530 _length = bound; 531 _parentOffset = offset; 532 } } 534 535 public TypeCodeImpl(ORB orb, 536 String id) 537 { 539 this(orb) ; 540 541 _kind = tk_indirect; 542 _id = id; 544 tryIndirectType(); 547 } 548 549 public TypeCodeImpl(ORB orb, 550 int creationKind, 551 short digits, 552 short scale) 553 { 555 this(orb) ; 556 557 560 if (creationKind == TCKind._tk_fixed) { 561 _kind = creationKind; 562 _digits = digits; 563 _scale = scale; 564 } } 566 567 570 protected static TypeCodeImpl convertToNative(ORB orb, 576 TypeCode tc) 577 { 578 if (tc instanceof TypeCodeImpl) 579 return (TypeCodeImpl) tc; 580 else 581 return new TypeCodeImpl(orb, tc); 582 } 583 584 public static CDROutputStream newOutputStream(ORB orb) { 585 TypeCodeOutputStream tcos = new TypeCodeOutputStream((ORB)orb); 586 return tcos; 589 } 590 591 593 private TypeCodeImpl indirectType() { 594 _indirectType = tryIndirectType(); 595 if (_indirectType == null) { 596 throw wrapper.unresolvedRecursiveTypecode() ; 598 } 599 return _indirectType; 600 } 601 602 private TypeCodeImpl tryIndirectType() { 603 if (_indirectType != null) 605 return _indirectType; 606 607 setIndirectType(_orb.getTypeCode(_id)); 608 609 return _indirectType; 610 } 611 612 private void setIndirectType(TypeCodeImpl newType) { 613 _indirectType = newType; 614 if (_indirectType != null) { 615 try { 616 _id = _indirectType.id(); 617 } catch (BadKind e) { 618 throw wrapper.badkindCannotOccur() ; 620 } 621 } 622 } 623 624 private void setId(String newID) { 625 _id = newID; 626 if (_orb instanceof TypeCodeFactory) { 627 ((TypeCodeFactory)_orb).setTypeCode(_id, this); 628 } 629 } 632 633 private void setParent(TypeCodeImpl parent) { 634 _parent = parent; 635 } 636 637 private TypeCodeImpl getParentAtLevel(int level) { 638 if (level == 0) 639 return this; 640 641 if (_parent == null) 642 throw wrapper.unresolvedRecursiveTypecode() ; 643 644 return _parent.getParentAtLevel(level - 1); 645 } 646 647 private TypeCodeImpl lazy_content_type() { 648 if (_contentType == null) { 649 if (_kind == TCKind._tk_sequence && _parentOffset > 0 && _parent != null) { 650 TypeCodeImpl realParent = getParentAtLevel(_parentOffset); 653 if (realParent != null && realParent._id != null) { 654 _contentType = new TypeCodeImpl((ORB)_orb, realParent._id); 658 } 659 } 660 } 661 return _contentType; 662 } 663 664 666 private TypeCode realType(TypeCode aType) { 667 TypeCode realType = aType; 668 try { 669 while (realType.kind().value() == TCKind._tk_alias) { 671 realType = realType.content_type(); 672 } 673 } catch (BadKind bad) { 674 throw wrapper.badkindCannotOccur() ; 676 } 677 return realType; 678 } 679 680 683 public final boolean equal(TypeCode tc) 684 { 687 if (tc == this) 688 return true; 689 690 try { 691 692 if (_kind == tk_indirect) { 693 if (_id != null && tc.id() != null) 695 return _id.equals(tc.id()); 696 return (_id == null && tc.id() == null); 697 } 698 699 if (_kind != tc.kind().value()) { 701 return false; 702 } 703 704 switch (typeTable[_kind]) { 705 case EMPTY: 706 return true; 708 709 case SIMPLE: 710 switch (_kind) { 711 case TCKind._tk_string: 712 case TCKind._tk_wstring: 713 return (_length == tc.length()); 715 716 case TCKind._tk_fixed: 717 return (_digits == tc.fixed_digits() && _scale == tc.fixed_scale()); 718 default: 719 return false; 720 } 721 722 case COMPLEX: 723 724 switch(_kind) { 725 726 case TCKind._tk_objref: 727 { 728 if (_id.compareTo(tc.id()) == 0) { 730 return true; 731 } 732 733 if (_id.compareTo( 734 (_orb.get_primitive_tc(_kind)).id()) == 0) 735 { 736 return true; 737 } 738 739 if (tc.id().compareTo( 740 (_orb.get_primitive_tc(_kind)).id()) == 0) 741 { 742 return true; 743 } 744 745 return false; 746 } 747 748 case TCKind._tk_native: 749 case TCKind._tk_abstract_interface: 750 { 751 if (_id.compareTo(tc.id()) != 0) { 753 return false; 754 755 } 756 return true; 758 } 759 760 case TCKind._tk_struct: 761 case TCKind._tk_except: 762 { 763 if (_memberCount != tc.member_count()) 765 return false; 766 if (_id.compareTo(tc.id()) != 0) 768 return false; 769 for (int i = 0 ; i < _memberCount ; i++) 771 if (! _memberTypes[i].equal(tc.member_type(i))) 772 return false; 773 return true; 775 } 776 777 case TCKind._tk_union: 778 { 779 if (_memberCount != tc.member_count()) 781 return false; 782 if (_id.compareTo(tc.id()) != 0) 784 return false; 785 if (_defaultIndex != tc.default_index()) 787 return false; 788 if (!_discriminator.equal(tc.discriminator_type())) 790 return false; 791 for (int i = 0 ; i < _memberCount ; i++) 793 if (! _unionLabels[i].equal(tc.member_label(i))) 794 return false; 795 for (int i = 0 ; i < _memberCount ; i++) 797 if (! _memberTypes[i].equal(tc.member_type(i))) 798 return false; 799 return true; 801 } 802 803 case TCKind._tk_enum: 804 { 805 if (_id.compareTo(tc.id()) != 0) 807 return false; 808 if (_memberCount != tc.member_count()) 810 return false; 811 return true; 813 } 814 815 case TCKind._tk_sequence: 816 case TCKind._tk_array: 817 { 818 if (_length != tc.length()) { 820 return false; 821 } 822 if (! lazy_content_type().equal(tc.content_type())) { 824 return false; 825 } 826 return true; 828 } 829 830 case TCKind._tk_value: 831 { 832 if (_memberCount != tc.member_count()) 834 return false; 835 if (_id.compareTo(tc.id()) != 0) 837 return false; 838 for (int i = 0 ; i < _memberCount ; i++) 840 if (_memberAccess[i] != tc.member_visibility(i) || 841 ! _memberTypes[i].equal(tc.member_type(i))) 842 return false; 843 if (_type_modifier == tc.type_modifier()) 844 return false; 845 TypeCode tccb = tc.concrete_base_type(); 847 if ((_concrete_base == null && tccb != null) || 848 (_concrete_base != null && tccb == null) || 849 ! _concrete_base.equal(tccb)) 850 { 851 return false; 852 } 853 return true; 855 } 856 857 case TCKind._tk_alias: 858 case TCKind._tk_value_box: 859 { 860 if (_id.compareTo(tc.id()) != 0) { 862 return false; 863 } 864 return _contentType.equal(tc.content_type()); 866 } 867 } 868 } 869 } catch (org.omg.CORBA.TypeCodePackage.Bounds e) {} catch (BadKind e) {} 870 return false; 873 } 874 875 879 public boolean equivalent(TypeCode tc) { 880 if (tc == this) { 881 return true; 882 } 883 884 TypeCode myRealType = (_kind == tk_indirect ? indirectType() : this); 889 myRealType = realType(myRealType); 890 TypeCode otherRealType = realType(tc); 891 892 if (myRealType.kind().value() != otherRealType.kind().value()) { 895 return false; 896 } 897 898 String myID = null; 899 String otherID = null; 900 try { 901 myID = this.id(); 902 otherID = tc.id(); 903 905 if (myID != null && otherID != null) { 909 return (myID.equals(otherID)); 910 } 911 } catch (BadKind e) { 912 } 914 915 918 int myKind = myRealType.kind().value(); 919 try { 920 if (myKind == TCKind._tk_struct || 921 myKind == TCKind._tk_union || 922 myKind == TCKind._tk_enum || 923 myKind == TCKind._tk_except || 924 myKind == TCKind._tk_value) 925 { 926 if (myRealType.member_count() != otherRealType.member_count()) 927 return false; 928 } 929 if (myKind == TCKind._tk_union) 930 { 931 if (myRealType.default_index() != otherRealType.default_index()) 932 return false; 933 } 934 if (myKind == TCKind._tk_string || 935 myKind == TCKind._tk_wstring || 936 myKind == TCKind._tk_sequence || 937 myKind == TCKind._tk_array) 938 { 939 if (myRealType.length() != otherRealType.length()) 940 return false; 941 } 942 if (myKind == TCKind._tk_fixed) 943 { 944 if (myRealType.fixed_digits() != otherRealType.fixed_digits() || 945 myRealType.fixed_scale() != otherRealType.fixed_scale()) 946 return false; 947 } 948 if (myKind == TCKind._tk_union) 949 { 950 for (int i=0; i<myRealType.member_count(); i++) { 951 if (myRealType.member_label(i) != otherRealType.member_label(i)) 952 return false; 953 } 954 if ( ! myRealType.discriminator_type().equivalent( 955 otherRealType.discriminator_type())) 956 return false; 957 } 958 if (myKind == TCKind._tk_alias || 959 myKind == TCKind._tk_value_box || 960 myKind == TCKind._tk_sequence || 961 myKind == TCKind._tk_array) 962 { 963 if ( ! myRealType.content_type().equivalent(otherRealType.content_type())) 964 return false; 965 } 966 if (myKind == TCKind._tk_struct || 967 myKind == TCKind._tk_union || 968 myKind == TCKind._tk_except || 969 myKind == TCKind._tk_value) 970 { 971 for (int i=0; i<myRealType.member_count(); i++) { 972 if ( ! myRealType.member_type(i).equivalent( 973 otherRealType.member_type(i))) 974 return false; 975 } 976 } 977 } catch (BadKind e) { 978 throw wrapper.badkindCannotOccur() ; 980 } catch (org.omg.CORBA.TypeCodePackage.Bounds e) { 981 throw wrapper.boundsCannotOccur() ; 983 } 984 985 return true; 987 } 988 989 public TypeCode get_compact_typecode() { 990 return this; 994 } 995 996 public TCKind kind() 997 { 998 if (_kind == tk_indirect) 999 return indirectType().kind(); 1000 return TCKind.from_int(_kind); 1001 } 1002 1003 public boolean is_recursive() 1004 { 1005 return (_kind == tk_indirect); 1008 } 1009 1010 public String id() 1011 throws BadKind 1012 { 1013 switch (_kind) { 1014 case tk_indirect: 1015 case TCKind._tk_except: 1017 case TCKind._tk_objref: 1018 case TCKind._tk_struct: 1019 case TCKind._tk_union: 1020 case TCKind._tk_enum: 1021 case TCKind._tk_alias: 1022 case TCKind._tk_value: 1023 case TCKind._tk_value_box: 1024 case TCKind._tk_native: 1025 case TCKind._tk_abstract_interface: 1026 return _id; 1029 default: 1030 throw new BadKind (); 1032 } 1033 } 1034 1035 public String name() 1036 throws BadKind 1037 { 1038 switch (_kind) { 1039 case tk_indirect: 1040 return indirectType().name(); 1041 case TCKind._tk_except: 1042 case TCKind._tk_objref: 1043 case TCKind._tk_struct: 1044 case TCKind._tk_union: 1045 case TCKind._tk_enum: 1046 case TCKind._tk_alias: 1047 case TCKind._tk_value: 1048 case TCKind._tk_value_box: 1049 case TCKind._tk_native: 1050 case TCKind._tk_abstract_interface: 1051 return _name; 1052 default: 1053 throw new BadKind (); 1054 } 1055 } 1056 1057 public int member_count() 1058 throws BadKind 1059 { 1060 switch (_kind) { 1061 case tk_indirect: 1062 return indirectType().member_count(); 1063 case TCKind._tk_except: 1064 case TCKind._tk_struct: 1065 case TCKind._tk_union: 1066 case TCKind._tk_enum: 1067 case TCKind._tk_value: 1068 return _memberCount; 1069 default: 1070 throw new BadKind (); 1071 } 1072 } 1073 1074 public String member_name(int index) 1075 throws BadKind , org.omg.CORBA.TypeCodePackage.Bounds 1076 { 1077 switch (_kind) { 1078 case tk_indirect: 1079 return indirectType().member_name(index); 1080 case TCKind._tk_except: 1081 case TCKind._tk_struct: 1082 case TCKind._tk_union: 1083 case TCKind._tk_enum: 1084 case TCKind._tk_value: 1085 try { 1086 return _memberNames[index]; 1087 } catch (ArrayIndexOutOfBoundsException e) { 1088 throw new org.omg.CORBA.TypeCodePackage.Bounds (); 1089 } 1090 default: 1091 throw new BadKind (); 1092 } 1093 } 1094 1095 public TypeCode member_type(int index) 1096 throws BadKind , org.omg.CORBA.TypeCodePackage.Bounds 1097 { 1098 switch (_kind) { 1099 case tk_indirect: 1100 return indirectType().member_type(index); 1101 case TCKind._tk_except: 1102 case TCKind._tk_struct: 1103 case TCKind._tk_union: 1104 case TCKind._tk_value: 1105 try { 1106 return _memberTypes[index]; 1107 } catch (ArrayIndexOutOfBoundsException e) { 1108 throw new org.omg.CORBA.TypeCodePackage.Bounds (); 1109 } 1110 default: 1111 throw new BadKind (); 1112 } 1113 } 1114 1115 public Any member_label(int index) 1116 throws BadKind , org.omg.CORBA.TypeCodePackage.Bounds 1117 { 1118 switch (_kind) { 1119 case tk_indirect: 1120 return indirectType().member_label(index); 1121 case TCKind._tk_union: 1122 try { 1123 return new AnyImpl(_orb, _unionLabels[index]); 1125 } catch (ArrayIndexOutOfBoundsException e) { 1126 throw new org.omg.CORBA.TypeCodePackage.Bounds (); 1127 } 1128 default: 1129 throw new BadKind (); 1130 } 1131 } 1132 1133 public TypeCode discriminator_type() 1134 throws BadKind 1135 { 1136 switch (_kind) { 1137 case tk_indirect: 1138 return indirectType().discriminator_type(); 1139 case TCKind._tk_union: 1140 return _discriminator; 1141 default: 1142 throw new BadKind (); 1143 } 1144 } 1145 1146 public int default_index() 1147 throws BadKind 1148 { 1149 switch (_kind) { 1150 case tk_indirect: 1151 return indirectType().default_index(); 1152 case TCKind._tk_union: 1153 return _defaultIndex; 1154 default: 1155 throw new BadKind (); 1156 } 1157 } 1158 1159 public int length() 1160 throws BadKind 1161 { 1162 switch (_kind) { 1163 case tk_indirect: 1164 return indirectType().length(); 1165 case TCKind._tk_string: 1166 case TCKind._tk_wstring: 1167 case TCKind._tk_sequence: 1168 case TCKind._tk_array: 1169 return _length; 1170 default: 1171 throw new BadKind (); 1172 } 1173 } 1174 1175 public TypeCode content_type() 1176 throws BadKind 1177 { 1178 switch (_kind) { 1179 case tk_indirect: 1180 return indirectType().content_type(); 1181 case TCKind._tk_sequence: 1182 return lazy_content_type(); 1183 case TCKind._tk_array: 1184 case TCKind._tk_alias: 1185 case TCKind._tk_value_box: 1186 return _contentType; 1187 default: 1188 throw new BadKind (); 1189 } 1190 } 1191 1192 public short fixed_digits() throws BadKind { 1193 switch (_kind) { 1194 case TCKind._tk_fixed: 1195 return _digits; 1196 default: 1197 throw new BadKind (); 1198 } 1199 } 1200 1201 public short fixed_scale() throws BadKind { 1202 switch (_kind) { 1203 case TCKind._tk_fixed: 1204 return _scale; 1205 default: 1206 throw new BadKind (); 1207 } 1208 } 1209 1210 public short member_visibility(int index) throws BadKind , 1211 org.omg.CORBA.TypeCodePackage.Bounds { 1212 switch (_kind) { 1213 case tk_indirect: 1214 return indirectType().member_visibility(index); 1215 case TCKind._tk_value: 1216 try { 1217 return _memberAccess[index]; 1218 } catch (ArrayIndexOutOfBoundsException e) { 1219 throw new org.omg.CORBA.TypeCodePackage.Bounds (); 1220 } 1221 default: 1222 throw new BadKind (); 1223 } 1224 } 1225 1226 public short type_modifier() throws BadKind { 1227 switch (_kind) { 1228 case tk_indirect: 1229 return indirectType().type_modifier(); 1230 case TCKind._tk_value: 1231 return _type_modifier; 1232 default: 1233 throw new BadKind (); 1234 } 1235 } 1236 1237 public TypeCode concrete_base_type() throws BadKind { 1238 switch (_kind) { 1239 case tk_indirect: 1240 return indirectType().concrete_base_type(); 1241 case TCKind._tk_value: 1242 return _concrete_base; 1243 default: 1244 throw new BadKind (); 1245 } 1246 } 1247 1248 public void read_value(InputStream is) { 1249 if (is instanceof TypeCodeReader) { 1250 if (read_value_kind((TypeCodeReader)is)) 1252 read_value_body(is); 1253 } else if (is instanceof CDRInputStream) { 1254 WrapperInputStream wrapper = new WrapperInputStream((CDRInputStream)is); 1255 if (read_value_kind((TypeCodeReader)wrapper)) 1258 read_value_body(wrapper); 1259 } else { 1260 read_value_kind(is); 1261 read_value_body(is); 1262 } 1263 } 1264 1265 private void read_value_recursive(TypeCodeInputStream is) { 1266 if (is instanceof TypeCodeReader) { 1268 if (read_value_kind((TypeCodeReader)is)) 1269 read_value_body(is); 1270 } else { 1271 read_value_kind((InputStream )is); 1272 read_value_body(is); 1273 } 1274 } 1275 1276 boolean read_value_kind(TypeCodeReader tcis) 1277 { 1278 _kind = tcis.read_long(); 1279 1280 int myPosition = tcis.getTopLevelPosition()-4; 1282 1283 if ((_kind < 0 || _kind > typeTable.length) && _kind != tk_indirect) { 1285 throw wrapper.cannotMarshalBadTckind() ; 1286 } 1287 1288 if (_kind == TCKind._tk_native) 1290 throw wrapper.cannotMarshalNative() ; 1291 1292 TypeCodeReader topStream = tcis.getTopLevelStream(); 1295 1296 if (_kind == tk_indirect) { 1297 int streamOffset = tcis.read_long(); 1298 if (streamOffset > -4) 1299 throw wrapper.invalidIndirection( new Integer (streamOffset) ) ; 1300 1301 int topPos = tcis.getTopLevelPosition(); 1305 int indirectTypePosition = topPos - 4 + streamOffset; 1307 1308 TypeCodeImpl type = topStream.getTypeCodeAtPosition(indirectTypePosition); 1314 if (type == null) 1315 throw wrapper.indirectionNotFound( new Integer (indirectTypePosition) ) ; 1316 setIndirectType(type); 1317 return false; 1318 } 1319 1320 topStream.addTypeCodeAtPosition(this, myPosition); 1321 return true; 1322 } 1323 1324 void read_value_kind(InputStream is) { 1325 _kind = is.read_long(); 1327 1328 if ((_kind < 0 || _kind > typeTable.length) && _kind != tk_indirect) { 1330 throw wrapper.cannotMarshalBadTckind() ; 1331 } 1332 if (_kind == TCKind._tk_native) 1334 throw wrapper.cannotMarshalNative() ; 1335 1336 if (_kind == tk_indirect) { 1337 throw wrapper.recursiveTypecodeError() ; 1338 } 1339 } 1340 1341 void read_value_body(InputStream is) { 1342 1345 switch (typeTable[_kind]) { 1346 case EMPTY: 1347 break; 1349 1350 case SIMPLE: 1351 switch (_kind) { 1352 case TCKind._tk_string: 1353 case TCKind._tk_wstring: 1354 _length = is.read_long(); 1355 break; 1356 case TCKind._tk_fixed: 1357 _digits = is.read_ushort(); 1358 _scale = is.read_short(); 1359 break; 1360 default: 1361 throw wrapper.invalidSimpleTypecode() ; 1362 } 1363 break; 1364 1365 case COMPLEX: 1366 { 1367 TypeCodeInputStream _encap = TypeCodeInputStream.readEncapsulation(is, 1368 is.orb()); 1369 1370 switch(_kind) { 1371 1372 case TCKind._tk_objref: 1373 case TCKind._tk_abstract_interface: 1374 { 1375 setId(_encap.read_string()); 1377 _name = _encap.read_string(); 1379 } 1380 break; 1381 1382 case TCKind._tk_union: 1383 { 1384 setId(_encap.read_string()); 1386 1387 _name = _encap.read_string(); 1389 1390 _discriminator = new TypeCodeImpl((ORB)is.orb()); 1392 _discriminator.read_value_recursive(_encap); 1393 1394 _defaultIndex = _encap.read_long(); 1396 1397 _memberCount = _encap.read_long(); 1399 1400 _unionLabels = new AnyImpl[_memberCount]; 1402 _memberNames = new String [_memberCount]; 1403 _memberTypes = new TypeCodeImpl[_memberCount]; 1404 1405 for (int i=0; i < _memberCount; i++) { 1407 _unionLabels[i] = new AnyImpl((ORB)is.orb()); 1408 if (i == _defaultIndex) 1409 _unionLabels[i].insert_octet(_encap.read_octet()); 1411 else { 1412 switch (realType(_discriminator).kind().value()) { 1413 case TCKind._tk_short: 1414 _unionLabels[i].insert_short(_encap.read_short()); 1415 break; 1416 case TCKind._tk_long: 1417 _unionLabels[i].insert_long(_encap.read_long()); 1418 break; 1419 case TCKind._tk_ushort: 1420 _unionLabels[i].insert_ushort(_encap.read_short()); 1421 break; 1422 case TCKind._tk_ulong: 1423 _unionLabels[i].insert_ulong(_encap.read_long()); 1424 break; 1425 case TCKind._tk_float: 1426 _unionLabels[i].insert_float(_encap.read_float()); 1427 break; 1428 case TCKind._tk_double: 1429 _unionLabels[i].insert_double(_encap.read_double()); 1430 break; 1431 case TCKind._tk_boolean: 1432 _unionLabels[i].insert_boolean(_encap.read_boolean()); 1433 break; 1434 case TCKind._tk_char: 1435 _unionLabels[i].insert_char(_encap.read_char()); 1436 break; 1437 case TCKind._tk_enum: 1438 _unionLabels[i].type(_discriminator); 1439 _unionLabels[i].insert_long(_encap.read_long()); 1440 break; 1441 case TCKind._tk_longlong: 1442 _unionLabels[i].insert_longlong(_encap.read_longlong()); 1443 break; 1444 case TCKind._tk_ulonglong: 1445 _unionLabels[i].insert_ulonglong(_encap.read_longlong()); 1446 break; 1447 case TCKind._tk_wchar: 1452 _unionLabels[i].insert_wchar(_encap.read_wchar()); 1453 break; 1454 default: 1455 throw wrapper.invalidComplexTypecode() ; 1456 } 1457 } 1458 _memberNames[i] = _encap.read_string(); 1459 _memberTypes[i] = new TypeCodeImpl((ORB)is.orb()); 1460 _memberTypes[i].read_value_recursive(_encap); 1461 _memberTypes[i].setParent(this); 1462 } 1463 } 1464 break; 1465 1466 case TCKind._tk_enum: 1467 { 1468 setId(_encap.read_string()); 1470 1471 _name = _encap.read_string(); 1473 1474 _memberCount = _encap.read_long(); 1476 1477 _memberNames = new String [_memberCount]; 1479 1480 for (int i=0; i < _memberCount; i++) 1482 _memberNames[i] = _encap.read_string(); 1483 } 1484 break; 1485 1486 case TCKind._tk_sequence: 1487 { 1488 _contentType = new TypeCodeImpl((ORB)is.orb()); 1490 _contentType.read_value_recursive(_encap); 1491 1492 _length = _encap.read_long(); 1494 } 1495 break; 1496 1497 case TCKind._tk_array: 1498 { 1499 _contentType = new TypeCodeImpl((ORB)is.orb()); 1501 _contentType.read_value_recursive(_encap); 1502 1503 _length = _encap.read_long(); 1505 } 1506 break; 1507 1508 case TCKind._tk_alias: 1509 case TCKind._tk_value_box: 1510 { 1511 setId(_encap.read_string()); 1513 1514 _name = _encap.read_string(); 1516 1517 _contentType = new TypeCodeImpl((ORB)is.orb()); 1519 _contentType.read_value_recursive(_encap); 1520 } 1521 break; 1522 1523 case TCKind._tk_except: 1524 case TCKind._tk_struct: 1525 { 1526 setId(_encap.read_string()); 1528 1529 _name = _encap.read_string(); 1531 1532 _memberCount = _encap.read_long(); 1534 1535 _memberNames = new String [_memberCount]; 1537 _memberTypes = new TypeCodeImpl[_memberCount]; 1538 1539 for (int i=0; i < _memberCount; i++) { 1541 _memberNames[i] = _encap.read_string(); 1542 _memberTypes[i] = new TypeCodeImpl((ORB)is.orb()); 1543 _memberTypes[i].read_value_recursive(_encap); 1546 _memberTypes[i].setParent(this); 1547 } 1548 } 1549 break; 1550 1551 case TCKind._tk_value: 1552 { 1553 setId(_encap.read_string()); 1555 1556 _name = _encap.read_string(); 1558 1559 _type_modifier = _encap.read_short(); 1561 1562 _concrete_base = new TypeCodeImpl((ORB)is.orb()); 1564 _concrete_base.read_value_recursive(_encap); 1565 if (_concrete_base.kind().value() == TCKind._tk_null) { 1566 _concrete_base = null; 1567 } 1568 1569 _memberCount = _encap.read_long(); 1571 1572 _memberNames = new String [_memberCount]; 1574 _memberTypes = new TypeCodeImpl[_memberCount]; 1575 _memberAccess = new short[_memberCount]; 1576 1577 for (int i=0; i < _memberCount; i++) { 1579 _memberNames[i] = _encap.read_string(); 1580 _memberTypes[i] = new TypeCodeImpl((ORB)is.orb()); 1581 _memberTypes[i].read_value_recursive(_encap); 1584 _memberTypes[i].setParent(this); 1585 _memberAccess[i] = _encap.read_short(); 1586 } 1587 } 1588 break; 1589 1590 default: 1591 throw wrapper.invalidTypecodeKindMarshal() ; 1592 } 1593 break; 1594 } 1595 } 1596 } 1597 1598 public void write_value(OutputStream os) { 1599 if (os instanceof TypeCodeOutputStream) { 1602 this.write_value((TypeCodeOutputStream)os); 1603 } else { 1604 TypeCodeOutputStream wrapperOutStream = null; 1605 1606 if (outBuffer == null) { 1607 wrapperOutStream = TypeCodeOutputStream.wrapOutputStream(os); 1608 this.write_value(wrapperOutStream); 1609 if (cachingEnabled) { 1610 outBuffer = wrapperOutStream.getTypeCodeBuffer(); 1612 } 1616 } else { 1617 } 1620 if (cachingEnabled && outBuffer != null) { 1623 os.write_long(_kind); 1624 os.write_octet_array(outBuffer, 0, outBuffer.length); 1625 } else { 1626 wrapperOutStream.writeRawBuffer(os, _kind); 1628 } 1629 } 1630 } 1631 1632 public void write_value(TypeCodeOutputStream tcos) { 1633 1634 if (_kind == TCKind._tk_native) 1636 throw wrapper.cannotMarshalNative() ; 1637 1638 TypeCodeOutputStream topStream = tcos.getTopLevelStream(); 1639 1641 if (_kind == tk_indirect) { 1642 int pos = topStream.getPositionForID(_id); 1647 int topPos = tcos.getTopLevelPosition(); 1648 tcos.writeIndirection(tk_indirect, pos); 1652 return; 1654 } 1655 1656 1659 tcos.write_long(_kind); 1661 1662 topStream.addIDAtPosition(_id, tcos.getTopLevelPosition()-4); 1670 1671 switch (typeTable[_kind]) { 1672 case EMPTY: 1673 break; 1675 1676 case SIMPLE: 1677 switch (_kind) { 1678 case TCKind._tk_string: 1679 case TCKind._tk_wstring: 1680 tcos.write_long(_length); 1682 break; 1683 case TCKind._tk_fixed: 1684 tcos.write_ushort(_digits); 1685 tcos.write_short(_scale); 1686 break; 1687 default: 1688 throw wrapper.invalidSimpleTypecode() ; 1690 } 1691 break; 1692 1693 case COMPLEX: 1694 { 1695 TypeCodeOutputStream _encap = tcos.createEncapsulation(tcos.orb()); 1697 1698 switch(_kind) { 1699 1700 case TCKind._tk_objref: 1701 case TCKind._tk_abstract_interface: 1702 { 1703 _encap.write_string(_id); 1705 1706 _encap.write_string(_name); 1708 } 1709 break; 1710 1711 case TCKind._tk_union: 1712 { 1713 _encap.write_string(_id); 1715 1716 _encap.write_string(_name); 1718 1719 _discriminator.write_value(_encap); 1721 1722 _encap.write_long(_defaultIndex); 1724 1725 _encap.write_long(_memberCount); 1727 1728 for (int i=0; i < _memberCount; i++) { 1730 1731 if (i == _defaultIndex) 1733 _encap.write_octet(_unionLabels[i].extract_octet()); 1734 1735 else { 1736 switch (realType(_discriminator).kind().value()) { 1737 case TCKind._tk_short: 1738 _encap.write_short(_unionLabels[i].extract_short()); 1739 break; 1740 case TCKind._tk_long: 1741 _encap.write_long(_unionLabels[i].extract_long()); 1742 break; 1743 case TCKind._tk_ushort: 1744 _encap.write_short(_unionLabels[i].extract_ushort()); 1745 break; 1746 case TCKind._tk_ulong: 1747 _encap.write_long(_unionLabels[i].extract_ulong()); 1748 break; 1749 case TCKind._tk_float: 1750 _encap.write_float(_unionLabels[i].extract_float()); 1751 break; 1752 case TCKind._tk_double: 1753 _encap.write_double(_unionLabels[i].extract_double()); 1754 break; 1755 case TCKind._tk_boolean: 1756 _encap.write_boolean(_unionLabels[i].extract_boolean()); 1757 break; 1758 case TCKind._tk_char: 1759 _encap.write_char(_unionLabels[i].extract_char()); 1760 break; 1761 case TCKind._tk_enum: 1762 _encap.write_long(_unionLabels[i].extract_long()); 1763 break; 1764 case TCKind._tk_longlong: 1765 _encap.write_longlong(_unionLabels[i].extract_longlong()); 1766 break; 1767 case TCKind._tk_ulonglong: 1768 _encap.write_longlong(_unionLabels[i].extract_ulonglong()); 1769 break; 1770 case TCKind._tk_wchar: 1775 _encap.write_wchar(_unionLabels[i].extract_wchar()); 1776 break; 1777 default: 1778 throw wrapper.invalidComplexTypecode() ; 1779 } 1780 } 1781 _encap.write_string(_memberNames[i]); 1782 _memberTypes[i].write_value(_encap); 1783 } 1784 } 1785 break; 1786 1787 case TCKind._tk_enum: 1788 { 1789 _encap.write_string(_id); 1791 1792 _encap.write_string(_name); 1794 1795 _encap.write_long(_memberCount); 1797 1798 for (int i=0; i < _memberCount; i++) 1800 _encap.write_string(_memberNames[i]); 1801 } 1802 break; 1803 1804 case TCKind._tk_sequence: 1805 { 1806 lazy_content_type().write_value(_encap); 1808 1809 _encap.write_long(_length); 1811 } 1812 break; 1813 1814 case TCKind._tk_array: 1815 { 1816 _contentType.write_value(_encap); 1818 1819 _encap.write_long(_length); 1821 } 1822 break; 1823 1824 case TCKind._tk_alias: 1825 case TCKind._tk_value_box: 1826 { 1827 _encap.write_string(_id); 1829 1830 _encap.write_string(_name); 1832 1833 _contentType.write_value(_encap); 1835 } 1836 break; 1837 1838 case TCKind._tk_struct: 1839 case TCKind._tk_except: 1840 { 1841 _encap.write_string(_id); 1843 1844 _encap.write_string(_name); 1846 1847 _encap.write_long(_memberCount); 1849 1850 for (int i=0; i < _memberCount; i++) { 1852 _encap.write_string(_memberNames[i]); 1853 _memberTypes[i].write_value(_encap); 1856 } 1857 } 1858 break; 1859 1860 case TCKind._tk_value: 1861 { 1862 _encap.write_string(_id); 1864 1865 _encap.write_string(_name); 1867 1868 _encap.write_short(_type_modifier); 1870 1871 if (_concrete_base == null) { 1873 _orb.get_primitive_tc(TCKind._tk_null).write_value(_encap); 1874 } else { 1875 _concrete_base.write_value(_encap); 1876 } 1877 1878 _encap.write_long(_memberCount); 1880 1881 for (int i=0; i < _memberCount; i++) { 1883 _encap.write_string(_memberNames[i]); 1884 _memberTypes[i].write_value(_encap); 1887 _encap.write_short(_memberAccess[i]); 1888 } 1889 } 1890 break; 1891 1892 default: 1893 throw wrapper.invalidTypecodeKindMarshal() ; 1894 } 1895 1896 _encap.writeOctetSequenceTo(tcos); 1898 break; 1899 } 1900 } 1901 } 1902 1903 1910 protected void copy(org.omg.CORBA.portable.InputStream src, 1911 org.omg.CORBA.portable.OutputStream dst) 1912 { 1913 switch (_kind) { 1914 1915 case TCKind._tk_null: 1916 case TCKind._tk_void: 1917 case TCKind._tk_native: 1918 case TCKind._tk_abstract_interface: 1919 break; 1920 1921 case TCKind._tk_short: 1922 case TCKind._tk_ushort: 1923 dst.write_short(src.read_short()); 1924 break; 1925 1926 case TCKind._tk_long: 1927 case TCKind._tk_ulong: 1928 dst.write_long(src.read_long()); 1929 break; 1930 1931 case TCKind._tk_float: 1932 dst.write_float(src.read_float()); 1933 break; 1934 1935 case TCKind._tk_double: 1936 dst.write_double(src.read_double()); 1937 break; 1938 1939 case TCKind._tk_longlong: 1940 case TCKind._tk_ulonglong: 1941 dst.write_longlong(src.read_longlong()); 1942 break; 1943 1944 case TCKind._tk_longdouble: 1945 throw wrapper.tkLongDoubleNotSupported() ; 1946 1947 case TCKind._tk_boolean: 1948 dst.write_boolean(src.read_boolean()); 1949 break; 1950 1951 case TCKind._tk_char: 1952 dst.write_char(src.read_char()); 1953 break; 1954 1955 case TCKind._tk_wchar: 1956 dst.write_wchar(src.read_wchar()); 1957 break; 1958 1959 case TCKind._tk_octet: 1960 dst.write_octet(src.read_octet()); 1961 break; 1962 1963 case TCKind._tk_string: 1964 { 1965 String s; 1966 s = src.read_string(); 1967 if ((_length != 0) && (s.length() > _length)) 1969 throw wrapper.badStringBounds( new Integer (s.length()), 1970 new Integer (_length) ) ; 1971 dst.write_string(s); 1972 } 1973 break; 1974 1975 case TCKind._tk_wstring: 1976 { 1977 String s; 1978 s = src.read_wstring(); 1979 if ((_length != 0) && (s.length() > _length)) 1981 throw wrapper.badStringBounds( new Integer (s.length()), 1982 new Integer (_length) ) ; 1983 dst.write_wstring(s); 1984 } 1985 break; 1986 1987 case TCKind._tk_fixed: 1988 { 1989 dst.write_ushort(src.read_ushort()); 1990 dst.write_short(src.read_short()); 1991 } 1992 break; 1993 1994 case TCKind._tk_any: 1995 { 1996 Any tmp = ((CDRInputStream)src).orb().create_any(); 1998 TypeCodeImpl t = new TypeCodeImpl((ORB)dst.orb()); 1999 t.read_value((org.omg.CORBA_2_3.portable.InputStream )src); 2000 t.write_value((org.omg.CORBA_2_3.portable.OutputStream )dst); 2001 tmp.read_value(src, t); 2002 tmp.write_value(dst); 2003 break; 2004 } 2005 2006 case TCKind._tk_TypeCode: 2007 { 2008 dst.write_TypeCode(src.read_TypeCode()); 2009 break; 2010 } 2011 2012 case TCKind._tk_Principal: 2013 { 2014 dst.write_Principal(src.read_Principal()); 2015 break; 2016 } 2017 2018 case TCKind._tk_objref: 2019 { 2020 dst.write_Object(src.read_Object()); 2021 break; 2022 } 2023 2024 case TCKind._tk_except: 2025 dst.write_string(src.read_string()); 2027 2028 case TCKind._tk_value: 2031 case TCKind._tk_struct: 2032 { 2033 for (int i=0; i < _memberTypes.length; i++) { 2035 _memberTypes[i].copy(src, dst); 2036 } 2037 break; 2038 } 2039 case TCKind._tk_union: 2040 2059 { 2060 Any tagValue = new AnyImpl( (ORB)src.orb()); 2061 2062 switch (realType(_discriminator).kind().value()) { 2063 case TCKind._tk_short: 2064 { 2065 short value = src.read_short(); 2066 tagValue.insert_short(value); 2067 dst.write_short(value); 2068 break; 2069 } 2070 case TCKind._tk_long: 2071 { 2072 int value = src.read_long(); 2073 tagValue.insert_long(value); 2074 dst.write_long(value); 2075 break; 2076 } 2077 case TCKind._tk_ushort: 2078 { 2079 short value = src.read_short(); 2080 tagValue.insert_ushort(value); 2081 dst.write_short(value); 2082 break; 2083 } 2084 case TCKind._tk_ulong: 2085 { 2086 int value = src.read_long(); 2087 tagValue.insert_ulong(value); 2088 dst.write_long(value); 2089 break; 2090 } 2091 case TCKind._tk_float: 2092 { 2093 float value = src.read_float(); 2094 tagValue.insert_float(value); 2095 dst.write_float(value); 2096 break; 2097 } 2098 case TCKind._tk_double: 2099 { 2100 double value = src.read_double(); 2101 tagValue.insert_double(value); 2102 dst.write_double(value); 2103 break; 2104 } 2105 case TCKind._tk_boolean: 2106 { 2107 boolean value = src.read_boolean(); 2108 tagValue.insert_boolean(value); 2109 dst.write_boolean(value); 2110 break; 2111 } 2112 case TCKind._tk_char: 2113 { 2114 char value = src.read_char(); 2115 tagValue.insert_char(value); 2116 dst.write_char(value); 2117 break; 2118 } 2119 case TCKind._tk_enum: 2120 { 2121 int value = src.read_long(); 2122 tagValue.type(_discriminator); 2123 tagValue.insert_long(value); 2124 dst.write_long(value); 2125 break; 2126 } 2127 case TCKind._tk_longlong: 2128 { 2129 long value = src.read_longlong(); 2130 tagValue.insert_longlong(value); 2131 dst.write_longlong(value); 2132 break; 2133 } 2134 case TCKind._tk_ulonglong: 2135 { 2136 long value = src.read_longlong(); 2137 tagValue.insert_ulonglong(value); 2138 dst.write_longlong(value); 2139 break; 2140 } 2141 case TCKind._tk_wchar: 2150 { 2151 char value = src.read_wchar(); 2152 tagValue.insert_wchar(value); 2153 dst.write_wchar(value); 2154 break; 2155 } 2156 default: 2157 throw wrapper.illegalUnionDiscriminatorType() ; 2158 } 2159 2160 2163 int labelIndex; 2164 for (labelIndex = 0; labelIndex < _unionLabels.length; labelIndex++) { 2165 if (tagValue.equal(_unionLabels[labelIndex])) { 2167 _memberTypes[labelIndex].copy(src, dst); 2168 break; 2169 } 2170 } 2171 2172 if (labelIndex == _unionLabels.length) { 2173 if (_defaultIndex == -1) 2175 throw wrapper.unexpectedUnionDefault() ; 2177 else 2178 _memberTypes[_defaultIndex].copy(src, dst); 2180 } 2181 break; 2182 } 2183 2184 case TCKind._tk_enum: 2185 dst.write_long(src.read_long()); 2186 break; 2187 2188 case TCKind._tk_sequence: 2189 int seqLength = src.read_long(); 2191 2192 if ((_length != 0) && (seqLength > _length)) 2194 throw wrapper.badSequenceBounds( new Integer (seqLength), 2195 new Integer (_length) ) ; 2196 2197 dst.write_long(seqLength); 2199 2200 lazy_content_type(); for (int i=0; i < seqLength; i++) 2203 _contentType.copy(src, dst); 2204 break; 2205 2206 case TCKind._tk_array: 2207 for (int i=0; i < _length; i++) 2209 _contentType.copy(src, dst); 2210 break; 2211 2212 case TCKind._tk_alias: 2213 case TCKind._tk_value_box: 2214 _contentType.copy(src, dst); 2216 break; 2217 2218 case tk_indirect: 2219 indirectType().copy(src, dst); 2224 break; 2225 2226 default: 2227 throw wrapper.invalidTypecodeKindMarshal() ; 2228 } 2229 } 2230 2231 2232 static protected short digits(java.math.BigDecimal value) { 2233 if (value == null) 2234 return 0; 2235 short length = (short)value.unscaledValue().toString().length(); 2236 if (value.signum() == -1) 2237 length--; 2238 return length; 2239 } 2240 2241 static protected short scale(java.math.BigDecimal value) { 2242 if (value == null) 2243 return 0; 2244 return (short)value.scale(); 2245 } 2246 2247 2249 int currentUnionMemberIndex(Any discriminatorValue) throws BadKind { 2253 if (_kind != TCKind._tk_union) 2254 throw new BadKind (); 2255 2256 try { 2257 for (int i=0; i<member_count(); i++) { 2258 if (member_label(i).equal(discriminatorValue)) { 2259 return i; 2260 } 2261 } 2262 if (_defaultIndex != -1) { 2263 return _defaultIndex; 2264 } 2265 } catch (BadKind bad) { 2266 } catch (org.omg.CORBA.TypeCodePackage.Bounds bounds) { 2267 } 2268 return -1; 2269 } 2270 2271 public String description() { 2272 return "TypeCodeImpl with kind " + _kind + " and id " + _id; 2273 } 2274 2275 public String toString() { 2276 ByteArrayOutputStream byteOut = new ByteArrayOutputStream (1024); 2277 PrintStream printOut = new PrintStream (byteOut, true); 2278 printStream(printOut); 2279 return super.toString() + " =\n" + byteOut.toString(); 2280 } 2281 2282 public void printStream(PrintStream s) { 2283 printStream(s, 0); 2284 } 2285 2286 private void printStream(PrintStream s, int level) { 2287 if (_kind == tk_indirect) { 2288 s.print("indirect " + _id); 2289 return; 2290 } 2291 2292 switch (_kind) { 2293 case TCKind._tk_null: 2294 case TCKind._tk_void: 2295 case TCKind._tk_short: 2296 case TCKind._tk_long: 2297 case TCKind._tk_ushort: 2298 case TCKind._tk_ulong: 2299 case TCKind._tk_float: 2300 case TCKind._tk_double: 2301 case TCKind._tk_boolean: 2302 case TCKind._tk_char: 2303 case TCKind._tk_octet: 2304 case TCKind._tk_any: 2305 case TCKind._tk_TypeCode: 2306 case TCKind._tk_Principal: 2307 case TCKind._tk_objref: 2308 case TCKind._tk_longlong: 2309 case TCKind._tk_ulonglong: 2310 case TCKind._tk_longdouble: 2311 case TCKind._tk_wchar: 2312 case TCKind._tk_native: 2313 s.print(kindNames[_kind] + " " + _name); 2314 break; 2315 2316 case TCKind._tk_struct: 2317 case TCKind._tk_except: 2318 case TCKind._tk_value: 2319 s.println(kindNames[_kind] + " " + _name + " = {"); 2320 for(int i=0; i<_memberCount; i++) { 2321 s.print(indent(level + 1)); 2323 if (_memberTypes[i] != null) 2324 _memberTypes[i].printStream(s, level + 1); 2325 else 2326 s.print("<unknown type>"); 2327 s.println(" " + _memberNames[i] + ";"); 2328 } 2329 s.print(indent(level) + "}"); 2330 break; 2331 2332 case TCKind._tk_union: 2333 s.print("union " + _name + "..."); 2334 break; 2335 2336 case TCKind._tk_enum: 2337 s.print("enum " + _name + "..."); 2338 break; 2339 2340 case TCKind._tk_string: 2341 if (_length == 0) 2342 s.print("unbounded string " + _name); 2343 else 2344 s.print("bounded string(" + _length + ") " + _name); 2345 break; 2346 2347 case TCKind._tk_sequence: 2348 case TCKind._tk_array: 2349 s.println(kindNames[_kind] + "[" + _length + "] " + _name + " = {"); 2350 s.print(indent(level + 1)); 2351 if (lazy_content_type() != null) { 2352 lazy_content_type().printStream(s, level + 1); 2353 } 2354 s.println(indent(level) + "}"); 2355 break; 2356 2357 case TCKind._tk_alias: 2358 s.print("alias " + _name + " = " + 2359 (_contentType != null ? _contentType._name : "<unresolved>")); 2360 break; 2361 2362 case TCKind._tk_wstring: 2363 s.print("wstring[" + _length + "] " + _name); 2364 break; 2365 2366 case TCKind._tk_fixed: 2367 s.print("fixed(" + _digits + ", " + _scale + ") " + _name); 2368 break; 2369 2370 case TCKind._tk_value_box: 2371 s.print("valueBox " + _name + "..."); 2372 break; 2373 2374 case TCKind._tk_abstract_interface: 2375 s.print("abstractInterface " + _name + "..."); 2376 break; 2377 2378 default: 2379 s.print("<unknown type>"); 2380 break; 2381 } 2382 } 2383 2384 private String indent(int level) { 2385 String indent = ""; 2386 for(int i=0; i<level; i++) { 2387 indent += " "; 2388 } 2389 return indent; 2390 } 2391 2392 protected void setCaching(boolean enableCaching) { 2393 cachingEnabled = enableCaching; 2394 if (enableCaching == false) 2395 outBuffer = null; 2396 } 2397} 2398 | Popular Tags |