1 26 27 package org.objectweb.ccm.IDL3; 28 29 37 38 public class ComponentDeclImpl 39 extends InterfaceDeclImpl 40 implements ComponentRef, ComponentDecl 41 { 42 48 51 private org.omg.CORBA.ComponentIR.ComponentDef component_def_; 52 53 56 private ComponentDeclImpl base_component_; 57 58 61 private org.objectweb.ccm.util.Vector supported_interfaces_; 62 63 66 private InterfaceDeclImpl client_mapping_; 67 68 71 private InterfaceDeclImpl local_context_mapping_; 72 73 76 private InterfaceDeclImpl local_monolithic_mapping_; 77 78 81 private InterfaceDeclImpl local_main_mapping_; 82 83 89 94 protected 95 ComponentDeclImpl(Repository rep, ScopeImpl parent) 96 { 97 super(rep, parent); 99 100 component_def_ = null; 102 base_component_ = null; 103 client_mapping_ = null; 104 local_context_mapping_ = null; 105 local_monolithic_mapping_ = null; 106 local_main_mapping_ = null; 107 supported_interfaces_ = new org.objectweb.ccm.util.Vector(); 108 the_declaration_kind_ = DeclarationKind._dk_component; 109 } 110 111 117 122 protected org.omg.CORBA.InterfaceDef [] 123 getInterfaceDefs() 124 { 125 org.omg.CORBA.InterfaceDef [] result = 126 new org.omg.CORBA.InterfaceDef [supported_interfaces_.size()]; 127 128 for(int i=0; i<result.length; i++) 129 { 130 result[i] = ((InterfaceRef)(supported_interfaces_.get(i))).getExtInterfaceDef(); 131 } 132 133 return result; 134 } 135 136 141 protected org.omg.CORBA.ComponentIR.ComponentDef 142 getBaseComponentDef() 143 { 144 return (base_component_ != null) 145 ? (base_component_.getComponentDef()) : null; 146 } 147 148 153 protected void 154 load(org.omg.CORBA.Contained contained) 155 { 156 component_def_ = org.omg.CORBA.ComponentIR.ComponentDefHelper.narrow(contained); 157 if (component_def_.base_component()!=null) 158 setBaseComponent( 159 (ComponentRef)getRepository().lookupId(component_def_.base_component().id())); 160 161 org.omg.CORBA.InterfaceDef [] supported = component_def_.supported_interfaces(); 162 for (int i=0;i<supported.length;i++) 163 addSupportedInterface((InterfaceRef)getRepository().lookupId(supported[i].id())); 165 166 getClientMapping(); 168 getLocalContextMapping(); 169 170 super.load(contained); 171 } 172 173 180 protected Declaration 181 findInSupportedInterfaces(String name) 182 { 183 for(int i=0; i<supported_interfaces_.size(); i++) 184 { 185 Declaration decl = ((InterfaceDecl)(supported_interfaces_.get(i))).find(name); 186 if (decl != null) return decl; 188 } 189 190 return null; 192 } 193 194 200 211 public Declaration 212 find(String name) 213 { 214 Declaration decl = super.find(name); 216 if(decl != null) return decl; 218 219 if (base_component_ != null) 221 { 222 decl = base_component_.find(name); 223 if(decl != null) return decl; 225 } 226 return findInSupportedInterfaces(name); 228 } 229 230 237 public Declaration[] 238 getDependencies() 239 { 240 if (dependencies_!=null) 241 return dependencies_; 242 243 dependencies_ = new Declaration[0]; 244 org.objectweb.ccm.util.Vector comp_depend = new org.objectweb.ccm.util.Vector(); 245 Declaration[] depend = null; 246 247 if (getBaseComponent()!=null) 249 { 250 comp_depend.add(getBaseComponent()); 251 depend = getBaseComponent().getDependencies(); 252 for (int j=0;j<depend.length;j++) 253 { 254 if (depend[j]!=this) 255 comp_depend.add(depend[j]); 256 } 257 } 258 259 InterfaceDecl[] supp = getSupportedInterfaces(); 261 for (int i=0;i<supp.length;i++) 262 { 263 comp_depend.add(supp[i]); 264 depend = supp[i].getDependencies(); 265 for (int j=0;j<depend.length;j++) 266 { 267 if ((depend[j]!=this) && 268 (comp_depend.indexOf(depend[j])==-1)) 269 comp_depend.add(depend[j]); 270 } 271 } 272 273 Declaration[] decls = getContents(true, org.objectweb.ccm.IDL3.DeclarationKind._dk_all); 275 for (int i=0;i<decls.length;i++) 276 { 277 depend = decls[i].getDependencies(); 278 for (int j=0;j<depend.length;j++) 279 { 280 if ((!containsDecl(depend[j])) && 281 (depend[j]!=this) && 282 (comp_depend.indexOf(depend[j])==-1)) 283 comp_depend.add(depend[j]); 284 } 285 } 286 287 dependencies_ = (Declaration[])comp_depend.toArray(new Declaration[0]); 288 return dependencies_; 289 } 290 291 297 302 public org.omg.CORBA.IDLType 303 getIDLType() 304 { 305 return component_def_; 306 } 307 308 311 public int 312 getTypeKind() 313 { 314 return TypeKind._tk_component; 315 } 316 317 323 329 public org.omg.CORBA.ExtInterfaceDef 330 getExtInterfaceDef() 331 { 332 return component_def_; 333 } 334 335 341 public org.omg.CORBA.InterfaceDef 342 getInterfaceDef() 343 { 344 return component_def_; 345 } 346 347 353 359 public org.omg.CORBA.ComponentIR.ComponentDef 360 getComponentDef() 361 { 362 return component_def_; 363 } 364 365 371 377 382 public void 383 addSupportedInterface(InterfaceRef itf) 384 { 385 if(itf != null) 386 { 387 itf.addRef(); 388 supported_interfaces_.add(itf); 389 } 390 } 391 392 399 public void 400 setBaseComponent(ComponentRef base_component) 401 { 402 if (base_component != null) 403 { 404 base_component_ = (ComponentDeclImpl)base_component; 405 base_component_.addRef(); 406 } 407 } 408 409 412 public ComponentDecl 413 getBaseComponent() 414 { 415 return base_component_; 416 } 417 418 421 public InterfaceDecl[] 422 getSupportedInterfaces() 423 { 424 InterfaceDecl[] result = new InterfaceDecl[supported_interfaces_.size()]; 425 426 for(int i=0; i<result.length; i++) 427 result[i] = (InterfaceDecl)supported_interfaces_.get(i); 428 429 return result; 430 } 431 432 435 public InterfaceDecl 436 getClientMapping() 437 { 438 if (client_mapping_!=null) 439 return client_mapping_; 440 441 client_mapping_ = (InterfaceDeclImpl)getRepository().loadMapping(getParent(), getId()); 443 444 return client_mapping_; 445 } 446 447 450 public InterfaceDecl 451 getLocalContextMapping() 452 { 453 if (local_context_mapping_!=null) 454 return local_context_mapping_; 455 456 String parent_base_id = the_parent_.getId(); 458 int idx = parent_base_id.lastIndexOf(':'); 459 parent_base_id = parent_base_id.substring(0, idx); 460 String id = parent_base_id + "/CCM_"+getName()+"_Context:"+getVersion(); 461 462 local_context_mapping_ = (InterfaceDeclImpl)getRepository().loadMapping(getParent(), id); 463 return local_context_mapping_; 464 } 465 466 469 public InterfaceDecl 470 getLocalMonolithicMapping() 471 { 472 if (local_monolithic_mapping_!=null) 473 return local_monolithic_mapping_; 474 475 String parent_base_id = the_parent_.getId(); 477 int idx = parent_base_id.lastIndexOf(':'); 478 parent_base_id = parent_base_id.substring(0, idx); 479 String id = parent_base_id + "/CCM_"+getName()+":"+getVersion(); 480 481 local_monolithic_mapping_ = (InterfaceDeclImpl)getRepository().loadMapping(getParent(), id); 482 return local_monolithic_mapping_; 483 } 484 485 488 public InterfaceDecl 489 getLocalMainMapping() 490 { 491 if (local_main_mapping_!=null) 492 return local_main_mapping_; 493 494 String parent_base_id = the_parent_.getId(); 496 int idx = parent_base_id.lastIndexOf(':'); 497 parent_base_id = parent_base_id.substring(0, idx); 498 String id = parent_base_id + "/CCM_"+getName()+"_Executor:"+getVersion(); 499 500 local_main_mapping_ = (InterfaceDeclImpl)getRepository().loadMapping(getParent(), id); 501 return local_main_mapping_; 502 } 503 504 510 513 public void 514 destroy() 515 { 516 if (base_component_!=null) 517 base_component_.removeRef(); 518 519 InterfaceDecl[] itfs = getSupportedInterfaces(); 520 for (int i=0;i<itfs.length;i++) 521 ((InterfaceRef)itfs[i]).removeRef(); 522 523 super.destroy(); 524 } 525 526 532 protected org.omg.CORBA.Contained 533 getContained() 534 { 535 return component_def_; 536 } 537 538 544 550 protected org.omg.CORBA.Container 551 getContainer() 552 { 553 return component_def_; 554 } 555 556 564 public Declaration[] 565 getContents(boolean exclude_inherited, int limited_types) 566 { 567 if (exclude_inherited) 568 return super.getContents(exclude_inherited, limited_types); 569 570 Declaration[] res = super.getContents(exclude_inherited, limited_types); 571 InterfaceDecl[] itfs = getSupportedInterfaces(); 572 for (int i=0;i<itfs.length;i++) 573 { 574 Declaration[] tmp1 = itfs[i].getContents(exclude_inherited, limited_types); 575 Declaration[] tmp2 = res; 576 res = new Declaration[tmp1.length+tmp2.length]; 577 System.arraycopy(tmp2, 0, res, 0, tmp2.length); 578 System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length); 579 } 580 581 if (base_component_==null) 582 return res; 583 584 Declaration[] tmp1 = base_component_.getContents(exclude_inherited, limited_types); 585 Declaration[] tmp2 = res; 586 res = new Declaration[tmp1.length+tmp2.length]; 587 System.arraycopy(tmp2, 0, res, 0, tmp2.length); 588 System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length); 589 return res; 590 } 591 592 598 601 protected void 602 createContainer() 603 { 604 component_def_ = the_parent_.getComponentContainer().create_component(getId(), 605 getName(), 606 getVersion(), 607 getBaseComponentDef(), 608 getInterfaceDefs()); 609 } 610 611 614 protected void 615 completeContainer() 616 { 617 org.omg.CORBA.ComponentIR.ComponentDef base_component = getBaseComponentDef(); 618 if (base_component != null) 619 component_def_.base_component(base_component); 620 621 org.omg.CORBA.InterfaceDef [] supported_interfaces = getInterfaceDefs(); 622 if (supported_interfaces.length != 0) 623 component_def_.supported_interfaces(supported_interfaces); 624 } 625 } 626 | Popular Tags |