1 26 27 package org.objectweb.openccm.ast.lib; 28 29 30 import org.objectweb.openccm.ast.api.TypeKind; 31 32 33 import org.objectweb.openccm.ast.api.TypeRef; 34 35 36 import org.objectweb.openccm.ast.api.PsdlTypeRef; 37 38 39 import org.objectweb.openccm.ast.api.DeclarationKind; 40 41 42 import org.objectweb.openccm.ast.api.Declaration; 43 44 45 import org.objectweb.openccm.ast.api.Scope; 46 47 48 import org.objectweb.openccm.ast.api.AnyValue; 49 50 51 import org.omg.CORBA.PrimitiveKind ; 52 53 65 66 public class Repository 67 extends ScopeImpl 68 implements org.objectweb.openccm.ast.api.AST 69 { 70 76 77 private TypeRefImpl null_ = null; 78 79 80 private TypeRefImpl void_ = null; 81 82 83 private TypeRefImpl short_ = null; 84 85 86 private TypeRefImpl long_ = null; 87 88 89 private TypeRefImpl unsigned_short_ = null; 90 91 92 private TypeRefImpl unsigned_long_ = null; 93 94 95 private TypeRefImpl float_ = null; 96 97 98 private TypeRefImpl double_ = null; 99 100 101 private TypeRefImpl boolean_ = null; 102 103 104 private TypeRefImpl char_ = null; 105 106 107 private TypeRefImpl octet_ = null; 108 109 110 private TypeRefImpl any_ = null; 111 112 113 private TypeRefImpl TypeCode_ = null; 114 115 116 private TypeRefImpl Principal_ = null; 117 118 119 private TypeRefImpl string_ = null; 120 121 122 private TypeRefImpl object_ = null; 123 124 125 private TypeRefImpl long_long_ = null; 126 127 128 private TypeRefImpl unsigned_long_long_ = null; 129 130 131 private TypeRefImpl long_double_ = null; 132 133 134 private TypeRefImpl wchar_ = null; 135 136 137 private TypeRefImpl wstring_ = null; 138 139 140 private TypeRefImpl value_base_ = null; 141 142 143 private java.util.Hashtable declarations_; 144 145 146 private java.util.Hashtable mapped_declarations_; 147 148 149 private org.omg.CORBA.Repository repository_; 150 151 152 private org.objectweb.openccm.ir3.api.ComponentRepository openccm_repository_; 153 154 160 165 public 166 Repository(org.omg.CORBA.Repository repository) 167 { 168 super(null, null); 170 171 the_repository_ = this; 173 174 declarations_ = new java.util.Hashtable (); 176 mapped_declarations_ = new java.util.Hashtable (); 177 repository_ = repository; 178 openccm_repository_ = org.objectweb.openccm.ir3.api.ComponentRepositoryHelper. 179 narrow(repository); 180 } 181 182 188 194 protected void 195 addDeclInRep(String rep_id, 196 Declaration decl) 197 { 198 declarations_.put(rep_id, decl); 199 } 200 201 206 protected void 207 removeDeclFromRep(String rep_id) 208 { 209 declarations_.remove(rep_id); 210 } 211 212 218 protected void 219 addMappedDeclInRep(String rep_id, 220 Declaration decl) 221 { 222 mapped_declarations_.put(rep_id, decl); 223 } 224 225 230 protected void 231 removeMappedDeclFromRep(String rep_id) 232 { 233 mapped_declarations_.remove(rep_id); 234 } 235 236 249 protected Declaration 250 loadContained(Scope scope, org.omg.CORBA.Contained contained) 251 { 252 ScopeImpl si = (ScopeImpl)scope; 253 org.omg.CORBA.DefinitionKind kind = contained.def_kind(); 254 255 if ((kind!=org.omg.CORBA.DefinitionKind.dk_Module) && 256 (kind!=org.omg.CORBA.DefinitionKind.dk_Interface) && 257 (kind!=org.omg.CORBA.DefinitionKind.dk_LocalInterface) && 258 (kind!=org.omg.CORBA.DefinitionKind.dk_AbstractInterface) && 259 (kind!=org.omg.CORBA.DefinitionKind.dk_Value) && 260 (kind!=org.omg.CORBA.DefinitionKind.dk_Struct) && 261 (kind!=org.omg.CORBA.DefinitionKind.dk_Union) && 262 (kind!=org.omg.CORBA.DefinitionKind.dk_Exception) && 263 (kind!=org.omg.CORBA.DefinitionKind.dk_Component) && 264 (kind!=org.omg.CORBA.DefinitionKind.dk_Home) && 265 (kind!=org.omg.CORBA.DefinitionKind.dk_Event)) 266 return null; 267 268 return si.loadContained(contained); 269 } 270 271 279 protected TypeRef 280 getAsTypeRef(org.omg.CORBA.IDLType type, 281 boolean is_mapped) 282 { 283 org.omg.CORBA.TypeCode tc = type.type(); 284 try 285 { 286 switch(tc.kind().value()) 287 { 288 case org.omg.CORBA.TCKind._tk_null: 289 return getNullType(); 290 case org.omg.CORBA.TCKind._tk_void: 291 return getVoidType(); 292 case org.omg.CORBA.TCKind._tk_short: 293 return getShortType(); 294 case org.omg.CORBA.TCKind._tk_long: 295 return getLongType(); 296 case org.omg.CORBA.TCKind._tk_ushort: 297 return getUShortType(); 298 case org.omg.CORBA.TCKind._tk_ulong: 299 return getULongType(); 300 case org.omg.CORBA.TCKind._tk_float: 301 return getFloatType(); 302 case org.omg.CORBA.TCKind._tk_double: 303 return getDoubleType(); 304 case org.omg.CORBA.TCKind._tk_boolean: 305 return getBooleanType(); 306 case org.omg.CORBA.TCKind._tk_char: 307 return getCharType(); 308 case org.omg.CORBA.TCKind._tk_octet: 309 return getOctetType(); 310 case org.omg.CORBA.TCKind._tk_any: 311 return getAnyType(); 312 case org.omg.CORBA.TCKind._tk_TypeCode: 313 return getTypeCodeType(); 314 case org.omg.CORBA.TCKind._tk_Principal: 315 return getPrincipalType(); 316 case org.omg.CORBA.TCKind._tk_longlong: 317 return getLongLongType(); 318 case org.omg.CORBA.TCKind._tk_ulonglong: 319 return getULongLongType(); 320 case org.omg.CORBA.TCKind._tk_longdouble: 321 return getLongDoubleType(); 322 case org.omg.CORBA.TCKind._tk_wchar: 323 return getWCharType(); 324 325 case org.omg.CORBA.TCKind._tk_string: 326 return new TypeRefWithLengthImpl(type, 327 TypeKind.tk_string, 328 tc.length()); 329 case org.omg.CORBA.TCKind._tk_sequence: 330 org.omg.CORBA.SequenceDef seq = org.omg.CORBA.SequenceDefHelper. 331 narrow(type); 332 return new TypeRefWithContentImpl(type, 333 TypeKind.tk_sequence, 334 tc.length(), 335 getAsTypeRef(seq.element_type_def())); 336 case org.omg.CORBA.TCKind._tk_array: 337 org.omg.CORBA.ArrayDef arr = org.omg.CORBA.ArrayDefHelper.narrow(type); 338 return new TypeRefWithContentImpl(type, 339 TypeKind.tk_array, 340 tc.length(), 341 getAsTypeRef(arr.element_type_def())); 342 case org.omg.CORBA.TCKind._tk_wstring: 343 return new TypeRefWithLengthImpl(type, 344 TypeKind.tk_wstring, 345 tc.length()); 346 case org.omg.CORBA.TCKind._tk_fixed: 347 return new FixedTypeRefImpl(type, 348 tc.fixed_digits(), 349 tc.fixed_scale()); 350 case org.omg.CORBA.TCKind._tk_objref: 351 if (tc.id().equals("IDL:omg.org/CORBA/Object:1.0")) 352 return getObjectType(); 353 354 case org.omg.CORBA.TCKind._tk_struct: 355 case org.omg.CORBA.TCKind._tk_union: 356 case org.omg.CORBA.TCKind._tk_enum: 357 case org.omg.CORBA.TCKind._tk_alias: 358 case org.omg.CORBA.TCKind._tk_value: 359 case org.omg.CORBA.TCKind._tk_value_box: 360 case org.omg.CORBA.TCKind._tk_native: 361 case org.omg.CORBA.TCKind._tk_abstract_interface: 362 369 if (is_mapped) 370 return (TypeRef)lookupMappedId(tc.id()); 371 else 372 return (TypeRef)lookupId(tc.id()); 373 374 case org.omg.CORBA.TCKind._tk_except: 379 default: 380 return getNullType(); 381 } 382 } 383 catch(org.omg.CORBA.TypeCodePackage.BadKind ex) 384 { 385 throw new org.objectweb.openccm.corba.UserExceptionWrapper(ex); 386 } 387 } 388 389 397 protected TypeRefImpl 398 createTypeRefImpl(PrimitiveKind pk, 399 TypeKind tk) 400 { 401 return new TypeRefImpl(repository_.get_primitive(pk), tk); 402 } 403 404 410 413 public void 414 useIDL3Repository() 415 { 416 if (openccm_repository_!=null) 418 openccm_repository_.as_IDL3_repository(); 419 } 420 421 424 public void 425 useIDL2Repository() 426 { 427 if (openccm_repository_!=null) 429 openccm_repository_.as_IDL2_repository(); 430 } 431 432 435 public Declaration 436 loadMapping(Scope scope, String rep_id) 437 { 438 if (openccm_repository_==null) 440 return null; 441 442 useIDL2Repository(); 444 445 Declaration result = (Declaration)mapped_declarations_.get(rep_id); 447 if (result==null) 448 { 449 org.omg.CORBA.Contained decl = openccm_repository_.lookup_mapped_id(rep_id); 450 if (decl!=null) 451 { 452 ScopeImpl si = (ScopeImpl)scope; 454 result = si.loadContainedAsMapping(decl); 455 } 456 } 457 458 useIDL3Repository(); 460 461 return result; 462 } 463 464 472 public Declaration 473 lookup(String scoped_name) 474 { 475 if (scoped_name.startsWith("::")) 476 return super.lookup(scoped_name.substring(2)); 477 else 478 return super.lookup(scoped_name); 479 } 480 481 484 public Declaration 485 lookupMappedId(String rep_id) 486 { 487 Object obj = mapped_declarations_.get(rep_id); 488 if (obj!=null) 489 return (Declaration)obj; 490 491 org.omg.CORBA.Contained decl = openccm_repository_.lookup_mapped_id(rep_id); 493 494 if (decl==null) 496 return lookupId(rep_id); 497 498 org.omg.CORBA.Contained decl2 = null; 500 String abs_name = decl.absolute_name(); 501 String name = ""; 502 if (abs_name.startsWith("::")) 503 abs_name = abs_name.substring(2, abs_name.length()); 504 505 int idx = 0; 506 ScopeImpl scope = null; 507 obj = this; 508 while (true) 509 { 510 scope = (ScopeImpl)obj; 511 idx = abs_name.indexOf(':'); 512 if (idx==-1) 513 return scope.loadContainedAsMapping(decl); 514 name = abs_name.substring(0, idx); 515 abs_name = abs_name.substring(idx+2, abs_name.length()); 516 obj = scope.findInScope(name); 517 if (obj==null) 518 { 519 decl2 = scope.getContainer().lookup(name); 520 obj = scope.loadContainedAsMapping(decl2); 521 } 522 } 523 } 524 525 528 public Declaration 529 lookupId(String rep_id) 530 { 531 Object obj = declarations_.get(rep_id); 532 533 if (obj!=null) 534 return (Declaration)obj; 535 536 org.omg.CORBA.Contained decl = repository_.lookup_id(rep_id); 538 org.omg.CORBA.Contained decl2 = null; 539 String abs_name = decl.absolute_name(); 540 String name = ""; 541 if (abs_name.startsWith("::")) 542 abs_name = abs_name.substring(2, abs_name.length()); 543 544 int idx = 0; 545 ScopeImpl scope = null; 546 obj = this; 547 while (true) 548 { 549 scope = (ScopeImpl)obj; 550 idx = abs_name.indexOf(':'); 551 if (idx==-1) 552 return scope.loadContained(decl); 553 name = abs_name.substring(0, idx); 554 abs_name = abs_name.substring(idx+2, abs_name.length()); 555 obj = scope.findInScope(name); 556 if (obj==null) 557 { 558 decl2 = scope.getContainer().lookup(name); 559 obj = scope.loadContained(decl2); 560 } 561 } 562 } 563 564 567 public TypeRef 568 getAsMappedTypeRef(org.omg.CORBA.IDLType type) 569 { 570 return getAsTypeRef(type, true); 571 } 572 573 576 public TypeRef 577 getAsTypeRef(org.omg.CORBA.IDLType type) 578 { 579 return getAsTypeRef(type, false); 580 } 581 582 588 594 protected org.omg.CORBA.Contained 595 getContained() 596 { 597 return null; 598 } 599 600 605 public long 606 getDeclKind() 607 { 608 return DeclarationKind.dk_repository; 609 } 610 611 617 622 protected org.omg.CORBA.Container 623 getContainer() 624 { 625 return repository_; 626 } 627 628 633 protected org.omg.CORBA.ComponentIR.Container 634 getComponentContainer() 635 { 636 return openccm_repository_; 637 } 638 639 645 656 public Declaration 657 importByName(Scope sc, String name) 658 { 659 Declaration d = ((ScopeImpl)sc).findInScope(name); 661 if (d != null) 662 return d; 663 664 org.omg.CORBA.Contained decl = repository_.lookup(name); 666 if (decl==null) 667 return null; 668 669 return loadContained(sc, decl); 670 } 671 672 683 public Declaration 684 importById(Scope sc, String id) 685 { 686 Declaration d = (Declaration)declarations_.get(id); 688 if (d != null) 689 return d; 690 691 org.omg.CORBA.Contained decl = repository_.lookup_id(id); 693 if (decl==null) 694 return null; 695 696 return loadContained(sc, decl); 697 } 698 699 704 public AnyValue 705 createAnyValue() 706 { 707 return new AnyValueImpl(); 708 } 709 710 711 716 public TypeRef 717 getNullType() 718 { 719 if (null_ == null) 720 { 721 null_ = createTypeRefImpl(PrimitiveKind.pk_null, 722 TypeKind.tk_null); 723 } 724 return null_; 725 } 726 727 732 public TypeRef 733 getVoidType() 734 { 735 if (void_ == null) 736 { 737 void_ = createTypeRefImpl(PrimitiveKind.pk_void, 738 TypeKind.tk_void); 739 } 740 return void_; 741 } 742 743 748 public TypeRef 749 getShortType() 750 { 751 if (short_ == null) 752 { 753 short_ = createTypeRefImpl(PrimitiveKind.pk_short, 754 TypeKind.tk_short); 755 } 756 return short_; 757 } 758 759 764 public TypeRef 765 getLongType() 766 { 767 if (long_ == null) 768 { 769 long_ = createTypeRefImpl(PrimitiveKind.pk_long, 770 TypeKind.tk_long); 771 } 772 return long_; 773 } 774 775 780 public TypeRef 781 getUShortType() 782 { 783 if (unsigned_short_ == null) 784 { 785 unsigned_short_ = createTypeRefImpl(PrimitiveKind.pk_ushort, 786 TypeKind.tk_ushort); 787 } 788 return unsigned_short_; 789 } 790 791 796 public TypeRef 797 getULongType() 798 { 799 if (unsigned_long_ == null) 800 { 801 unsigned_long_ = createTypeRefImpl(PrimitiveKind.pk_ulong, 802 TypeKind.tk_ulong); 803 } 804 return unsigned_long_; 805 } 806 807 812 public TypeRef 813 getFloatType() 814 { 815 if (float_ == null) 816 { 817 float_ = createTypeRefImpl(PrimitiveKind.pk_float, 818 TypeKind.tk_float); 819 } 820 return float_; 821 } 822 823 828 public TypeRef 829 getDoubleType() 830 { 831 if (double_ == null) 832 { 833 double_ = createTypeRefImpl(PrimitiveKind.pk_double, 834 TypeKind.tk_double); 835 } 836 return double_; 837 } 838 839 844 public TypeRef 845 getBooleanType() 846 { 847 if (boolean_ == null) 848 { 849 boolean_ = createTypeRefImpl(PrimitiveKind.pk_boolean, 850 TypeKind.tk_boolean); 851 } 852 return boolean_; 853 } 854 855 860 public TypeRef 861 getCharType() 862 { 863 if (char_ == null) 864 { 865 char_ = createTypeRefImpl(PrimitiveKind.pk_char, 866 TypeKind.tk_char); 867 } 868 return char_; 869 } 870 871 876 public TypeRef 877 getOctetType() 878 { 879 if (octet_ == null) 880 { 881 octet_ = createTypeRefImpl(PrimitiveKind.pk_octet, 882 TypeKind.tk_octet); 883 } 884 return octet_; 885 } 886 887 892 public TypeRef 893 getAnyType() 894 { 895 if (any_ == null) 896 { 897 any_ = createTypeRefImpl(PrimitiveKind.pk_any, 898 TypeKind.tk_any); 899 } 900 return any_; 901 } 902 903 908 public TypeRef 909 getTypeCodeType() 910 { 911 if (TypeCode_ == null) 912 { 913 TypeCode_ = createTypeRefImpl(PrimitiveKind.pk_TypeCode, 914 TypeKind.tk_TypeCode); 915 } 916 return TypeCode_; 917 } 918 919 924 public TypeRef 925 getPrincipalType() 926 { 927 if (Principal_ == null) 928 { 929 Principal_ = createTypeRefImpl(PrimitiveKind.pk_Principal, 930 TypeKind.tk_Principal); 931 } 932 return Principal_; 933 } 934 935 940 public TypeRef 941 getStringType() 942 { 943 if (string_ == null) 944 { 945 string_ = new TypeRefWithLengthImpl( 946 repository_.get_primitive(PrimitiveKind.pk_string), 947 TypeKind.tk_string, 0); 948 } 949 return string_; 950 } 951 952 957 public TypeRef 958 getObjectType() 959 { 960 if (object_ == null) 961 { 962 object_ = createTypeRefImpl(PrimitiveKind.pk_objref, 963 TypeKind.tk_objref); 964 } 965 return object_; 966 } 967 968 973 public TypeRef 974 getLongLongType() 975 { 976 if (long_long_ == null) 977 { 978 long_long_ = createTypeRefImpl(PrimitiveKind.pk_longlong, 979 TypeKind.tk_longlong); 980 } 981 return long_long_; 982 } 983 984 989 public TypeRef 990 getULongLongType() 991 { 992 if (unsigned_long_long_ == null) 993 { 994 unsigned_long_long_ = createTypeRefImpl(PrimitiveKind.pk_ulonglong, 995 TypeKind.tk_ulonglong); 996 } 997 return unsigned_long_long_; 998 } 999 1000 1005 public TypeRef 1006 getLongDoubleType() 1007 { 1008 if (long_double_ == null) 1009 { 1010 long_double_ = createTypeRefImpl(PrimitiveKind.pk_longdouble, 1011 TypeKind.tk_longdouble); 1012 } 1013 return long_double_; 1014 } 1015 1016 1021 public TypeRef 1022 getWCharType() 1023 { 1024 if (wchar_ == null) 1025 { 1026 wchar_ = createTypeRefImpl(PrimitiveKind.pk_wchar, 1027 TypeKind.tk_wchar); 1028 } 1029 return wchar_; 1030 } 1031 1032 1037 public TypeRef 1038 getWStringType() 1039 { 1040 if (wstring_ == null) 1041 { 1042 wstring_ = new TypeRefWithLengthImpl( 1043 repository_.get_primitive(PrimitiveKind.pk_wstring), 1044 TypeKind.tk_wstring, 0); 1045 } 1046 return wstring_; 1047 } 1048 1049 1054 public TypeRef 1055 getValueBaseType() 1056 { 1057 if (value_base_ == null) 1058 { 1059 value_base_ = createTypeRefImpl(PrimitiveKind.pk_value_base, 1060 TypeKind.tk_value); 1061 } 1062 return value_base_; 1063 } 1064 1065 1072 public TypeRef 1073 createStringType(int bound) 1074 { 1075 org.omg.CORBA.StringDef stringDef = repository_.create_string(bound); 1077 return new TypeRefWithLengthImpl(stringDef, TypeKind.tk_string, bound); 1078 } 1079 1080 1087 public TypeRef 1088 createWStringType(int bound) 1089 { 1090 org.omg.CORBA.WstringDef wstringDef = repository_.create_wstring(bound); 1092 return new TypeRefWithLengthImpl(wstringDef, TypeKind.tk_wstring, bound); 1093 } 1094 1095 1103 public TypeRef 1104 createSequenceType(int bound, 1105 TypeRef element_type) 1106 { 1107 if(element_type == null) 1108 return null; 1109 1110 org.omg.CORBA.SequenceDef sequenceDef = 1112 repository_.create_sequence(bound, 1113 ((IDLTypeWrapper)element_type).getIDLType()); 1114 return new TypeRefWithContentImpl(sequenceDef, TypeKind.tk_sequence, 1115 bound, element_type); 1116 } 1117 1118 1126 public TypeRef 1127 createArrayType(int length, 1128 TypeRef element_type) 1129 { 1130 if(element_type == null) 1131 return null; 1132 1133 org.omg.CORBA.ArrayDef arrayDef = 1135 repository_.create_array(length, 1136 ((IDLTypeWrapper)element_type).getIDLType()); 1137 return new TypeRefWithContentImpl(arrayDef, TypeKind.tk_array, 1138 length, element_type); 1139 } 1140 1141 1149 public TypeRef 1150 createFixedType(short digits, 1151 short scale) 1152 { 1153 org.omg.CORBA.FixedDef fixedDef = 1155 repository_.create_fixed (digits, scale); 1156 return new FixedTypeRefImpl(fixedDef, digits, scale); 1157 } 1158 1159 1166 public PsdlTypeRef 1167 createPsdlType(TypeRef idl_type) 1168 { 1169 return new PsdlTypeRefImpl(idl_type); 1170 } 1171 1172 1182 public PsdlTypeRef 1183 createAbstractStorageTypePsdlType( boolean isStrong, 1184 boolean isRef, 1185 org.objectweb.openccm.ast.api.AbstractStorageTypeDecl ast) 1186 { 1187 return new PsdlTypeRefImpl(ast, isRef, isStrong); 1188 } 1189 1190 1199 public PsdlTypeRef 1200 createStorageTypePsdlType( boolean isRef, 1201 org.objectweb.openccm.ast.api.StorageTypeDecl st) 1202 { 1203 return new PsdlTypeRefImpl(st, isRef, false); 1204 } 1205} 1206 | Popular Tags |