1 26 27 package org.objectweb.ccm.IDL3; 28 29 37 38 abstract public class ScopeImpl 39 extends DeclarationImpl 40 implements Scope 41 { 42 48 52 protected org.objectweb.ccm.util.Vector contained_decls_; 53 54 57 protected boolean content_loaded_; 58 59 65 70 protected 71 ScopeImpl(Repository rep, ScopeImpl parent) 72 { 73 super(rep, parent); 75 76 contained_decls_ = new org.objectweb.ccm.util.Vector(); 78 content_loaded_ = false; 79 } 80 81 87 92 protected void 93 addDecl(Declaration decl) 94 { 95 contained_decls_.add(decl); 97 } 98 99 105 protected boolean 106 containsDecl(Declaration decl) 107 { 108 return ( decl.getAbsoluteName().startsWith(getAbsoluteName()+"::") ); 109 } 110 111 112 115 protected void 116 removeDecl(String name) 117 { 118 Declaration decl = null; 119 for (int i=0;i<contained_decls_.size();i++) 120 { 121 decl = (Declaration)contained_decls_.get(i); 122 if (decl.getName().equalsIgnoreCase(name)) 123 contained_decls_.remove(i); 124 } 125 } 126 127 130 protected Declaration 131 createDeclaration(int kind, 132 java.lang.String name) 133 { 134 Declaration decl = null; 135 switch (kind) 136 { 137 case org.omg.CORBA.DefinitionKind._dk_Interface : 139 decl = startInterface(name); 140 break; 141 case org.omg.CORBA.DefinitionKind._dk_LocalInterface : 142 decl = startLocalInterface(name); 143 break; 144 case org.omg.CORBA.DefinitionKind._dk_AbstractInterface : 145 decl = startAbstractInterface(name); 146 break; 147 case org.omg.CORBA.DefinitionKind._dk_Module : 148 decl = startModule(name); 149 break; 150 case org.omg.CORBA.DefinitionKind._dk_Struct : 151 decl = startStruct(name); 152 break; 153 case org.omg.CORBA.DefinitionKind._dk_Value : 154 decl = startValue(name); 155 break; 156 case org.omg.CORBA.DefinitionKind._dk_Union : 157 decl = startUnion(name); 158 break; 159 case org.omg.CORBA.DefinitionKind._dk_Exception : 160 decl = startException(name); 161 break; 162 case org.omg.CORBA.DefinitionKind._dk_Constant : 163 decl = startConstant(name); 164 break; 165 case org.omg.CORBA.DefinitionKind._dk_Enum : 166 decl = startEnum(name); 167 break; 168 case org.omg.CORBA.DefinitionKind._dk_Alias : 169 decl = startAlias(name); 170 break; 171 case org.omg.CORBA.DefinitionKind._dk_Attribute : 172 decl = startAttribute(name); 173 break; 174 case org.omg.CORBA.DefinitionKind._dk_Operation : 175 decl = startOperation(name); 176 break; 177 case org.omg.CORBA.DefinitionKind._dk_ValueBox : 178 decl = startValueBox(name); 179 break; 180 case org.omg.CORBA.DefinitionKind._dk_Native : 181 decl = startNative(name); 182 break; 183 case org.omg.CORBA.DefinitionKind._dk_ValueMember : 184 decl = startValueMember(name); 185 break; 186 187 case org.omg.CORBA.DefinitionKind._dk_Component : 189 decl = startComponent(name); 190 break; 191 case org.omg.CORBA.DefinitionKind._dk_Home : 192 decl = startHome(name); 193 break; 194 case org.omg.CORBA.DefinitionKind._dk_Factory : 195 decl = startFactory(name); 196 break; 197 case org.omg.CORBA.DefinitionKind._dk_Finder : 198 decl = startFinder(name); 199 break; 200 case org.omg.CORBA.DefinitionKind._dk_Emits : 201 decl = startEmits(name); 202 break; 203 case org.omg.CORBA.DefinitionKind._dk_Publishes : 204 decl = startPublishes(name); 205 break; 206 case org.omg.CORBA.DefinitionKind._dk_Consumes : 207 decl = startConsumes(name); 208 break; 209 case org.omg.CORBA.DefinitionKind._dk_Provides : 210 decl = startProvides(name); 211 break; 212 case org.omg.CORBA.DefinitionKind._dk_Uses : 213 decl = startUses(name); 214 break; 215 case org.omg.CORBA.DefinitionKind._dk_Event : 216 decl = startEvent(name); 217 break; 218 default : 219 break; 221 } 222 223 return decl; 224 } 225 226 227 234 protected Declaration 235 loadContained(org.omg.CORBA.Contained contained) 236 { 237 DeclarationImpl decl = null; 238 239 decl = (DeclarationImpl)createDeclaration(contained.def_kind().value(), contained.name()); 240 decl.load(contained); 241 decl.setImported(); 242 243 return decl; 244 } 245 246 253 protected Declaration 254 loadContainedAsMapping(org.omg.CORBA.Contained contained) 255 { 256 DeclarationImpl decl = null; 257 258 decl = (DeclarationImpl)createDeclaration(contained.def_kind().value(), contained.name()); 259 decl.loadAsMapping(contained); 260 261 return decl; 262 } 263 264 269 protected StructDecl 270 startStruct(String name) 271 { 272 StructDecl decl = new StructDeclImpl(getRepository(), this); 273 decl.setName(name); 274 return decl; 275 } 276 277 282 protected UnionDecl 283 startUnion(String name) 284 { 285 UnionDecl decl = new UnionDeclImpl(getRepository(), this); 286 decl.setName(name); 287 return decl; 288 } 289 290 295 protected InterfaceDecl 296 startInterface(String name) 297 { 298 InterfaceDecl decl = new InterfaceDeclImpl(getRepository(), this); 299 decl.setName(name); 300 return decl; 301 } 302 303 308 protected LocalInterfaceDecl 309 startLocalInterface(String name) 310 { 311 LocalInterfaceDecl decl = new LocalInterfaceDeclImpl(getRepository(), this); 312 decl.setName(name); 313 return decl; 314 } 315 316 321 protected AbstractInterfaceDecl 322 startAbstractInterface(String name) 323 { 324 AbstractInterfaceDecl decl = new AbstractInterfaceDeclImpl(getRepository(), this); 325 decl.setName(name); 326 return decl; 327 } 328 329 334 protected ValueDecl 335 startValue(String name) 336 { 337 ValueDecl decl = new ValueDeclImpl(getRepository(), this); 338 decl.setName(name); 339 return decl; 340 } 341 342 347 protected ModuleDecl 348 startModule(String name) 349 { 350 ModuleDecl module = new ModuleDeclImpl(getRepository(), this); 351 module.setName(name); 352 return module; 353 } 354 355 360 protected ComponentDecl 361 startComponent(String name) 362 { 363 ComponentDecl decl = new ComponentDeclImpl(getRepository(), this); 364 decl.setName(name); 365 return decl; 366 } 367 368 373 protected EventDecl 374 startEvent(String name) 375 { 376 EventDecl decl = new EventDeclImpl(getRepository(), this); 377 decl.setName(name); 378 return decl; 379 } 380 381 389 protected Declaration 390 findInScope(String name) 391 { 392 Declaration decl = null; 393 for (int i=0;i<contained_decls_.size();i++) 394 { 395 decl = (Declaration)contained_decls_.get(i); 396 if (decl.getName().equalsIgnoreCase(name)) 397 return decl; 398 } 399 400 return null; 401 } 402 403 411 protected Declaration 412 findInIR3(String name) 413 { 414 Declaration decl = null; 415 org.omg.CORBA.Contained contained = getContainer().lookup(name); 416 if (contained == null) 417 return null; 418 419 return loadContained(contained); 420 } 421 422 427 abstract protected org.omg.CORBA.Container 428 getContainer(); 429 430 433 protected org.omg.CORBA.ComponentIR.ComponentDef 434 getComponentDef() 435 { 436 return null; 437 } 438 439 442 protected org.omg.CORBA.ExtValueDef 443 getExtValueDef() 444 { 445 return null; 446 } 447 448 451 protected org.omg.CORBA.ComponentIR.HomeDef 452 getHomeDef() 453 { 454 return null; 455 } 456 457 462 protected org.omg.CORBA.ComponentIR.Container 463 getComponentContainer() 464 { 465 return null; 466 } 467 468 481 protected org.omg.CORBA.ExtAttributeDef 482 createExtAttribute(AttributeDecl attribute, 483 org.omg.CORBA.IDLType type, 484 org.omg.CORBA.AttributeMode mode, 485 org.omg.CORBA.ExceptionDef [] get_exceptions, 486 org.omg.CORBA.ExceptionDef [] set_exceptions) 487 { 488 return null; 489 } 490 491 504 protected org.omg.CORBA.OperationDef 505 createOperation(OperationDecl operation, 506 org.omg.CORBA.IDLType type, 507 org.omg.CORBA.OperationMode mode, 508 org.omg.CORBA.ParameterDescription [] params, 509 org.omg.CORBA.ExceptionDef [] exceptions, 510 String [] contexts) 511 { 512 return null; 513 } 514 515 521 526 public FileScope 527 startFileScope(String filename) 528 { 529 FileScope decl = new FileScope(getRepository(), this, contained_decls_); 530 decl.setName(filename); 531 return decl; 532 } 533 534 542 public ModuleDecl 543 declareModule(String name) 544 { 545 Declaration decl = findInScope(name); 547 548 if (decl != null && decl instanceof ModuleDecl) 551 return (ModuleDecl)decl; 552 553 ModuleDeclImpl module = new ModuleDeclImpl(getRepository(), this); 555 module.setName(name); 556 557 try 559 { 560 org.omg.CORBA.Contained contained = getContainer().lookup(name); 561 if (contained!=null) 562 module.load(contained); 563 } 564 catch(org.omg.CORBA.SystemException exc) 565 { 566 } 568 569 return module; 570 } 571 572 577 public ConstantDecl 578 startConstant(String name) 579 { 580 ConstantDecl decl = new ConstantDeclImpl(getRepository(), this); 581 decl.setName(name); 582 return decl; 583 } 584 585 590 public StructDecl 591 declareStruct(String name) 592 { 593 Declaration decl = findInScope(name); 595 596 if ((decl != null) && (decl instanceof StructDecl)) 597 return (StructDecl)decl; 598 599 decl = new StructDeclImpl(getRepository(), this); 601 decl.setName(name); 602 return (StructDecl)decl; 603 } 604 605 610 public UnionDecl 611 declareUnion(String name) 612 { 613 Declaration decl = findInScope(name); 615 616 if ((decl != null) && (decl instanceof UnionDecl)) 617 return (UnionDecl)decl; 618 619 decl = new UnionDeclImpl(getRepository(), this); 621 decl.setName(name); 622 return (UnionDecl)decl; 623 } 624 625 630 public EnumDecl 631 startEnum(String name) 632 { 633 EnumDecl decl = new EnumDeclImpl(getRepository(), this); 634 decl.setName(name); 635 return decl; 636 } 637 638 643 public AliasDecl 644 startAlias(String name) 645 { 646 AliasDecl decl = new AliasDeclImpl(getRepository(), this); 647 decl.setName(name); 648 return decl; 649 } 650 651 660 public InterfaceDecl 661 declareInterface(String name) 662 { 663 Declaration decl = findInScope(name); 665 666 if (decl != null) 667 { 668 if (decl.getClass() == InterfaceDeclImpl.class) 670 return (InterfaceDecl)decl; 671 672 if (decl instanceof AbstractInterfaceDeclImpl) 674 throw new Error ("interface `" + name + 675 "' does not match forward abstract declaration"); 676 677 if (decl instanceof LocalInterfaceDeclImpl) 679 throw new Error ("interface `" + name + 680 "' does not match forward local declaration"); 681 } 682 683 decl = new InterfaceDeclImpl(getRepository(), this); 685 decl.setName(name); 686 return (InterfaceDecl)decl; 687 } 688 689 698 public AbstractInterfaceDecl 699 declareAbstractInterface(String name) 700 { 701 Declaration decl = findInScope(name); 703 704 if (decl != null) 705 { 706 if (decl instanceof AbstractInterfaceDeclImpl) 708 return (AbstractInterfaceDecl)decl; 709 710 if (decl instanceof LocalInterfaceDeclImpl) 712 throw new Error ("interface `" + name + 713 "' does not match forward local declaration"); 714 715 if (decl instanceof InterfaceDeclImpl) 717 throw new Error ("interface `" + name + 718 "' does not match forward declaration"); 719 } 720 721 decl = new AbstractInterfaceDeclImpl(getRepository(), this); 723 decl.setName(name); 724 return (AbstractInterfaceDecl)decl; 725 } 726 727 736 public LocalInterfaceDecl 737 declareLocalInterface(String name) 738 { 739 Declaration decl = findInScope(name); 741 742 if (decl != null) 743 { 744 if (decl instanceof LocalInterfaceDeclImpl) 746 return (LocalInterfaceDecl)decl; 747 748 if (decl instanceof AbstractInterfaceDeclImpl) 750 throw new Error ("interface `" + name + 751 "' does not match forward abstract declaration"); 752 753 if (decl instanceof InterfaceDeclImpl) 755 throw new Error ("interface `" + name + 756 "' does not match forward declaration"); 757 } 758 759 decl = new LocalInterfaceDeclImpl(getRepository(), this); 761 decl.setName(name); 762 return (LocalInterfaceDecl)decl; 763 } 764 765 773 public ValueDecl 774 declareValue(String name) 775 { 776 Declaration decl = findInScope(name); 778 779 if ((decl != null) && (decl instanceof ValueDecl)) 780 return (ValueDecl)decl; 781 782 decl = new ValueDeclImpl(getRepository(), this); 784 decl.setName(name); 785 return (ValueDecl)decl; 786 } 787 788 793 public Initializer 794 startInitializer(String name) 795 { 796 Initializer init = new InitializerImpl(); 797 init.setName(name); 798 return init; 799 } 800 801 809 public EventDecl 810 declareEvent(String name) 811 { 812 Declaration decl = findInScope(name); 814 815 if ((decl != null) && (decl instanceof EventDecl)) 816 return (EventDecl)decl; 817 818 decl = new EventDeclImpl(getRepository(), this); 820 decl.setName(name); 821 return (EventDecl)decl; 822 } 823 824 829 public ValueMemberDecl 830 startValueMember(String name) 831 { 832 ValueMemberDecl decl = new ValueMemberDeclImpl(getRepository(), this); 833 decl.setName(name); 834 return decl; 835 } 836 837 842 public ValueBoxDecl 843 startValueBox(String name) 844 { 845 ValueBoxDecl decl = new ValueBoxDeclImpl(getRepository(), this); 846 decl.setName(name); 847 return decl; 848 } 849 850 855 public ExceptionDecl 856 startException(String name) 857 { 858 ExceptionDecl decl = new ExceptionDeclImpl(getRepository(), this); 859 decl.setName(name); 860 return decl; 861 } 862 863 868 public NativeDecl 869 startNative(String name) 870 { 871 NativeDecl decl = new NativeDeclImpl(getRepository(), this); 872 decl.setName(name); 873 return decl; 874 } 875 876 881 public AttributeDecl 882 startAttribute(String name) 883 { 884 AttributeDecl decl = new AttributeDeclImpl(getRepository(), this); 885 decl.setName(name); 886 return decl; 887 } 888 889 894 public OperationDecl 895 startOperation(String name) 896 { 897 OperationDecl decl = new OperationDeclImpl(getRepository(), this); 898 decl.setName(name); 899 return decl; 900 } 901 902 907 public FactoryDecl 908 startFactory(String name) 909 { 910 FactoryDecl decl = new FactoryDeclImpl(getRepository(), this); 911 decl.setName(name); 912 return decl; 913 } 914 915 920 public FinderDecl 921 startFinder(String name) 922 { 923 FinderDecl decl = new FinderDeclImpl(getRepository(), this); 924 decl.setName(name); 925 return decl; 926 } 927 928 933 public ProvidesDecl 934 startProvides(String name) 935 { 936 ProvidesDecl decl = new ProvidesDeclImpl(getRepository(), this); 937 decl.setName(name); 938 return decl; 939 } 940 941 946 public UsesDecl 947 startUses(String name) 948 { 949 UsesDecl decl = new UsesDeclImpl(getRepository(), this); 950 decl.setName(name); 951 return decl; 952 } 953 954 959 public ConsumesDecl 960 startConsumes(String name) 961 { 962 ConsumesDecl decl = new ConsumesDeclImpl(getRepository(), this); 963 decl.setName(name); 964 return decl; 965 } 966 967 972 public EmitsDecl 973 startEmits(String name) 974 { 975 EmitsDecl decl = new EmitsDeclImpl(getRepository(), this); 976 decl.setName(name); 977 return decl; 978 } 979 980 985 public PublishesDecl 986 startPublishes(String name) 987 { 988 PublishesDecl decl = new PublishesDeclImpl(getRepository(), this); 989 decl.setName(name); 990 return decl; 991 } 992 993 1002 public ComponentDecl 1003 declareComponent(String name) 1004 { 1005 Declaration decl = findInScope(name); 1007 1008 if ((decl != null) && (decl instanceof ComponentDecl)) 1009 return (ComponentDecl)decl; 1010 1011 decl = new ComponentDeclImpl(getRepository(), this); 1013 decl.setName(name); 1014 return (ComponentDecl)decl; 1015 } 1016 1017 1022 public HomeDecl 1023 startHome(String name) 1024 { 1025 HomeDecl decl = new HomeDeclImpl(getRepository(), this); 1026 decl.setName(name); 1027 return decl; 1028 } 1029 1030 1042 public Declaration 1043 find(String name) 1044 { 1045 Declaration decl = findInScope(name); 1046 if (decl != null) return decl; 1048 1049 if (the_parent_!=null) 1051 decl = the_parent_.find(name); 1052 1053 if (decl != null) return decl; 1055 1056 return findInIR3(name); 1057 } 1058 1059 1065 1073 public Declaration[] 1074 getContents(boolean exclude_inherited, int limited_types) 1075 { 1076 if (!content_loaded_) 1077 { 1078 if (is_mapping_) 1081 getRepository().useIDL2Repository(); 1082 1083 org.omg.CORBA.Contained [] content = getContainer().contents(org.omg.CORBA.DefinitionKind.dk_all, true); 1084 1085 org.objectweb.ccm.util.Vector ordered_decls = new org.objectweb.ccm.util.Vector(); 1089 Declaration decl = null; 1090 contained_decls_.clear(); 1091 1092 1095 for (int i=0;i<content.length;i++) 1096 { 1097 decl = findInScope(content[i].name()); 1099 if (decl==null) 1100 { 1101 if (is_mapping_) 1102 decl = loadContainedAsMapping(content[i]); 1103 else 1104 decl = loadContained(content[i]); 1105 } 1106 1107 ordered_decls.add(decl); 1109 } 1110 1111 contained_decls_ = ordered_decls; 1112 1113 if (is_mapping_) 1115 getRepository().useIDL3Repository(); 1116 1117 content_loaded_ = true; 1118 } 1119 1120 Declaration decl = null; 1121 org.objectweb.ccm.util.Vector selection = new org.objectweb.ccm.util.Vector(); 1122 for (int i=0;i<contained_decls_.size();i++) 1123 { 1124 decl = (Declaration)contained_decls_.get(i); 1125 if ((decl.getDeclKind()&limited_types)!=0) 1126 selection.add(decl); 1127 } 1128 return (Declaration[])selection.toArray(new Declaration[0]); 1129 } 1130 1131 1138 public Declaration 1139 lookup(String scoped_name) 1140 { 1141 int idx = scoped_name.indexOf("::"); 1142 String s1 = null; 1143 String s2 = null; 1144 if (idx==-1) 1145 { 1146 s1 = scoped_name; 1147 s2 = ""; 1148 } 1149 else 1150 { 1151 s1 = scoped_name.substring(0,idx); 1152 s2 = scoped_name.substring(idx+2); 1153 } 1154 1155 Declaration decl = findInScope(s1); 1156 if (decl==null) 1157 { 1158 decl = findInIR3(s1); 1160 } 1161 1162 if (s2.equals("")) 1163 return decl; 1164 1165 if (decl instanceof Scope) 1166 return ((Scope)decl).lookup(s2); 1167 1168 return null; 1169 } 1170 1171 1177 1180 public void 1181 destroy() 1182 { 1183 Declaration decl = null; 1184 for (int i=contained_decls_.size()-1;i>=0;i--) 1185 { 1186 decl = (Declaration)contained_decls_.get(i); 1187 decl.destroy(); 1188 } 1189 1190 if (contained_decls_.size()==0) 1192 super.destroy(); 1193 } 1194} 1195 | Popular Tags |