| 1 26 27 package org.objectweb.openccm.ast.lib; 28 29 30 import org.objectweb.openccm.ast.api.ASTError; 31 32 33 import org.objectweb.openccm.ast.api.*; 34 35 46 47 abstract public class ScopeImpl 48 extends DeclarationImpl 49 implements org.objectweb.openccm.ast.api.Scope 50 { 51 57 61 protected java.util.List contained_decls_; 62 63 64 protected boolean content_loaded_; 65 66 72 78 protected 79 ScopeImpl(Repository rep, 80 ScopeImpl parent) 81 { 82 super(rep, parent); 84 85 contained_decls_ = new java.util.ArrayList (); 87 content_loaded_ = false; 88 } 89 90 96 101 protected void 102 addDecl(Declaration decl) 103 { 104 Declaration current = null; 106 String name = decl.getName(); 107 for (int i=0;i<contained_decls_.size();i++) 108 { 109 current = (Declaration)contained_decls_.get(i); 110 if (current.getName().equalsIgnoreCase(name)) 111 return; } 113 contained_decls_.add(decl); 115 } 116 117 124 protected boolean 125 containsDecl(Declaration decl) 126 { 127 return ( decl.getAbsoluteName().startsWith(getAbsoluteName()+"::") ); 128 } 129 130 133 protected void 134 removeDecl(String name) 135 { 136 Declaration decl = null; 137 for (int i=0;i<contained_decls_.size();i++) 138 { 139 decl = (Declaration)contained_decls_.get(i); 140 if (decl.getName().equalsIgnoreCase(name)) 141 contained_decls_.remove(i); 142 } 143 } 144 145 148 protected Declaration 149 createDeclaration(int kind, 150 java.lang.String name) 151 { 152 Declaration decl = null; 153 switch (kind) 154 { 155 case org.omg.CORBA.DefinitionKind._dk_Interface : 157 decl = startInterface(name); 158 break; 159 case org.omg.CORBA.DefinitionKind._dk_LocalInterface : 160 decl = startLocalInterface(name); 161 break; 162 case org.omg.CORBA.DefinitionKind._dk_AbstractInterface : 163 decl = startAbstractInterface(name); 164 break; 165 case org.omg.CORBA.DefinitionKind._dk_Module : 166 decl = startModule(name); 167 break; 168 case org.omg.CORBA.DefinitionKind._dk_Struct : 169 decl = startStruct(name); 170 break; 171 case org.omg.CORBA.DefinitionKind._dk_Value : 172 decl = startValue(name); 173 break; 174 case org.omg.CORBA.DefinitionKind._dk_Union : 175 decl = startUnion(name); 176 break; 177 case org.omg.CORBA.DefinitionKind._dk_Exception : 178 decl = startException(name); 179 break; 180 case org.omg.CORBA.DefinitionKind._dk_Constant : 181 decl = startConstant(name); 182 break; 183 case org.omg.CORBA.DefinitionKind._dk_Enum : 184 decl = startEnum(name); 185 break; 186 case org.omg.CORBA.DefinitionKind._dk_Alias : 187 decl = startAlias(name); 188 break; 189 case org.omg.CORBA.DefinitionKind._dk_Attribute : 190 decl = startAttribute(name); 191 break; 192 case org.omg.CORBA.DefinitionKind._dk_Operation : 193 decl = startOperation(name); 194 break; 195 case org.omg.CORBA.DefinitionKind._dk_ValueBox : 196 decl = startValueBox(name); 197 break; 198 case org.omg.CORBA.DefinitionKind._dk_Native : 199 decl = startNative(name); 200 break; 201 case org.omg.CORBA.DefinitionKind._dk_ValueMember : 202 decl = startValueMember(name); 203 break; 204 205 case org.omg.CORBA.DefinitionKind._dk_Component : 207 decl = startComponent(name); 208 break; 209 case org.omg.CORBA.DefinitionKind._dk_Home : 210 decl = startHome(name); 211 break; 212 case org.omg.CORBA.DefinitionKind._dk_Factory : 213 decl = startFactory(name); 214 break; 215 case org.omg.CORBA.DefinitionKind._dk_Finder : 216 decl = startFinder(name); 217 break; 218 case org.omg.CORBA.DefinitionKind._dk_Emits : 219 decl = startEmits(name); 220 break; 221 case org.omg.CORBA.DefinitionKind._dk_Publishes : 222 decl = startPublishes(name); 223 break; 224 case org.omg.CORBA.DefinitionKind._dk_Consumes : 225 decl = startConsumes(name); 226 break; 227 case org.omg.CORBA.DefinitionKind._dk_Provides : 228 decl = startProvides(name); 229 break; 230 case org.omg.CORBA.DefinitionKind._dk_Uses : 231 decl = startUses(name); 232 break; 233 case org.omg.CORBA.DefinitionKind._dk_Event : 234 decl = startEvent(name); 235 break; 236 default : 237 throw new ASTError(""); 239 } 240 241 return decl; 242 } 243 244 251 protected Declaration 252 loadContained(org.omg.CORBA.Contained contained) 253 { 254 DeclarationImpl decl = (DeclarationImpl) 255 createDeclaration(contained.def_kind().value(), contained.name()); 256 decl.load(contained); 257 decl.setImported(); 258 return decl; 259 } 260 261 268 protected Declaration 269 loadContainedAsMapping(org.omg.CORBA.Contained contained) 270 { 271 DeclarationImpl decl = (DeclarationImpl) 272 createDeclaration(contained.def_kind().value(), contained.name()); 273 decl.loadAsMapping(contained); 274 return decl; 275 } 276 277 284 protected StructDecl 285 startStruct(String name) 286 { 287 StructDecl decl = new StructDeclImpl(getRepository(), this); 288 decl.setName(name); 289 return decl; 290 } 291 292 299 protected UnionDecl 300 startUnion(String name) 301 { 302 UnionDecl decl = new UnionDeclImpl(getRepository(), this); 303 decl.setName(name); 304 return decl; 305 } 306 307 314 protected InterfaceDecl 315 startInterface(String name) 316 { 317 InterfaceDecl decl = new InterfaceDeclImpl(getRepository(), this); 318 decl.setName(name); 319 return decl; 320 } 321 322 329 protected LocalInterfaceDecl 330 startLocalInterface(String name) 331 { 332 LocalInterfaceDecl decl = new LocalInterfaceDeclImpl( 333 getRepository(), this); 334 decl.setName(name); 335 return decl; 336 } 337 338 345 protected AbstractInterfaceDecl 346 startAbstractInterface(String name) 347 { 348 AbstractInterfaceDecl decl = new AbstractInterfaceDeclImpl( 349 getRepository(), this); 350 decl.setName(name); 351 return decl; 352 } 353 354 361 protected ValueDecl 362 startValue(String name) 363 { 364 ValueDecl decl = new ValueDeclImpl(getRepository(), this); 365 decl.setName(name); 366 return decl; 367 } 368 369 376 protected ModuleDecl 377 startModule(String name) 378 { 379 ModuleDecl module = new ModuleDeclImpl(getRepository(), this); 380 module.setName(name); 381 return module; 382 } 383 384 391 protected ComponentDecl 392 startComponent(String name) 393 { 394 ComponentDecl decl = new ComponentDeclImpl(getRepository(), this); 395 decl.setName(name); 396 return decl; 397 } 398 399 406 protected EventDecl 407 startEvent(String name) 408 { 409 EventDecl decl = new EventDeclImpl(getRepository(), this); 410 decl.setName(name); 411 return decl; 412 } 413 414 422 protected Declaration 423 findInScope(String name) 424 { 425 Declaration decl = null; 426 for (int i=0;i<contained_decls_.size();i++) 427 { 428 decl = (Declaration)contained_decls_.get(i); 429 if (decl.getName().equalsIgnoreCase(name)) 430 return decl; 431 } 432 return null; 433 } 434 435 443 protected Declaration 444 findInIR3(String name) 445 { 446 org.omg.CORBA.Container container = getContainer(); 447 if (container == null) 448 return null; 449 450 org.omg.CORBA.Contained contained = container.lookup(name); 451 if (contained == null) 452 return null; 453 454 return loadContained(contained); 455 } 456 457 462 protected org.omg.CORBA.Container  463 getContainer() 464 { 465 return null; 467 } 468 469 472 protected org.omg.CORBA.ComponentIR.ComponentDef 473 getComponentDef() 474 { 475 return null; 477 } 478 479 482 protected org.omg.CORBA.ExtValueDef 483 getExtValueDef() 484 { 485 return null; 487 } 488 489 492 protected org.omg.CORBA.ComponentIR.HomeDef 493 getHomeDef() 494 { 495 return null; 497 } 498 499 504 protected org.omg.CORBA.ComponentIR.Container 505 getComponentContainer() 506 { 507 return null; 509 } 510 511 524 protected org.omg.CORBA.ExtAttributeDef 525 createExtAttribute(AttributeDecl attribute, 526 org.omg.CORBA.IDLType type, 527 org.omg.CORBA.AttributeMode mode, 528 org.omg.CORBA.ExceptionDef [] get_exceptions, 529 org.omg.CORBA.ExceptionDef [] set_exceptions) 530 { 531 return null; 533 } 534 535 548 protected org.omg.CORBA.OperationDef  549 createOperation(OperationDecl operation, 550 org.omg.CORBA.IDLType type, 551 org.omg.CORBA.OperationMode mode, 552 org.omg.CORBA.ParameterDescription [] params, 553 org.omg.CORBA.ExceptionDef [] exceptions, 554 String [] contexts) 555 { 556 return null; 558 } 559 560 566 572 575 public void 576 destroy() 577 { 578 Declaration decl = null; 579 for (int i=contained_decls_.size()-1;i>=0;i--) 580 { 581 decl = (Declaration)contained_decls_.get(i); 582 decl.destroy(); 583 } 584 585 if (contained_decls_.size()==0) 587 super.destroy(); 588 } 589 590 596 603 public FileScope 604 startFileScope(String filename) 605 { 606 FileScope decl = new FileScopeImpl(getRepository(), 607 this, 608 contained_decls_); 609 decl.setFileName(filename); 610 return decl; 611 } 612 613 620 public ConstantDecl 621 startConstant(String name) 622 { 623 ConstantDecl decl = new ConstantDeclImpl(getRepository(), this); 624 decl.setName(name); 625 return decl; 626 } 627 628 636 public StructDecl 637 declareStruct(String name) 638 { 639 Declaration decl = findInScope(name); 641 642 if ((decl != null) && (decl instanceof StructDecl)) 643 return (StructDecl)decl; 644 645 return startStruct(name); 647 } 648 649 657 public UnionDecl 658 declareUnion(String name) 659 { 660 Declaration decl = findInScope(name); 662 663 if ((decl != null) && (decl instanceof UnionDecl)) 664 return (UnionDecl)decl; 665 666 return startUnion(name); 668 } 669 670 677 public EnumDecl 678 startEnum(String name) 679 { 680 EnumDecl decl = new EnumDeclImpl(getRepository(), this); 681 decl.setName(name); 682 return decl; 683 } 684 685 692 public AliasDecl 693 startAlias(String name) 694 { 695 AliasDecl decl = new AliasDeclImpl(getRepository(), this); 696 decl.setName(name); 697 return decl; 698 } 699 700 708 public ModuleDecl 709 declareModule(String name) 710 { 711 713 Declaration decl = findInScope(name); 715 716 if(decl != null && decl instanceof ModuleDecl) 719 { 720 return (ModuleDecl)decl; 721 } 722 723 ModuleDeclImpl module = (ModuleDeclImpl)startModule(name); 725 726 try 728 { 729 org.omg.CORBA.Contained contained = getContainer().lookup(name); 730 if (contained!=null) 731 module.load(contained); 732 } 733 catch(org.omg.CORBA.SystemException exc) 734 { 735 } 737 738 return module; 739 } 740 741 749 public InterfaceDecl 750 declareInterface(String name) 751 { 752 Declaration decl = findInScope(name); 754 755 if (decl != null) 756 { 757 if (decl.getClass() == InterfaceDeclImpl.class) 759 return (InterfaceDecl)decl; 760 761 if (decl instanceof AbstractInterfaceDeclImpl) 763 throw new ASTError("interface `" + name + 764 "' does not match forward abstract declaration"); 765 766 if (decl instanceof LocalInterfaceDeclImpl) 768 throw new ASTError("interface `" + name + 769 "' does not match forward local declaration"); 770 } 771 772 return startInterface(name); 774 } 775 776 784 public LocalInterfaceDecl 785 declareLocalInterface(String name) 786 { 787 Declaration decl = findInScope(name); 789 790 if (decl != null) 791 { 792 if (decl instanceof LocalInterfaceDeclImpl) 794 return (LocalInterfaceDecl)decl; 795 796 if (decl instanceof AbstractInterfaceDeclImpl) 798 throw new ASTError("interface `" + name + 799 "' does not match forward abstract declaration"); 800 801 if (decl instanceof InterfaceDeclImpl) 803 throw new ASTError("interface `" + name + 804 "' does not match forward declaration"); 805 } 806 807 return startLocalInterface(name); 809 } 810 811 819 public AbstractInterfaceDecl 820 declareAbstractInterface(String name) 821 { 822 Declaration decl = findInScope(name); 824 825 if (decl != null) 826 { 827 if (decl instanceof AbstractInterfaceDeclImpl) 829 return (AbstractInterfaceDecl)decl; 830 831 if (decl instanceof LocalInterfaceDeclImpl) 833 throw new ASTError("interface `" + name + 834 "' does not match forward local declaration"); 835 836 if (decl instanceof InterfaceDeclImpl) 838 throw new ASTError("interface `" + name + 839 "' does not match forward declaration"); 840 } 841 842 return startAbstractInterface(name); 844 } 845 846 854 public ValueDecl 855 declareValue(String name) 856 { 857 Declaration decl = findInScope(name); 859 860 if ((decl != null) && (decl instanceof ValueDecl)) 861 return (ValueDecl)decl; 862 863 return startValue(name); 865 } 866 867 874 public Initializer 875 startInitializer(String name) 876 { 877 Initializer init = new InitializerImpl(); 878 init.setName(name); 879 return init; 880 } 881 882 889 public ValueMemberDecl 890 startValueMember(String name) 891 { 892 ValueMemberDecl decl = new ValueMemberDeclImpl(getRepository(), this); 893 decl.setName(name); 894 return decl; 895 } 896 897 904 public ValueBoxDecl 905 startValueBox(String name) 906 { 907 ValueBoxDecl decl = new ValueBoxDeclImpl(getRepository(), this); 908 decl.setName(name); 909 return decl; 910 } 911 912 919 public ExceptionDecl 920 startException(String name) 921 { 922 ExceptionDecl decl = new ExceptionDeclImpl(getRepository(), this); 923 decl.setName(name); 924 return decl; 925 } 926 927 934 public NativeDecl 935 startNative(String name) 936 { 937 NativeDecl decl = new NativeDeclImpl(getRepository(), this); 938 decl.setName(name); 939 return decl; 940 } 941 942 949 public AttributeDecl 950 startAttribute(String name) 951 { 952 AttributeDecl decl = new AttributeDeclImpl(getRepository(), this); 953 decl.setName(name); 954 return decl; 955 } 956 957 964 public OperationDecl 965 startOperation(String name) 966 { 967 OperationDecl decl = new OperationDeclImpl(getRepository(), this); 968 decl.setName(name); 969 return decl; 970 } 971 972 980 public EventDecl 981 declareEvent(String name) 982 { 983 Declaration decl = findInScope(name); 985 <
|