1 19 package gcc.rmi.iiop; 20 21 import org.omg.CORBA.TCKind; 22 import org.omg.CORBA.TypeCodePackage.BadKind; 23 import org.omg.CORBA.TypeCodePackage.Bounds; 24 25 28 public class TypeCode extends org.omg.CORBA.TypeCode 29 { 30 34 public static final TypeCode NULL = new TypeCode(TCKind.tk_null); 35 public static final TypeCode VOID = new TypeCode(TCKind.tk_void); 36 public static final TypeCode ANY = new TypeCode(TCKind.tk_any); 37 public static final TypeCode BOOLEAN = new TypeCode(TCKind.tk_boolean); 38 public static final TypeCode CHAR = new TypeCode(TCKind.tk_char); 39 public static final TypeCode WCHAR = new TypeCode(TCKind.tk_wchar); 40 public static final TypeCode OCTET = new TypeCode(TCKind.tk_octet); 41 public static final TypeCode SHORT = new TypeCode(TCKind.tk_short); 42 public static final TypeCode USHORT = new TypeCode(TCKind.tk_ushort); 43 public static final TypeCode LONG = new TypeCode(TCKind.tk_long); 44 public static final TypeCode ULONG = new TypeCode(TCKind.tk_ulong); 45 public static final TypeCode LONGLONG = new TypeCode(TCKind.tk_longlong); 46 public static final TypeCode ULONGLONG = new TypeCode(TCKind.tk_ulonglong); 47 public static final TypeCode FLOAT = new TypeCode(TCKind.tk_float); 48 public static final TypeCode DOUBLE = new TypeCode(TCKind.tk_double); 49 public static final TypeCode LONGDOUBLE = new TypeCode(TCKind.tk_longdouble); 50 public static final TypeCode STRING = new TypeCode(TCKind.tk_string); 51 public static final TypeCode WSTRING = new TypeCode(TCKind.tk_wstring); 52 public static final TypeCode OBJREF = new TypeCode(TCKind.tk_objref); 53 public static final TypeCode TYPECODE = new TypeCode(TCKind.tk_TypeCode); 54 55 59 private TCKind _kind; 60 61 private String _name; 62 63 private String _type; 64 65 private String _id; 66 67 private String _label; 68 69 private org.omg.CORBA.TypeCode _ref; 72 73 private String[] _member_name; 74 75 private org.omg.CORBA.TypeCode[] _member_type; 76 77 private org.omg.CORBA.Any[] _member_label; 78 79 private short[] _member_visibility; 80 81 private int _default; 82 83 private int _length; 84 85 private short _digits; 86 87 private short _scale; 88 89 private short _type_modifier; 90 91 private boolean _indirection; 92 93 100 public TypeCode(TCKind kind) 101 { 102 _kind = kind; 103 _default = -1; 104 if (kind.value() == TCKind._tk_objref) 105 { 106 _type = "Object"; 107 } 108 } 109 110 115 public boolean equal(org.omg.CORBA.TypeCode tc) 116 { 117 if (_indirection) 118 { 119 return _ref.equal(tc); 120 } 121 try 122 { 123 int tk = _kind.value(); 124 if (tk != tc.kind().value()) 125 { 126 return false; 127 } 128 if (_member_name != null) 130 { 131 int n = _member_name.length; 132 if (n != tc.member_count()) 133 { 134 return false; 135 } 136 for (int i = 0; i < n; i++) 137 { 138 if (! equalIfNotEmpty(member_name(i), tc.member_name(i))) 139 { 140 return false; 141 } 142 if (! member_type(i).equal(tc.member_type(i))) 143 { 144 return false; 145 } 146 } 147 } 148 if (tk == TCKind._tk_union) 149 { 150 if (! discriminator_type().equal(tc.discriminator_type())) 151 { 152 return false; 153 } 154 int n = _member_name.length; 155 for (int i = 0; i < n; i++) 156 { 157 if (! member_label(i).equal(tc.member_label(i))) 158 { 159 return false; 160 } 161 } 162 } 163 if (tk == TCKind._tk_array 164 || tk == TCKind._tk_sequence 165 || tk == TCKind._tk_string 166 || tk == TCKind._tk_wstring) 167 { 168 if (length() != tc.length()) 169 { 170 return false; 171 } 172 } 173 if (tk == TCKind._tk_alias 174 || tk == TCKind._tk_array 175 || tk == TCKind._tk_sequence) 176 { 177 if (! content_type().equal(tc.content_type())) 178 { 179 return false; 180 } 181 } 182 return true; 183 } 184 catch (org.omg.CORBA.TypeCodePackage.BadKind ex) 185 { 186 throw new org.omg.CORBA.UNKNOWN(ex.toString()); 187 } 188 catch (org.omg.CORBA.TypeCodePackage.Bounds ex) 189 { 190 throw new org.omg.CORBA.UNKNOWN(ex.toString()); 191 } 192 } 193 194 199 public boolean equivalent 200 (org.omg.CORBA.TypeCode tc) 201 { 202 throw new org.omg.CORBA.NO_IMPLEMENT(); 203 } 204 205 209 public org.omg.CORBA.TypeCode get_compact_typecode() 210 { 211 throw new org.omg.CORBA.NO_IMPLEMENT(); 212 } 213 214 220 private boolean equalIfNotEmpty(String a, String b) 221 { 222 if (a.length() == 0 || b.length() == 0) 223 { 224 return true; 225 } 226 else 227 { 228 return a.equals(b); 229 } 230 } 231 232 236 public TCKind kind() 237 { 238 if (_indirection) 239 { 240 return _ref.kind(); 241 } 242 return _kind; 243 } 244 245 250 public String id() 251 throws BadKind 252 { 253 if (_indirection) 254 { 255 return _ref.id(); 256 } 257 if (_id != null) 258 { 259 return _id; 260 } 261 if (_type != null && _type.equals("Object")) 262 { 263 return ""; 264 } 265 return default_id(); 266 } 267 268 273 public void id(String id) 274 { 275 if (! id.equals("")) 276 { 277 _id = id; 278 if (id.startsWith("IDL:") && id.endsWith(":1.0")) 279 { 280 id = id.substring(4, id.length() - 4); 282 if (id.startsWith("omg.org/")) 283 { 284 id = id.substring(8); 285 } 286 _type = ""; 287 for (;;) 288 { 289 int slash = id.indexOf('/'); 290 if (slash == -1) 291 { 292 break; 293 } 294 _type = _type + id.substring(0, slash) + "::"; 295 id = id.substring(slash + 1); 296 } 297 _type = _type + id; 298 } 299 } 300 } 301 302 307 public String name() 308 throws BadKind 309 { 310 if (_indirection) 311 { 312 return _ref.name(); 313 } 314 320 if (_name == null) 321 { 322 throw new BadKind(); 323 } 324 return _name; 325 } 326 327 332 public void name(String name) 333 { 334 _name = name; 335 } 336 337 342 public int member_count() 343 throws BadKind 344 { 345 if (_indirection) 346 { 347 return _ref.member_count(); 348 } 349 if (_member_name == null) 350 { 351 throw new BadKind(); 352 } 353 return _member_name.length; 354 } 355 356 361 public void member_count(int count) 362 { 363 _member_name = new String[count]; 364 _member_type = new org.omg.CORBA.TypeCode[count]; 365 if (_kind.value() == TCKind._tk_union) 366 { 367 _member_label = new org.omg.CORBA.Any[count]; 368 } 369 if (_kind.value() == TCKind._tk_value) 370 { 371 _member_visibility = new short[count]; 372 } 373 } 374 375 382 public String member_name(int index) 383 throws BadKind, Bounds 384 { 385 if (_indirection) 386 { 387 return _ref.member_name(index); 388 } 389 if (_member_name == null) 390 { 391 throw new BadKind(); 392 } 393 if (index < 0 || index >= _member_name.length) 394 { 395 throw new Bounds(); 396 } 397 return _member_name[index]; 398 } 399 400 406 public void member_name(int index, String name) 407 { 408 _member_name[index] = name; 409 } 410 411 418 public org.omg.CORBA.TypeCode member_type(int index) 419 throws BadKind, Bounds 420 { 421 if (_indirection) 422 { 423 return _ref.member_type(index); 424 } 425 if (_member_type == null) 426 { 427 throw new BadKind(); 428 } 429 if (index < 0 || index >= _member_type.length) 430 { 431 throw new Bounds(); 432 } 433 return _member_type[index]; 434 } 435 436 442 public void member_type(int index, org.omg.CORBA.TypeCode type) 443 { 444 _member_type[index] = type; 445 } 446 447 454 public org.omg.CORBA.Any member_label(int index) 455 throws BadKind, Bounds 456 { 457 if (_indirection) 458 { 459 return _ref.member_label(index); 460 } 461 if (_member_label == null) 462 { 463 throw new BadKind(); 464 } 465 if (index < 0 || index >= _member_label.length) 466 { 467 throw new Bounds(); 468 } 469 return _member_label[index]; 470 } 471 472 478 public void member_label(int index, org.omg.CORBA.Any label) 479 { 480 _member_label[index] = label; 481 } 482 483 488 public org.omg.CORBA.TypeCode discriminator_type() 489 throws BadKind 490 { 491 if (_indirection) 492 { 493 return _ref.discriminator_type(); 494 } 495 if (_ref == null 496 || _kind.value() != TCKind._tk_union) 497 { 498 throw new BadKind(); 499 } 500 return _ref; 501 } 502 503 508 public void discriminator_type(org.omg.CORBA.TypeCode disc) 509 { 510 _ref = disc; 511 } 512 513 518 public int default_index() 519 throws BadKind 520 { 521 if (_indirection) 522 { 523 return _ref.default_index(); 524 } 525 if (_kind.value() != TCKind._tk_union) 526 { 527 throw new BadKind(); 528 } 529 return _default; 530 } 531 532 537 public void default_index(int index) 538 { 539 _default = index; 540 if (index != -1) 541 { 542 _member_label[index] = new Any(_ref, "0"); 545 } 546 } 547 548 553 public int length() 554 throws BadKind 555 { 556 if (_indirection) 557 { 558 return _ref.length(); 559 } 560 int tk = _kind.value(); 561 if (tk != TCKind._tk_string && tk != TCKind._tk_wstring 562 && tk != TCKind._tk_sequence && tk != TCKind._tk_array) 563 { 564 throw new BadKind(); 565 } 566 return _length; 567 } 568 569 574 public void length(int length) 575 { 576 _length = length; 577 } 578 579 584 public org.omg.CORBA.TypeCode content_type() 585 throws BadKind 586 { 587 if (_indirection) 588 { 589 return _ref.content_type(); 590 } 591 int tk = _kind.value(); 592 if (_ref == null 593 || (tk != TCKind._tk_alias 594 && tk != TCKind._tk_array 595 && tk != TCKind._tk_sequence 596 && tk != TCKind._tk_value_box)) 597 { 598 throw new BadKind(); 599 } 600 return _ref; 601 } 602 603 608 public void content_type(org.omg.CORBA.TypeCode type) 609 { 610 _ref = type; 611 } 612 613 618 public short fixed_digits() 619 throws BadKind 620 { 621 if (_indirection) 622 { 623 return _ref.fixed_digits(); 624 } 625 int tk = _kind.value(); 626 if (tk != TCKind._tk_fixed) 627 { 628 throw new BadKind(); 629 } 630 return _digits; 631 } 632 633 638 public void fixed_digits(short digits) 639 { 640 _digits = digits; 641 } 642 643 648 public short fixed_scale() 649 throws BadKind 650 { 651 if (_indirection) 652 { 653 return _ref.fixed_scale(); 654 } 655 int tk = _kind.value(); 656 if (tk != TCKind._tk_fixed) 657 { 658 throw new BadKind(); 659 } 660 return _scale; 661 } 662 663 668 public void fixed_scale(short scale) 669 { 670 _scale = scale; 671 } 672 673 680 public short member_visibility 681 (int index) 682 throws BadKind, Bounds 683 { 684 if (_indirection) 685 { 686 return _ref.member_visibility(index); 687 } 688 if (_member_type == null) 689 { 690 throw new BadKind(); 691 } 692 if (index < 0 || index >= _member_visibility.length) 693 { 694 throw new Bounds(); 695 } 696 return _member_visibility[index]; 697 } 698 699 705 public void member_visibility(int index, short visibility) 706 { 707 _member_visibility[index] = visibility; 708 } 709 710 715 public short type_modifier() 716 throws BadKind 717 { 718 if (_indirection) 719 { 720 return _ref.type_modifier(); 721 } 722 int tk = _kind.value(); 723 if (tk != TCKind._tk_value) 724 { 725 throw new BadKind(); 726 } 727 return _type_modifier; 728 } 729 730 735 public void type_modifier(short modifier) 736 { 737 _type_modifier = modifier; 738 } 739 740 745 public org.omg.CORBA.TypeCode concrete_base_type() 746 throws BadKind 747 { 748 if (_indirection) 749 { 750 return _ref.concrete_base_type(); 751 } 752 int tk = _kind.value(); 753 if (tk != TCKind._tk_value) 754 { 755 throw new BadKind(); 756 } 757 return _ref; 758 } 759 760 765 public void concrete_base_type(org.omg.CORBA.TypeCode base) 766 { 767 _ref = base; 768 } 769 770 775 public void indirection(org.omg.CORBA.TypeCode ref) 776 { 777 _ref = ref; 778 _indirection = true; 779 } 780 781 786 public void recursive(String id) 787 { 788 _id = id; 789 _ref = null; 790 _indirection = true; 791 } 792 793 797 public void fix_recursive_members() 798 { 799 String id = _id == null ? default_id() : _id; 800 int n = _member_type.length; 801 for (int i = 0; i < n; i++) 802 { 803 TypeCode mt = (TypeCode)_member_type[i]; 804 if (mt._kind.value() == TCKind._tk_sequence) 805 { 806 TypeCode ct = (TypeCode)mt._ref; 807 if (ct._indirection 808 && ct._ref == null 809 && ct._id.equals(id)) 810 { 811 ct._ref = this; 812 } 813 } 814 } 815 } 816 817 824 private String default_id() 825 { 826 if (_type == null) 830 { 831 return ""; 832 } 833 StringBuffer id = new StringBuffer(_type.length() + 10); 834 id.append("IDL:"); 835 int n = _type.length(); 836 for (int i = 0; i < n; i++) 837 { 838 char c = _type.charAt(i); 839 if (c == ':' && i + 1 < n && _type.charAt(i + 1) == ':') 840 { 841 i++; 842 } 843 id.append(c == ':' ? '/' : c); 844 } 845 id.append(":1.0"); 846 return id.toString(); 847 } 848 } 849 | Popular Tags |