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.DeclarationKind; 34 35 36 import org.objectweb.openccm.ast.api.Declaration; 37 38 39 import org.objectweb.openccm.ast.api.ComponentDecl; 40 41 42 import org.objectweb.openccm.ast.api.InterfaceDecl; 43 44 45 import org.omg.CORBA.ComponentIR.ComponentDef; 46 import org.omg.CORBA.ComponentIR.ComponentDefHelper; 47 48 80 81 public class ComponentDeclImpl 82 extends ComponentBaseImpl 83 implements ComponentDecl 84 { 85 91 92 private ComponentDef component_def_; 93 94 95 private ComponentDeclImpl base_component_; 96 97 98 private InterfaceDeclImpl local_context_mapping_; 99 100 101 private InterfaceDeclImpl local_monolithic_mapping_; 102 103 104 private InterfaceDeclImpl local_main_mapping_; 105 106 112 118 protected 119 ComponentDeclImpl(Repository rep, 120 ScopeImpl parent) 121 { 122 super(rep, parent); 124 125 component_def_ = null; 127 base_component_ = null; 128 local_context_mapping_ = null; 129 local_monolithic_mapping_ = null; 130 local_main_mapping_ = null; 131 } 132 133 139 145 150 protected void 151 load(org.omg.CORBA.Contained contained) 152 { 153 component_def_ = ComponentDefHelper.narrow(contained); 154 155 ComponentDef baseComponent = component_def_.base_component(); 156 if (baseComponent!=null) 157 setBaseComponent( 158 (ComponentDecl)getRepository(). 159 lookupId(baseComponent.id())); 160 161 addSupportedInterfaces(component_def_.supported_interfaces()); 162 163 getClientMapping(); 165 getLocalContextMapping(); 166 167 super.load(contained); 168 } 169 170 176 protected org.omg.CORBA.Contained 177 getContained() 178 { 179 return component_def_; 180 } 181 182 188 194 protected org.omg.CORBA.Container 195 getContainer() 196 { 197 return component_def_; 198 } 199 200 206 212 215 protected void 216 createContainer() 217 { 218 221 component_def_ = the_parent_.getComponentContainer(). 222 create_component(getId(), 223 getName(), 224 getVersion(), 225 getBaseComponentDef(), 226 supported_interfaces_.getInterfaceDefSeq()); 227 } 228 229 232 protected void 233 completeContainer() 234 { 235 ComponentDef baseComponent = getBaseComponentDef(); 236 if (baseComponent != null) 237 component_def_.base_component(baseComponent); 238 239 if (supported_interfaces_.getSize() != 0) 240 component_def_.supported_interfaces( 241 supported_interfaces_.getInterfaceDefSeq()); 242 } 243 244 250 256 public ComponentDef 257 getComponentDef() 258 { 259 return component_def_; 260 } 261 262 267 public ComponentDef 268 getBaseComponentDef() 269 { 270 return (base_component_ != null) 271 ? (base_component_.getComponentDef()) : null; 272 } 273 274 280 public org.omg.CORBA.ExtInterfaceDef 281 getExtInterfaceDef() 282 { 283 return component_def_; 284 } 285 286 292 public org.omg.CORBA.InterfaceDef 293 getInterfaceDef() 294 { 295 return component_def_; 296 } 297 298 304 312 public Declaration[] 313 getDependencies() 314 { 315 if (dependencies_!=null) 316 return dependencies_; 317 318 dependencies_ = new Declaration[0]; 319 java.util.List comp_depend = new java.util.ArrayList (); 320 Declaration[] depend = null; 321 322 if (getBaseComponent()!=null) 324 { 325 comp_depend.add(getBaseComponent()); 326 depend = getBaseComponent().getDependencies(); 327 for (int j=0; j<depend.length; j++) 328 { 329 if (depend[j]!=this) 330 comp_depend.add(depend[j]); 331 } 332 } 333 334 InterfaceDecl[] supp = supported_interfaces_.getInterfaces(); 336 for (int i=0; i<supp.length; i++) 337 { 338 comp_depend.add(supp[i]); 339 depend = supp[i].getDependencies(); 340 for (int j=0; j<depend.length; j++) 341 { 342 if ( (depend[j]!=this) && 343 (comp_depend.indexOf(depend[j])==-1) ) 344 comp_depend.add(depend[j]); 345 } 346 } 347 348 Declaration[] decls = getContents(true, DeclarationKind.dk_all); 350 for (int i=0; i<decls.length; i++) 351 { 352 depend = decls[i].getDependencies(); 353 for (int j=0; j<depend.length; j++) 354 { 355 if ( (!containsDecl(depend[j])) && 358 (depend[j]!=this) && 359 (comp_depend.indexOf(depend[j])==-1) ) 360 { 361 comp_depend.add(depend[j]); 362 } 363 } 364 } 365 366 dependencies_ = (Declaration[])comp_depend.toArray(new Declaration[0]); 367 return dependencies_; 368 } 369 370 376 381 public long 382 getDeclKind() 383 { 384 return DeclarationKind.dk_component; 385 } 386 387 393 404 public Declaration 405 find(String name) 406 { 407 Declaration decl = super.find(name); 409 410 if(decl != null) return decl; 412 413 if (base_component_ != null) 415 { 416 decl = base_component_.find(name); 417 418 if(decl != null) return decl; 420 } 421 422 return supported_interfaces_.find(name); 424 } 425 426 435 public Declaration[] 436 getContents(boolean exclude_inherited, 437 long limited_types) 438 { 439 if (exclude_inherited) 440 return super.getContents(exclude_inherited, limited_types); 441 442 Declaration[] res = super.getContents(exclude_inherited, limited_types); 443 InterfaceDecl[] itfs = supported_interfaces_.getInterfaces(); 444 for (int i=0; i<itfs.length; i++) 445 { 446 Declaration[] tmp1 = itfs[i].getContents(exclude_inherited, limited_types); 447 Declaration[] tmp2 = res; 448 res = new Declaration[tmp1.length+tmp2.length]; 449 System.arraycopy(tmp2, 0, res, 0, tmp2.length); 450 System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length); 451 } 452 453 if (base_component_==null) 454 return res; 455 456 Declaration[] tmp1 = base_component_.getContents(exclude_inherited, limited_types); 457 Declaration[] tmp2 = res; 458 res = new Declaration[tmp1.length+tmp2.length]; 459 System.arraycopy(tmp2, 0, res, 0, tmp2.length); 460 System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length); 461 return res; 462 } 463 464 470 476 481 public TypeKind 482 getTypeKind() 483 { 484 return TypeKind.tk_component; 485 } 486 487 493 499 504 public org.omg.CORBA.IDLType 505 getIDLType() 506 { 507 return component_def_; 508 } 509 510 516 521 public InterfaceDecl 522 getClientMapping() 523 { 524 if (client_mapping_ == null) 525 { 526 client_mapping_ = (InterfaceDeclImpl)getRepository(). 528 loadMapping(getParent(), getId()); 529 } 530 return client_mapping_; 531 } 532 533 539 546 public void 547 setBaseComponent(ComponentDecl base_component) 548 { 549 if (base_component != null) 550 { 551 base_component_ = (ComponentDeclImpl)base_component; 552 } 553 } 554 555 560 public ComponentDecl 561 getBaseComponent() 562 { 563 return base_component_; 564 } 565 566 571 public InterfaceDecl 572 getLocalContextMapping() 573 { 574 if (local_context_mapping_ == null) 575 { 576 String parent_base_id = the_parent_.getId(); 578 int idx = parent_base_id.lastIndexOf(':'); 579 parent_base_id = parent_base_id.substring(0, idx); 580 String id = parent_base_id + "/CCM_" + getName() + 581 "_Context:" + getVersion(); 582 local_context_mapping_ = (InterfaceDeclImpl)getRepository(). 583 loadMapping(getParent(), id); 584 } 585 return local_context_mapping_; 586 } 587 588 593 public InterfaceDecl 594 getLocalMonolithicMapping() 595 { 596 if (local_monolithic_mapping_ == null) 597 { 598 String parent_base_id = the_parent_.getId(); 600 int idx = parent_base_id.lastIndexOf(':'); 601 parent_base_id = parent_base_id.substring(0, idx); 602 String id = parent_base_id + "/CCM_" + getName() + 603 ':' + getVersion(); 604 605 local_monolithic_mapping_ = (InterfaceDeclImpl)getRepository(). 606 loadMapping(getParent(), id); 607 } 608 return local_monolithic_mapping_; 609 } 610 611 616 public InterfaceDecl 617 getLocalMainMapping() 618 { 619 if (local_main_mapping_ == null) 620 { 621 String parent_base_id = the_parent_.getId(); 623 int idx = parent_base_id.lastIndexOf(':'); 624 parent_base_id = parent_base_id.substring(0, idx); 625 String id = parent_base_id + "/CCM_" + getName() + 626 "_Executor:" + getVersion(); 627 628 local_main_mapping_ = (InterfaceDeclImpl)getRepository(). 629 loadMapping(getParent(), id); 630 } 631 return local_main_mapping_; 632 } 633 } 634 | Popular Tags |