1 18 package org.apache.geronimo.interop.rmi.iiop; 19 20 import org.omg.CORBA.TCKind ; 21 import org.omg.CORBA.TypeCodePackage.BadKind ; 22 import org.omg.CORBA.TypeCodePackage.Bounds ; 23 24 27 public class TypeCode 28 extends org.omg.CORBA.TypeCode 29 { 30 34 public static final TypeCode NULL = new TypeCode(TCKind.tk_null); 35 36 public static final TypeCode VOID = new TypeCode(TCKind.tk_void); 37 38 public static final TypeCode ANY = new TypeCode(TCKind.tk_any); 39 40 public static final TypeCode BOOLEAN = new TypeCode(TCKind.tk_boolean); 41 42 public static final TypeCode CHAR = new TypeCode(TCKind.tk_char); 43 44 public static final TypeCode WCHAR = new TypeCode(TCKind.tk_wchar); 45 46 public static final TypeCode OCTET = new TypeCode(TCKind.tk_octet); 47 48 public static final TypeCode SHORT = new TypeCode(TCKind.tk_short); 49 50 public static final TypeCode USHORT = new TypeCode(TCKind.tk_ushort); 51 52 public static final TypeCode LONG = new TypeCode(TCKind.tk_long); 53 54 public static final TypeCode ULONG = new TypeCode(TCKind.tk_ulong); 55 56 public static final TypeCode LONGLONG = new TypeCode(TCKind.tk_longlong); 57 58 public static final TypeCode ULONGLONG = new TypeCode(TCKind.tk_ulonglong); 59 60 public static final TypeCode FLOAT = new TypeCode(TCKind.tk_float); 61 62 public static final TypeCode DOUBLE = new TypeCode(TCKind.tk_double); 63 64 public static final TypeCode LONGDOUBLE = new TypeCode( 65 TCKind.tk_longdouble); 66 67 public static final TypeCode STRING = new TypeCode(TCKind.tk_string); 68 69 public static final TypeCode WSTRING = new TypeCode(TCKind.tk_wstring); 70 71 public static final TypeCode OBJREF = new TypeCode(TCKind.tk_objref); 72 73 public static final TypeCode TYPECODE = new TypeCode(TCKind.tk_TypeCode); 74 75 79 private TCKind _kind; 80 81 private String _name; 82 83 private String _type; 84 85 private String _id; 86 87 private String _label; 88 89 private org.omg.CORBA.TypeCode _ref; 92 93 private String [] _member_name; 94 95 private org.omg.CORBA.TypeCode [] _member_type; 96 97 private org.omg.CORBA.Any [] _member_label; 98 99 private short[] _member_visibility; 100 101 private int _default; 102 103 private int _length; 104 105 private short _digits; 106 107 private short _scale; 108 109 private short _type_modifier; 110 111 private boolean _indirection; 112 113 119 public TypeCode(TCKind kind) 120 { 121 _kind = kind; 122 _default = -1; 123 if (kind.value() == TCKind._tk_objref) 124 { 125 _type = "Object"; 126 } 127 } 128 129 133 public boolean equal(org.omg.CORBA.TypeCode tc) 134 { 135 if (_indirection) 136 { 137 return _ref.equal(tc); 138 } 139 try 140 { 141 int tk = _kind.value(); 142 if (tk != tc.kind().value()) 143 { 144 return false; 145 } 146 if (_member_name != null) 148 { 149 int n = _member_name.length; 150 if (n != tc.member_count()) 151 { 152 return false; 153 } 154 for (int i = 0; i < n; i++) 155 { 156 if (!equalIfNotEmpty(member_name(i), tc.member_name(i))) 157 { 158 return false; 159 } 160 if (!member_type(i).equal(tc.member_type(i))) 161 { 162 return false; 163 } 164 } 165 } 166 if (tk == TCKind._tk_union) 167 { 168 if (!discriminator_type().equal(tc.discriminator_type())) 169 { 170 return false; 171 } 172 int n = _member_name.length; 173 for (int i = 0; i < n; i++) 174 { 175 if (!member_label(i).equal(tc.member_label(i))) 176 { 177 return false; 178 } 179 } 180 } 181 if (tk == TCKind._tk_array 182 || 183 tk == TCKind._tk_sequence 184 || 185 tk == TCKind._tk_string 186 || tk == TCKind._tk_wstring) 187 { 188 if (length() != tc.length()) 189 { 190 return false; 191 } 192 } 193 if (tk == TCKind._tk_alias 194 || 195 tk == TCKind._tk_array 196 || tk == TCKind._tk_sequence) 197 { 198 if (!content_type().equal(tc.content_type())) 199 { 200 return false; 201 } 202 } 203 return true; 204 } 205 catch (org.omg.CORBA.TypeCodePackage.BadKind ex) 206 { 207 throw new org.omg.CORBA.UNKNOWN (ex.toString()); 208 } 209 catch (org.omg.CORBA.TypeCodePackage.Bounds ex) 210 { 211 throw new org.omg.CORBA.UNKNOWN (ex.toString()); 212 } 213 } 214 215 219 public boolean equivalent 220 (org.omg.CORBA.TypeCode tc) 221 { 222 throw new org.omg.CORBA.NO_IMPLEMENT (); 223 } 224 225 228 public org.omg.CORBA.TypeCode get_compact_typecode() 229 { 230 throw new org.omg.CORBA.NO_IMPLEMENT (); 231 } 232 233 238 private boolean equalIfNotEmpty(String a, String b) 239 { 240 if (a.length() == 0 || b.length() == 0) 241 { 242 return true; 243 } 244 else 245 { 246 return a.equals(b); 247 } 248 } 249 250 253 public TCKind kind() 254 { 255 if (_indirection) 256 { 257 return _ref.kind(); 258 } 259 return _kind; 260 } 261 262 266 public String id() 267 throws BadKind 268 { 269 if (_indirection) 270 { 271 return _ref.id(); 272 } 273 if (_id != null) 274 { 275 return _id; 276 } 277 if (_type != null && _type.equals("Object")) 278 { 279 return ""; 280 } 281 return default_id(); 282 } 283 284 287 public void id(String id) 288 { 289 if (!id.equals("")) 290 { 291 _id = id; 292 if (id.startsWith("IDL:") && id.endsWith(":1.0")) 293 { 294 id = id.substring(4, id.length() - 4); 296 if (id.startsWith("omg.org/")) 297 { 298 id = id.substring(8); 299 } 300 _type = ""; 301 for (; ;) 302 { 303 int slash = id.indexOf('/'); 304 if (slash == -1) 305 { 306 break; 307 } 308 _type = _type + id.substring(0, slash) + "::"; 309 id = id.substring(slash + 1); 310 } 311 _type = _type + id; 312 } 313 } 314 } 315 316 320 public String name() 321 throws BadKind 322 { 323 if (_indirection) 324 { 325 return _ref.name(); 326 } 327 333 if (_name == null) 334 { 335 throw new BadKind (); 336 } 337 return _name; 338 } 339 340 343 public void name(String name) 344 { 345 _name = name; 346 } 347 348 352 public int member_count() 353 throws BadKind 354 { 355 if (_indirection) 356 { 357 return _ref.member_count(); 358 } 359 if (_member_name == null) 360 { 361 throw new BadKind (); 362 } 363 return _member_name.length; 364 } 365 366 369 public void member_count(int count) 370 { 371 _member_name = new String [count]; 372 _member_type = new org.omg.CORBA.TypeCode [count]; 373 if (_kind.value() == TCKind._tk_union) 374 { 375 _member_label = new org.omg.CORBA.Any [count]; 376 } 377 if (_kind.value() == TCKind._tk_value) 378 { 379 _member_visibility = new short[count]; 380 } 381 } 382 383 389 public String member_name(int index) 390 throws BadKind , Bounds 391 { 392 if (_indirection) 393 { 394 return _ref.member_name(index); 395 } 396 if (_member_name == null) 397 { 398 throw new BadKind (); 399 } 400 if (index < 0 || index >= _member_name.length) 401 { 402 throw new Bounds (); 403 } 404 return _member_name[index]; 405 } 406 407 411 public void member_name(int index, String name) 412 { 413 _member_name[index] = name; 414 } 415 416 422 public org.omg.CORBA.TypeCode member_type(int index) 423 throws BadKind , Bounds 424 { 425 if (_indirection) 426 { 427 return _ref.member_type(index); 428 } 429 if (_member_type == null) 430 { 431 throw new BadKind (); 432 } 433 if (index < 0 || index >= _member_type.length) 434 { 435 throw new Bounds (); 436 } 437 return _member_type[index]; 438 } 439 440 444 public void member_type(int index, org.omg.CORBA.TypeCode type) 445 { 446 _member_type[index] = type; 447 } 448 449 455 public org.omg.CORBA.Any member_label(int index) 456 throws BadKind , Bounds 457 { 458 if (_indirection) 459 { 460 return _ref.member_label(index); 461 } 462 if (_member_label == null) 463 { 464 throw new BadKind (); 465 } 466 if (index < 0 || index >= _member_label.length) 467 { 468 throw new Bounds (); 469 } 470 return _member_label[index]; 471 } 472 473 477 public void member_label(int index, org.omg.CORBA.Any label) 478 { 479 _member_label[index] = label; 480 } 481 482 486 public org.omg.CORBA.TypeCode discriminator_type() 487 throws BadKind 488 { 489 if (_indirection) 490 { 491 return _ref.discriminator_type(); 492 } 493 if (_ref == null 494 || _kind.value() != TCKind._tk_union) 495 { 496 throw new BadKind (); 497 } 498 return _ref; 499 } 500 501 504 public void discriminator_type(org.omg.CORBA.TypeCode disc) 505 { 506 _ref = disc; 507 } 508 509 513 public int default_index() 514 throws BadKind 515 { 516 if (_indirection) 517 { 518 return _ref.default_index(); 519 } 520 if (_kind.value() != TCKind._tk_union) 521 { 522 throw new BadKind (); 523 } 524 return _default; 525 } 526 527 530 public void default_index(int index) 531 { 532 _default = index; 533 if (index != -1) 534 { 535 _member_label[index] = new Any(_ref, "0"); 538 } 539 } 540 541 545 public int length() 546 throws BadKind 547 { 548 if (_indirection) 549 { 550 return _ref.length(); 551 } 552 int tk = _kind.value(); 553 if (tk != TCKind._tk_string && 554 tk != TCKind._tk_wstring 555 && tk != TCKind._tk_sequence && tk != TCKind._tk_array) 556 { 557 throw new BadKind (); 558 } 559 return _length; 560 } 561 562 565 public void length(int length) 566 { 567 _length = length; 568 } 569 570 574 public org.omg.CORBA.TypeCode content_type() 575 throws BadKind 576 { 577 if (_indirection) 578 { 579 return _ref.content_type(); 580 } 581 int tk = _kind.value(); 582 if (_ref == null 583 || (tk != TCKind._tk_alias 584 && 585 tk != TCKind._tk_array 586 && 587 tk != TCKind._tk_sequence 588 && tk != TCKind._tk_value_box)) 589 { 590 throw new BadKind (); 591 } 592 return _ref; 593 } 594 595 598 public void content_type(org.omg.CORBA.TypeCode type) 599 { 600 _ref = type; 601 } 602 603 607 public short fixed_digits() 608 throws BadKind 609 { 610 if (_indirection) 611 { 612 return _ref.fixed_digits(); 613 } 614 int tk = _kind.value(); 615 if (tk != TCKind._tk_fixed) 616 { 617 throw new BadKind (); 618 } 619 return _digits; 620 } 621 622 625 public void fixed_digits(short digits) 626 { 627 _digits = digits; 628 } 629 630 634 public short fixed_scale() 635 throws BadKind 636 { 637 if (_indirection) 638 { 639 return _ref.fixed_scale(); 640 } 641 int tk = _kind.value(); 642 if (tk != TCKind._tk_fixed) 643 { 644 throw new BadKind (); 645 } 646 return _scale; 647 } 648 649 652 public void fixed_scale(short scale) 653 { 654 _scale = scale; 655 } 656 657 663 public short member_visibility 664 (int index) 665 throws BadKind , Bounds 666 { 667 if (_indirection) 668 { 669 return _ref.member_visibility(index); 670 } 671 if (_member_type == null) 672 { 673 throw new BadKind (); 674 } 675 if (index < 0 || index >= _member_visibility.length) 676 { 677 throw new Bounds (); 678 } 679 return _member_visibility[index]; 680 } 681 682 686 public void member_visibility(int index, short visibility) 687 { 688 _member_visibility[index] = visibility; 689 } 690 691 695 public short type_modifier() 696 throws BadKind 697 { 698 if (_indirection) 699 { 700 return _ref.type_modifier(); 701 } 702 int tk = _kind.value(); 703 if (tk != TCKind._tk_value) 704 { 705 throw new BadKind (); 706 } 707 return _type_modifier; 708 } 709 710 713 public void type_modifier(short modifier) 714 { 715 _type_modifier = modifier; 716 } 717 718 722 public org.omg.CORBA.TypeCode concrete_base_type() 723 throws BadKind 724 { 725 if (_indirection) 726 { 727 return _ref.concrete_base_type(); 728 } 729 int tk = _kind.value(); 730 if (tk != TCKind._tk_value) 731 { 732 throw new BadKind (); 733 } 734 return _ref; 735 } 736 737 740 public void concrete_base_type(org.omg.CORBA.TypeCode base) 741 { 742 _ref = base; 743 } 744 745 748 public void indirection(org.omg.CORBA.TypeCode ref) 749 { 750 _ref = ref; 751 _indirection = true; 752 } 753 754 757 public void recursive(String id) 758 { 759 _id = id; 760 _ref = null; 761 _indirection = true; 762 } 763 764 767 public void fix_recursive_members() 768 { 769 String id = _id == null ? default_id() : _id; 770 int n = _member_type.length; 771 for (int i = 0; i < n; i++) 772 { 773 TypeCode mt = (TypeCode) _member_type[i]; 774 if (mt._kind.value() == TCKind._tk_sequence) 775 { 776 TypeCode ct = (TypeCode) mt._ref; 777 if (ct._indirection 778 && 779 ct._ref == null 780 && ct._id.equals(id)) 781 { 782 ct._ref = this; 783 } 784 } 785 } 786 } 787 788 794 private String default_id() 795 { 796 if (_type == null) 800 { 801 return ""; 802 } 803 StringBuffer id = new StringBuffer (_type.length() + 10); 804 id.append("IDL:"); 805 int n = _type.length(); 806 for (int i = 0; i < n; i++) 807 { 808 char c = _type.charAt(i); 809 if (c == ':' && i + 1 < n && _type.charAt(i + 1) == ':') 810 { 811 i++; 812 } 813 id.append(c == ':' ? '/' : c); 814 } 815 id.append(":1.0"); 816 return id.toString(); 817 } 818 } 819 | Popular Tags |