1 26 27 package org.objectweb.ccm.IDL3; 28 29 37 38 public class HomeDeclImpl 39 extends InterfaceDeclImpl 40 implements HomeRef, HomeDecl 41 { 42 48 51 private org.omg.CORBA.ComponentIR.HomeDef home_def_; 52 53 56 private HomeDeclImpl base_home_; 57 58 61 private ComponentDeclImpl managed_component_; 62 63 66 private ValueDeclImpl primary_key_; 67 68 71 private org.objectweb.ccm.util.Vector supported_interfaces_; 72 73 76 private InterfaceDeclImpl client_mapping_; 77 78 81 private InterfaceDeclImpl local_mapping_; 82 83 89 94 protected 95 HomeDeclImpl(Repository rep, ScopeImpl parent) 96 { 97 super(rep, parent); 99 100 home_def_ = null; 102 base_home_ = null; 103 managed_component_ = null; 104 primary_key_ = null; 105 client_mapping_ = null; 106 local_mapping_ = null; 107 supported_interfaces_ = new org.objectweb.ccm.util.Vector(); 108 the_declaration_kind_ = DeclarationKind._dk_home; 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.HomeDef 142 getBaseHomeDef() 143 { 144 return (base_home_ != null) 145 ?(base_home_.getHomeDef()) : null; 146 } 147 148 151 protected org.omg.CORBA.ExtValueDef 152 getPrimaryKeyDef() 153 { 154 return (primary_key_ != null) 155 ?(primary_key_.getExtValueDef()) : null; 156 } 157 158 163 protected void 164 load(org.omg.CORBA.Contained contained) 165 { 166 home_def_ = org.omg.CORBA.ComponentIR.HomeDefHelper.narrow(contained); 167 if (home_def_.base_home()!=null) 168 setBaseHome((HomeRef)getRepository().lookupId(home_def_.base_home().id())); 169 170 setManagedComponent( 171 (ComponentRef)getRepository().lookupId(home_def_.managed_component().id())); 172 173 if (home_def_.primary_key()!=null) 174 setPrimaryKey((ValueRef)getRepository().lookupId(home_def_.primary_key().id())); 175 176 org.omg.CORBA.InterfaceDef [] supported = home_def_.supported_interfaces(); 177 for (int i=0;i<supported.length;i++) 178 addSupportedInterface((InterfaceRef)getRepository().lookupId(supported[i].id())); 180 181 getClientMapping(); 183 184 super.load(contained); 185 } 186 187 194 protected Declaration 195 findInSupportedInterfaces(String name) 196 { 197 for(int i=0; i<supported_interfaces_.size(); i++) 198 { 199 Declaration decl = ((InterfaceDecl)(supported_interfaces_.get(i))).find(name); 200 if (decl != null) return decl; 202 } 203 204 return null; 206 } 207 208 214 225 public Declaration 226 find(String name) 227 { 228 Declaration decl = super.find(name); 230 if(decl != null) return decl; 232 233 if (base_home_ != null) 235 { 236 decl = base_home_.find(name); 237 if(decl != null) return decl; 238 } 239 240 return findInSupportedInterfaces(name); 241 } 242 243 250 public Declaration[] 251 getDependencies() 252 { 253 if (dependencies_!=null) 254 return dependencies_; 255 256 org.objectweb.ccm.util.Vector home_depend = new org.objectweb.ccm.util.Vector(); 257 Declaration[] depend = null; 258 259 if (getBaseHome()!=null) 261 { 262 home_depend.add(getBaseHome()); 263 depend = getBaseHome().getDependencies(); 264 for (int j=0;j<depend.length;j++) 265 home_depend.add(depend[j]); 266 } 267 268 if (getPrimaryKey()!=null) 270 { 271 home_depend.add(getPrimaryKey()); 272 depend = getPrimaryKey().getDependencies(); 273 for (int j=0;j<depend.length;j++) 274 home_depend.add(depend[j]); 275 } 276 277 home_depend.add(getManagedComponent()); 279 depend = getManagedComponent().getDependencies(); 280 for (int j=0;j<depend.length;j++) 281 home_depend.add(depend[j]); 282 283 InterfaceDecl[] supp = getSupportedInterfaces(); 285 for (int i=0;i<supp.length;i++) 286 { 287 home_depend.add(supp[i]); 288 depend = supp[i].getDependencies(); 289 for (int j=0;j<depend.length;j++) 290 { 291 if (home_depend.indexOf(depend[j])==-1) 292 home_depend.add(depend[j]); 293 } 294 } 295 296 Declaration[] decls = getContents(true, org.objectweb.ccm.IDL3.DeclarationKind._dk_all); 298 for (int i=0;i<decls.length;i++) 299 { 300 depend = decls[i].getDependencies(); 301 for (int j=0;j<depend.length;j++) 302 { 303 if ((!containsDecl(depend[j])) && 304 (home_depend.indexOf(depend[j])==-1)) 305 home_depend.add(depend[j]); 306 } 307 } 308 309 dependencies_ = (Declaration[])home_depend.toArray(new Declaration[0]); 310 return dependencies_; 311 } 312 313 319 324 public org.omg.CORBA.IDLType 325 getIDLType() 326 { 327 return home_def_; 328 } 329 330 333 public int 334 getTypeKind() 335 { 336 return TypeKind._tk_home; 337 } 338 339 345 350 public org.omg.CORBA.ExtInterfaceDef 351 getExtInterfaceDef() 352 { 353 return home_def_; 354 } 355 356 362 public org.omg.CORBA.InterfaceDef 363 getInterfaceDef() 364 { 365 return home_def_; 366 } 367 368 374 379 public org.omg.CORBA.ComponentIR.HomeDef 380 getHomeDef() 381 { 382 return home_def_; 383 } 384 385 391 396 public void 397 addSupportedInterface(InterfaceRef itf) 398 { 399 if(itf != null) 400 { 401 itf.addRef(); 402 supported_interfaces_.add(itf); 403 } 404 } 405 406 411 public void 412 setBaseHome(HomeRef base_home) 413 { 414 if (base_home != null) 415 { 416 base_home_ = (HomeDeclImpl)base_home; 417 base_home_.addRef(); 418 } 419 } 420 421 426 public void 427 setManagedComponent(ComponentRef managed_component) 428 { 429 if (managed_component != null) 430 { 431 managed_component_ = (ComponentDeclImpl)managed_component; 432 managed_component_.addRef(); 433 } 434 } 435 436 441 public void 442 setPrimaryKey(ValueRef primary_key) 443 { 444 if (primary_key != null) 445 { 446 primary_key_ = (ValueDeclImpl)primary_key; 447 primary_key_.addRef(); 448 } 449 } 450 451 454 public HomeDecl 455 getBaseHome() 456 { 457 return base_home_; 458 } 459 460 463 public ComponentDecl 464 getManagedComponent() 465 { 466 return managed_component_; 467 } 468 469 472 public ValueDecl 473 getPrimaryKey() 474 { 475 return primary_key_; 476 } 477 478 481 public InterfaceDecl[] 482 getSupportedInterfaces() 483 { 484 InterfaceDecl[] result = new InterfaceDecl[supported_interfaces_.size()]; 485 for(int i=0; i<result.length; i++) 486 result[i] = (InterfaceDecl)supported_interfaces_.get(i); 487 488 return result; 489 } 490 491 494 public InterfaceDecl 495 getClientExplicitMapping() 496 { 497 InterfaceDecl client = getClientMapping(); 499 InterfaceDecl[] bases = client.getBaseInterfaces(); 500 if (bases[0].getName().equals(getName()+"Explicit")) 501 return bases[0]; 502 else 503 return bases[1]; 504 } 505 506 509 public InterfaceDecl 510 getClientImplicitMapping() 511 { 512 InterfaceDecl client = getClientMapping(); 514 InterfaceDecl[] bases = client.getBaseInterfaces(); 515 if (bases[0].getName().equals(getName()+"Implicit")) 516 return bases[0]; 517 else 518 return bases[1]; 519 } 520 521 524 public InterfaceDecl 525 getClientMapping() 526 { 527 if (client_mapping_!=null) 528 return client_mapping_; 529 530 client_mapping_ = (InterfaceDeclImpl)getRepository().loadMapping(getParent(), getId()); 532 533 return client_mapping_; 534 } 535 536 539 public InterfaceDecl 540 getLocalMapping() 541 { 542 if (local_mapping_!=null) 543 return local_mapping_; 544 545 String parent_base_id = the_parent_.getId(); 547 int idx = parent_base_id.lastIndexOf(':'); 548 parent_base_id = parent_base_id.substring(0, idx); 549 String id = parent_base_id + "/CCM_"+getName()+":"+getVersion(); 550 551 local_mapping_ = (InterfaceDeclImpl)getRepository().loadMapping(getParent(), id); 552 return local_mapping_; 553 } 554 555 561 564 public void 565 destroy() 566 { 567 if (base_home_!=null) 568 base_home_.removeRef(); 569 570 if (managed_component_!=null) 571 managed_component_.removeRef(); 572 573 if (primary_key_!=null) 574 primary_key_.removeRef(); 575 576 InterfaceDecl[] itfs = getSupportedInterfaces(); 577 for (int i=0;i<itfs.length;i++) 578 ((InterfaceRef)itfs[i]).removeRef(); 579 580 super.destroy(); 581 } 582 583 588 protected org.omg.CORBA.Contained 589 getContained() 590 { 591 return home_def_; 592 } 593 594 600 603 protected void 604 createContainer() 605 { 606 home_def_ = the_parent_.getComponentContainer().create_home(getId(), 607 getName(), 608 getVersion(), 609 getBaseHomeDef(), 610 managed_component_.getComponentDef(), 611 getInterfaceDefs(), 612 getPrimaryKeyDef()); 613 } 614 615 618 protected void 619 completeContainer() 620 { 621 } 622 623 629 634 protected org.omg.CORBA.Container 635 getContainer() 636 { 637 return home_def_; 638 } 639 640 648 public Declaration[] 649 getContents(boolean exclude_inherited, int limited_types) 650 { 651 if (exclude_inherited) 652 return super.getContents(exclude_inherited, limited_types); 653 654 Declaration[] res = super.getContents(exclude_inherited, limited_types); 655 InterfaceDecl[] itfs = getSupportedInterfaces(); 656 for (int i=0;i<itfs.length;i++) 657 { 658 Declaration[] tmp1 = itfs[i].getContents(exclude_inherited, limited_types); 659 Declaration[] tmp2 = res; 660 res = new Declaration[tmp1.length+tmp2.length]; 661 System.arraycopy(tmp2, 0, res, 0, tmp2.length); 662 System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length); 663 } 664 665 if (base_home_==null) 666 return res; 667 668 Declaration[] tmp1 = base_home_.getContents(exclude_inherited, limited_types); 669 Declaration[] tmp2 = res; 670 res = new Declaration[tmp1.length+tmp2.length]; 671 System.arraycopy(tmp2, 0, res, 0, tmp2.length); 672 System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length); 673 return res; 674 } 675 } 676 | Popular Tags |