1 26 27 package org.objectweb.ccm.IDL3; 28 29 37 38 public class Repository 39 extends ScopeImpl 40 implements PrimitiveTypeFactory 41 { 42 48 51 private TypeRefImpl null_ = null; 52 53 56 private TypeRefImpl void_ = null; 57 58 61 private TypeRefImpl short_ = null; 62 63 66 private TypeRefImpl long_ = null; 67 68 71 private TypeRefImpl unsigned_short_ = null; 72 73 76 private TypeRefImpl unsigned_long_ = null; 77 78 81 private TypeRefImpl float_ = null; 82 83 86 private TypeRefImpl double_ = null; 87 88 91 private TypeRefImpl boolean_ = null; 92 93 96 private TypeRefImpl char_ = null; 97 98 101 private TypeRefImpl octet_ = null; 102 103 106 private TypeRefImpl any_ = null; 107 108 111 private TypeRefImpl TypeCode_ = null; 112 113 116 private TypeRefImpl Principal_ = null; 117 118 121 private TypeRefImpl string_ = null; 122 123 126 private TypeRefImpl object_ = null; 127 128 131 private TypeRefImpl long_long_ = null; 132 133 136 private TypeRefImpl unsigned_long_long_ = null; 137 138 141 private TypeRefImpl long_double_ = null; 142 143 146 private TypeRefImpl wchar_ = null; 147 148 151 private TypeRefImpl wstring_ = null; 152 153 156 private TypeRefImpl value_base_ = null; 157 158 161 private org.objectweb.ccm.util.Table declarations_; 162 163 166 private org.objectweb.ccm.util.Table mapped_declarations_; 167 168 171 private org.omg.CORBA.Repository repository_; 172 173 176 private org.objectweb.openccm.ir3.api.ComponentRepository openccm_repository_; 177 178 184 189 public 190 Repository(org.omg.CORBA.Repository repository) 191 { 192 super(null, null); 194 195 the_declaration_kind_ = DeclarationKind._dk_repository; 197 repository_ = repository; 198 openccm_repository_ = org.objectweb.openccm.ir3.api.ComponentRepositoryHelper.narrow(repository); 199 declarations_ = new org.objectweb.ccm.util.Table(); 200 mapped_declarations_ = new org.objectweb.ccm.util.Table(); 201 the_repository_ = this; 202 } 203 204 210 213 protected void 214 addDeclInRep(String rep_id, Declaration decl) 215 { 216 declarations_.put(rep_id, decl); 217 } 218 219 222 protected void 223 removeDeclFromRep(String rep_id) 224 { 225 declarations_.remove(rep_id); 226 } 227 228 231 protected void 232 addMappedDeclInRep(String rep_id, Declaration decl) 233 { 234 mapped_declarations_.put(rep_id, decl); 235 } 236 237 240 protected void 241 removeMappedDeclFromRep(String rep_id) 242 { 243 mapped_declarations_.remove(rep_id); 244 } 245 246 258 protected Declaration 259 loadContained(Scope scope, org.omg.CORBA.Contained contained) 260 { 261 ScopeImpl si = (ScopeImpl)scope; 262 int kind = contained.def_kind().value(); 263 264 if ((kind!=org.omg.CORBA.DefinitionKind._dk_Module) && 265 (kind!=org.omg.CORBA.DefinitionKind._dk_Interface) && 266 (kind!=org.omg.CORBA.DefinitionKind._dk_LocalInterface) && 267 (kind!=org.omg.CORBA.DefinitionKind._dk_AbstractInterface) && 268 (kind!=org.omg.CORBA.DefinitionKind._dk_Value) && 269 (kind!=org.omg.CORBA.DefinitionKind._dk_Struct) && 270 (kind!=org.omg.CORBA.DefinitionKind._dk_Union) && 271 (kind!=org.omg.CORBA.DefinitionKind._dk_Exception) && 272 (kind!=org.omg.CORBA.DefinitionKind._dk_Component) && 273 (kind!=org.omg.CORBA.DefinitionKind._dk_Home) && 274 (kind!=org.omg.CORBA.DefinitionKind._dk_Event)) 275 return null; 276 277 return si.loadContained(contained); 278 } 279 280 283 protected TypeRef 284 getAsTypeRef(org.omg.CORBA.IDLType type, 285 boolean is_mapped) 286 { 287 org.omg.CORBA.TypeCode tc = type.type(); 288 try 289 { 290 switch(tc.kind().value()) 291 { 292 case org.omg.CORBA.TCKind._tk_null: 293 return type_null(); 294 case org.omg.CORBA.TCKind._tk_void: 295 return type_void(); 296 case org.omg.CORBA.TCKind._tk_short: 297 return type_short(); 298 case org.omg.CORBA.TCKind._tk_long: 299 return type_long(); 300 case org.omg.CORBA.TCKind._tk_ushort: 301 return type_unsigned_short(); 302 case org.omg.CORBA.TCKind._tk_ulong: 303 return type_unsigned_long(); 304 case org.omg.CORBA.TCKind._tk_float: 305 return type_float(); 306 case org.omg.CORBA.TCKind._tk_double: 307 return type_double(); 308 case org.omg.CORBA.TCKind._tk_boolean: 309 return type_boolean(); 310 case org.omg.CORBA.TCKind._tk_char: 311 return type_char(); 312 case org.omg.CORBA.TCKind._tk_octet: 313 return type_octet(); 314 case org.omg.CORBA.TCKind._tk_any: 315 return type_any(); 316 case org.omg.CORBA.TCKind._tk_TypeCode: 317 return type_TypeCode(); 318 case org.omg.CORBA.TCKind._tk_Principal: 319 return type_Principal(); 320 case org.omg.CORBA.TCKind._tk_longlong: 321 return type_long_long(); 322 case org.omg.CORBA.TCKind._tk_ulonglong: 323 return type_unsigned_long_long(); 324 case org.omg.CORBA.TCKind._tk_longdouble: 325 return type_long_double(); 326 case org.omg.CORBA.TCKind._tk_wchar: 327 return type_wchar(); 328 329 case org.omg.CORBA.TCKind._tk_string: 330 TypeRefImpl tr = new TypeRefImpl(type, TypeKind._tk_string); 331 tr.setLength(tc.length()); 332 return tr; 333 case org.omg.CORBA.TCKind._tk_sequence: 334 tr = new TypeRefImpl(type, TypeKind._tk_sequence); 335 tr.setLength(tc.length()); 336 org.omg.CORBA.SequenceDef seq = org.omg.CORBA.SequenceDefHelper.narrow(type); 337 tr.setContentType(getAsTypeRef(seq.element_type_def())); 338 return tr; 339 case org.omg.CORBA.TCKind._tk_array: 340 tr = new TypeRefImpl(type, TypeKind._tk_array); 341 tr.setLength(tc.length()); 342 org.omg.CORBA.ArrayDef arr = org.omg.CORBA.ArrayDefHelper.narrow(type); 343 tr.setContentType(getAsTypeRef(arr.element_type_def())); 344 return tr; 345 case org.omg.CORBA.TCKind._tk_wstring: 346 tr = new TypeRefImpl(type, TypeKind._tk_wstring); 347 tr.setLength(tc.length()); 348 return tr; 349 case org.omg.CORBA.TCKind._tk_fixed: 350 tr = new TypeRefImpl(type, TypeKind._tk_fixed); 351 tr.setDigits(tc.fixed_digits()); 352 tr.setScale(tc.fixed_scale()); 353 return tr; 354 355 case org.omg.CORBA.TCKind._tk_objref: 356 if (tc.id().equals("IDL:omg.org/CORBA/Object:1.0")) 357 return type_Object(); 358 359 case org.omg.CORBA.TCKind._tk_struct: 360 case org.omg.CORBA.TCKind._tk_union: 361 case org.omg.CORBA.TCKind._tk_enum: 362 case org.omg.CORBA.TCKind._tk_alias: 363 case org.omg.CORBA.TCKind._tk_value: 364 case org.omg.CORBA.TCKind._tk_value_box: 365 case org.omg.CORBA.TCKind._tk_native: 366 case org.omg.CORBA.TCKind._tk_abstract_interface: 367 374 if (is_mapped) 375 return (TypeRef)lookupMappedId(tc.id()); 376 else 377 return (TypeRef)lookupId(tc.id()); 378 379 case org.omg.CORBA.TCKind._tk_except: 384 default: 385 return type_null(); 386 } 387 } 388 catch(org.omg.CORBA.TypeCodePackage.BadKind ex) 389 { 390 throw new Error ("Should not have happened !"); 391 } 392 } 393 394 400 403 public void 404 useIDL3Repository() 405 { 406 if (openccm_repository_!=null) 408 openccm_repository_.as_IDL3_repository(); 409 } 410 411 414 public void 415 useIDL2Repository() 416 { 417 if (openccm_repository_!=null) 419 openccm_repository_.as_IDL2_repository(); 420 } 421 422 428 436 public Declaration 437 load(Scope scope, String name) 438 { 439 org.omg.CORBA.Contained decl = repository_.lookup(name); 440 if (decl==null) 441 return null; 442 443 return loadContained(scope, decl); 444 } 445 446 454 public Declaration 455 loadId(Scope scope, String id) 456 { 457 org.omg.CORBA.Contained decl = repository_.lookup_id(id); 458 if (decl==null) 459 return null; 460 461 return loadContained(scope, decl); 462 } 463 464 467 public Declaration 468 loadMapping(Scope scope, String rep_id) 469 { 470 if (openccm_repository_==null) 472 return null; 473 474 openccm_repository_.as_IDL2_repository(); 476 477 Declaration result = (Declaration)mapped_declarations_.get(rep_id); 479 if (result!=null) 480 return result; 481 482 org.omg.CORBA.Contained decl = openccm_repository_.lookup_mapped_id(rep_id); 483 if (decl==null) 484 return null; 485 486 ScopeImpl si = (ScopeImpl)scope; 488 result = si.loadContainedAsMapping(decl); 489 490 openccm_repository_.as_IDL3_repository(); 492 493 return result; 494 } 495 496 502 510 public Declaration 511 lookup(String scoped_name) 512 { 513 if (scoped_name.startsWith("::")) 514 return super.lookup(scoped_name.substring(2)); 515 else 516 return super.lookup(scoped_name); 517 } 518 519 522 public Declaration 523 lookupMappedId(String rep_id) 524 { 525 Object obj = mapped_declarations_.get(rep_id); 526 if (obj!=null) 527 return (Declaration)obj; 528 529 org.omg.CORBA.Contained decl = openccm_repository_.lookup_mapped_id(rep_id); 531 532 if (decl==null) 534 return lookupId(rep_id); 535 536 org.omg.CORBA.Contained decl2 = null; 538 String abs_name = decl.absolute_name(); 539 String name = ""; 540 if (abs_name.startsWith("::")) 541 abs_name = abs_name.substring(2, abs_name.length()); 542 543 int idx = 0; 544 ScopeImpl scope = null; 545 obj = this; 546 while (true) 547 { 548 scope = (ScopeImpl)obj; 549 idx = abs_name.indexOf(':'); 550 if (idx==-1) 551 return scope.loadContainedAsMapping(decl); 552 name = abs_name.substring(0, idx); 553 abs_name = abs_name.substring(idx+2, abs_name.length()); 554 obj = scope.findInScope(name); 555 if (obj==null) 556 { 557 decl2 = scope.getContainer().lookup(name); 558 obj = scope.loadContainedAsMapping(decl2); 559 } 560 } 561 } 562 563 566 public Declaration 567 lookupId(String rep_id) 568 { 569 Object obj = declarations_.get(rep_id); 570 571 if (obj!=null) 572 return (Declaration)obj; 573 574 org.omg.CORBA.Contained decl = repository_.lookup_id(rep_id); 576 org.omg.CORBA.Contained decl2 = null; 577 String abs_name = decl.absolute_name(); 578 String name = ""; 579 if (abs_name.startsWith("::")) 580 abs_name = abs_name.substring(2, abs_name.length()); 581 582 int idx = 0; 583 ScopeImpl scope = null; 584 obj = this; 585 while (true) 586 { 587 scope = (ScopeImpl)obj; 588 idx = abs_name.indexOf(':'); 589 if (idx==-1) 590 return scope.loadContained(decl); 591 name = abs_name.substring(0, idx); 592 abs_name = abs_name.substring(idx+2, abs_name.length()); 593 obj = scope.findInScope(name); 594 if (obj==null) 595 { 596 decl2 = scope.getContainer().lookup(name); 597 obj = scope.loadContained(decl2); 598 } 599 } 600 } 601 602 608 611 public TypeRef 612 getAsMappedTypeRef(org.omg.CORBA.IDLType type) 613 { 614 return getAsTypeRef(type, true); 615 } 616 617 620 public TypeRef 621 getAsTypeRef(org.omg.CORBA.IDLType type) 622 { 623 return getAsTypeRef(type, false); 624 } 625 626 631 public TypeRef 632 type_null() 633 { 634 if (null_ == null) 635 { 636 null_ = new TypeRefImpl( 637 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_null), 638 TypeKind._tk_null); 639 } 640 return null_; 641 } 642 643 648 public TypeRef 649 type_void() 650 { 651 if (void_ == null) 652 { 653 void_ = new TypeRefImpl( 654 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_void), 655 TypeKind._tk_void); 656 } 657 return void_; 658 } 659 660 665 public TypeRef 666 type_short() 667 { 668 if (short_ == null) 669 { 670 short_ = new TypeRefImpl( 671 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_short), 672 TypeKind._tk_short); 673 } 674 return short_; 675 } 676 677 682 public TypeRef 683 type_long() 684 { 685 if (long_ == null) 686 { 687 long_ = new TypeRefImpl( 688 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_long), 689 TypeKind._tk_long); 690 } 691 return long_; 692 } 693 694 699 public TypeRef 700 type_unsigned_short() 701 { 702 if (unsigned_short_ == null) 703 { 704 unsigned_short_ = new TypeRefImpl( 705 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_ushort), 706 TypeKind._tk_ushort); 707 } 708 return unsigned_short_; 709 } 710 711 716 public TypeRef 717 type_unsigned_long() 718 { 719 if (unsigned_long_ == null) 720 { 721 unsigned_long_ = new TypeRefImpl( 722 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_ulong), 723 TypeKind._tk_ulong); 724 } 725 return unsigned_long_; 726 } 727 728 733 public TypeRef 734 type_float() 735 { 736 if (float_ == null) 737 { 738 float_ = new TypeRefImpl( 739 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_float), 740 TypeKind._tk_float); 741 } 742 return float_; 743 } 744 745 750 public TypeRef 751 type_double() 752 { 753 if (double_ == null) 754 { 755 double_ = new TypeRefImpl( 756 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_double), 757 TypeKind._tk_double); 758 } 759 return double_; 760 } 761 762 767 public TypeRef 768 type_boolean() 769 { 770 if (boolean_ == null) 771 { 772 boolean_ = new TypeRefImpl( 773 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_boolean), 774 TypeKind._tk_boolean); 775 } 776 return boolean_; 777 } 778 779 784 public TypeRef 785 type_char() 786 { 787 if (char_ == null) 788 { 789 char_ = new TypeRefImpl( 790 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_char), 791 TypeKind._tk_char); 792 } 793 return char_; 794 } 795 796 801 public TypeRef 802 type_octet() 803 { 804 if (octet_ == null) 805 { 806 octet_ = new TypeRefImpl( 807 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_octet), 808 TypeKind._tk_octet); 809 } 810 return octet_; 811 } 812 813 818 public TypeRef 819 type_any() 820 { 821 if (any_ == null) 822 { 823 any_ = new TypeRefImpl( 824 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_any), 825 TypeKind._tk_any); 826 } 827 return any_; 828 } 829 830 835 public TypeRef 836 type_TypeCode() 837 { 838 if (TypeCode_ == null) 839 { 840 TypeCode_ =new TypeRefImpl( 841 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_TypeCode), 842 TypeKind._tk_TypeCode); 843 } 844 return TypeCode_; 845 } 846 847 852 public TypeRef 853 type_Principal() 854 { 855 if (Principal_ == null) 856 { 857 Principal_ =new TypeRefImpl( 858 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_Principal), 859 TypeKind._tk_Principal); 860 } 861 return Principal_; 862 } 863 864 869 public TypeRef 870 type_string() 871 { 872 if (string_ == null) 873 { 874 string_ = new TypeRefImpl( 875 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_string), 876 TypeKind._tk_string); 877 } 878 return string_; 879 } 880 881 886 public TypeRef 887 type_Object() 888 { 889 if (object_ == null) 890 { 891 object_ = new TypeRefImpl( 892 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_objref), 893 TypeKind._tk_objref); 894 } 895 return object_; 896 } 897 898 903 public TypeRef 904 type_long_long() 905 { 906 if (long_long_ == null) 907 { 908 long_long_ = new TypeRefImpl( 909 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_longlong), 910 TypeKind._tk_longlong); 911 } 912 return long_long_; 913 } 914 915 920 public TypeRef 921 type_unsigned_long_long() 922 { 923 if (unsigned_long_long_ == null) 924 { 925 unsigned_long_long_ = new TypeRefImpl( 926 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_ulonglong), 927 TypeKind._tk_ulonglong); 928 } 929 return unsigned_long_long_; 930 } 931 932 937 public TypeRef 938 type_long_double() 939 { 940 if (long_double_ == null) 941 { 942 long_double_ = new TypeRefImpl( 943 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_longdouble), 944 TypeKind._tk_longdouble); 945 } 946 return long_double_; 947 } 948 949 954 public TypeRef 955 type_wchar() 956 { 957 if (wchar_ == null) 958 { 959 wchar_ = new TypeRefImpl( 960 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_wchar), 961 TypeKind._tk_wchar); 962 } 963 return wchar_; 964 } 965 966 971 public TypeRef 972 type_wstring() 973 { 974 if (wstring_ == null) 975 { 976 wstring_ = new TypeRefImpl( 977 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_wstring), 978 TypeKind._tk_wstring); 979 } 980 return wstring_; 981 } 982 983 988 public TypeRef 989 type_value_base() 990 { 991 if (value_base_ == null) 992 { 993 value_base_ = new TypeRefImpl( 994 repository_.get_primitive(org.omg.CORBA.PrimitiveKind.pk_value_base), 995 TypeKind._tk_null); 999 } 1000 return value_base_; 1001 } 1002 1003 1010 public TypeRef 1011 createString(int bound) 1012 { 1013 org.omg.CORBA.StringDef stringDef = repository_.create_string(bound); 1015 TypeRefImpl tr = new TypeRefImpl(stringDef, TypeKind._tk_string); 1016 tr.setLength(bound); 1017 return tr; 1018 } 1019 1020 1027 public TypeRef 1028 createWstring(int bound) 1029 { 1030 org.omg.CORBA.WstringDef wstringDef = repository_.create_wstring(bound); 1032 TypeRefImpl tr = new TypeRefImpl(wstringDef, TypeKind._tk_wstring); 1033 tr.setLength(bound); 1034 return tr; 1035 } 1036 1037 1045 public TypeRef 1046 createSequence(int bound, 1047 TypeRef element_type) 1048 { 1049 if(element_type == null) 1050 return null; 1051 1052 org.omg.CORBA.SequenceDef sequenceDef = 1054 repository_.create_sequence(bound, element_type.getIDLType()); 1055 TypeRefImpl tr = new TypeRefImpl(sequenceDef, TypeKind._tk_sequence); 1056 tr.setLength(bound); 1057 tr.setContentType(element_type); 1058 return tr; 1059 } 1060 1061 1069 public TypeRef 1070 createArray(int length, 1071 TypeRef element_type) 1072 { 1073 if(element_type == null) 1074 return null; 1075 1076 org.omg.CORBA.ArrayDef arrayDef = 1078 repository_.create_array(length, element_type.getIDLType()); 1079 TypeRefImpl tr = new TypeRefImpl(arrayDef, TypeKind._tk_array); 1080 tr.setLength(length); 1081 tr.setContentType(element_type); 1082 return tr; 1083 } 1084 1085 1093 public TypeRef 1094 createFixed(short digits, 1095 short scale) 1096 { 1097 org.omg.CORBA.FixedDef fixedDef = 1099 repository_.create_fixed (digits,scale); 1100 TypeRefImpl tr = new TypeRefImpl(fixedDef, TypeKind._tk_fixed); 1101 tr.setDigits(digits); 1102 tr.setScale(scale); 1103 return tr; 1104 } 1105 1106 1112 1118 protected org.omg.CORBA.Contained 1119 getContained() 1120 { 1121 return null; 1122 } 1123 1124 1130 1135 protected org.omg.CORBA.Container 1136 getContainer() 1137 { 1138 return repository_; 1139 } 1140 1141 1146 protected org.omg.CORBA.ComponentIR.Container 1147 getComponentContainer() 1148 { 1149 return openccm_repository_; 1150 } 1151} 1152 | Popular Tags |