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.InterfaceDecl; 40 41 42 import org.objectweb.openccm.ast.api.ComponentDecl; 43 44 45 import org.objectweb.openccm.ast.api.HomeDecl; 46 47 48 import org.objectweb.openccm.ast.api.ValueDecl; 49 50 51 import org.omg.CORBA.ComponentIR.HomeDef; 52 import org.omg.CORBA.ComponentIR.HomeDefHelper; 53 54 55 import org.omg.CORBA.ValueDef ; 56 57 95 96 public class HomeDeclImpl 97 extends ComponentBaseImpl 98 implements HomeDecl 99 { 100 106 107 private HomeDef home_def_; 108 109 110 private HomeDeclImpl base_home_; 111 112 113 private ComponentDeclImpl managed_component_; 114 115 116 private ValueDeclImpl primary_key_; 117 118 119 private InterfaceDeclImpl local_mapping_; 120 121 127 133 protected 134 HomeDeclImpl(Repository rep, 135 ScopeImpl parent) 136 { 137 super(rep, parent); 139 140 home_def_ = null; 142 base_home_ = null; 143 managed_component_ = null; 144 primary_key_ = null; 145 local_mapping_ = null; 146 } 147 148 154 160 165 protected void 166 load(org.omg.CORBA.Contained contained) 167 { 168 home_def_ = HomeDefHelper.narrow(contained); 169 170 HomeDef baseHome = home_def_.base_home(); 171 if (baseHome!=null) 172 setBaseHome((HomeDecl)getRepository(). 173 lookupId(baseHome.id())); 174 175 setManagedComponent( 176 (ComponentDecl)getRepository(). 177 lookupId(home_def_.managed_component().id())); 178 179 ValueDef primaryKey = home_def_.primary_key(); 180 if (primaryKey!=null) 181 setPrimaryKey((ValueDecl)getRepository(). 182 lookupId(primaryKey.id())); 183 184 addSupportedInterfaces(home_def_.supported_interfaces()); 185 186 getClientMapping(); 188 189 super.load(contained); 190 } 191 192 197 protected org.omg.CORBA.Contained 198 getContained() 199 { 200 return home_def_; 201 } 202 203 209 214 protected org.omg.CORBA.Container 215 getContainer() 216 { 217 return home_def_; 218 } 219 220 226 229 protected void 230 createContainer() 231 { 232 org.omg.CORBA.ComponentIR.ComponentDef managed_component_def = 233 (managed_component_ != null) ? (managed_component_.getComponentDef()) : null; 234 235 home_def_ = the_parent_.getComponentContainer(). 236 create_home(getId(), getName(), getVersion(), 237 getBaseHomeDef(), 238 managed_component_def, 239 supported_interfaces_.getInterfaceDefSeq(), 240 getPrimaryKeyDef()); 241 } 242 243 246 protected void 247 completeContainer() 248 { 249 } 250 251 257 262 public HomeDef 263 getBaseHomeDef() 264 { 265 return (base_home_ != null) 266 ?(base_home_.getHomeDef()) : null; 267 } 268 269 274 public org.omg.CORBA.ExtValueDef 275 getPrimaryKeyDef() 276 { 277 return (primary_key_ != null) 278 ?(primary_key_.getExtValueDef()) : null; 279 } 280 281 286 public HomeDef 287 getHomeDef() 288 { 289 return home_def_; 290 } 291 292 297 public org.omg.CORBA.ExtInterfaceDef 298 getExtInterfaceDef() 299 { 300 return home_def_; 301 } 302 303 309 public org.omg.CORBA.InterfaceDef 310 getInterfaceDef() 311 { 312 return home_def_; 313 } 314 315 321 329 public Declaration[] 330 getDependencies() 331 { 332 if (dependencies_ != null) 333 return dependencies_; 334 335 java.util.List home_depend = new java.util.ArrayList (); 336 Declaration[] depend = null; 337 338 if (getBaseHome() != null) 340 { 341 home_depend.add(getBaseHome()); 342 depend = getBaseHome().getDependencies(); 343 for (int j=0; j<depend.length; j++) 344 home_depend.add(depend[j]); 345 } 346 347 if (getPrimaryKey() != null) 349 { 350 home_depend.add(getPrimaryKey()); 351 depend = getPrimaryKey().getDependencies(); 352 for (int j=0; j<depend.length; j++) 353 home_depend.add(depend[j]); 354 } 355 356 home_depend.add(getManagedComponent()); 358 depend = getManagedComponent().getDependencies(); 359 for (int j=0; j<depend.length; j++) 360 home_depend.add(depend[j]); 361 362 InterfaceDecl[] supp = supported_interfaces_.getInterfaces(); 364 for (int i=0; i<supp.length; i++) 365 { 366 home_depend.add(supp[i]); 367 depend = supp[i].getDependencies(); 368 for (int j=0; j<depend.length; j++) 369 { 370 if (home_depend.indexOf(depend[j])==-1) 371 home_depend.add(depend[j]); 372 } 373 } 374 375 Declaration[] decls = getContents(true, DeclarationKind.dk_all); 377 for (int i=0; i<decls.length; i++) 378 { 379 depend = decls[i].getDependencies(); 380 for (int j=0; j<depend.length; j++) 381 { 382 if ( (!containsDecl(depend[j])) && 383 (home_depend.indexOf(depend[j])==-1) ) 384 home_depend.add(depend[j]); 385 } 386 } 387 388 dependencies_ = (Declaration[])home_depend.toArray(new Declaration[0]); 389 return dependencies_; 390 } 391 392 398 403 public long 404 getDeclKind() 405 { 406 return DeclarationKind.dk_home; 407 } 408 409 415 426 public Declaration 427 find(String name) 428 { 429 Declaration decl = super.find(name); 431 432 if(decl != null) return decl; 434 435 if (base_home_ != null) 437 { 438 decl = base_home_.find(name); 439 if(decl != null) return decl; 440 } 441 442 return supported_interfaces_.find(name); 444 } 445 446 455 public Declaration[] 456 getContents(boolean exclude_inherited, 457 long limited_types) 458 { 459 if ((exclude_inherited) || (base_home_==null)) 460 return super.getContents(exclude_inherited, limited_types); 461 462 Declaration[] res = super.getContents(exclude_inherited, limited_types); 463 InterfaceDecl[] itfs = supported_interfaces_.getInterfaces(); 464 for (int i=0; i<itfs.length; i++) 465 { 466 Declaration[] tmp1 = itfs[i].getContents(exclude_inherited, limited_types); 467 Declaration[] tmp2 = res; 468 res = new Declaration[tmp1.length+tmp2.length]; 469 System.arraycopy(tmp2, 0, res, 0, tmp2.length); 470 System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length); 471 } 472 Declaration[] tmp1 = base_home_.getContents(exclude_inherited, limited_types); 473 Declaration[] tmp2 = res; 474 res = new Declaration[tmp1.length+tmp2.length]; 475 System.arraycopy(tmp2, 0, res, 0, tmp2.length); 476 System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length); 477 return res; 478 } 479 480 486 492 497 public TypeKind 498 getTypeKind() 499 { 500 return TypeKind.tk_home; 501 } 502 503 509 515 520 public org.omg.CORBA.IDLType 521 getIDLType() 522 { 523 return home_def_; 524 } 525 526 532 537 public InterfaceDecl 538 getClientMapping() 539 { 540 if (client_mapping_ == null) 541 { 542 client_mapping_ = (InterfaceDeclImpl)getRepository(). 544 loadMapping(getParent(), getId()); 545 } 546 return client_mapping_; 547 } 548 549 555 560 public void 561 setBaseHome(HomeDecl base_home) 562 { 563 if (base_home != null) 564 { 565 base_home_ = (HomeDeclImpl)base_home; 566 } 567 } 568 569 574 public HomeDecl 575 getBaseHome() 576 { 577 return base_home_; 578 } 579 580 585 public void 586 setManagedComponent(ComponentDecl managed_component) 587 { 588 if (managed_component != null) 589 { 590 managed_component_ = (ComponentDeclImpl)managed_component; 591 } 592 } 593 594 599 public ComponentDecl 600 getManagedComponent() 601 { 602 return managed_component_; 603 } 604 605 610 public void 611 setPrimaryKey(ValueDecl primary_key) 612 { 613 if (primary_key != null) 614 { 615 primary_key_ = (ValueDeclImpl)primary_key; 616 } 617 } 618 619 624 public ValueDecl 625 getPrimaryKey() 626 { 627 return primary_key_; 628 } 629 630 635 public InterfaceDecl 636 getClientExplicitMapping() 637 { 638 InterfaceDecl client = getClientMapping(); 640 InterfaceDecl[] bases = client.getInheritedInterfaceList() 641 .getInterfaces(); 642 if (bases[0].getName().equals(getName()+"Explicit")) 643 return bases[0]; 644 else 645 return bases[1]; 646 } 647 648 653 public InterfaceDecl 654 getClientImplicitMapping() 655 { 656 InterfaceDecl client = getClientMapping(); 658 InterfaceDecl[] bases = client.getInheritedInterfaceList() 659 .getInterfaces(); 660 if (bases[0].getName().equals(getName()+"Implicit")) 661 return bases[0]; 662 else 663 return bases[1]; 664 } 665 666 671 public InterfaceDecl 672 getLocalMapping() 673 { 674 if (local_mapping_ == null) 675 { 676 String parent_base_id = the_parent_.getId(); 678 int idx = parent_base_id.lastIndexOf(':'); 679 parent_base_id = parent_base_id.substring(0, idx); 680 String id = parent_base_id + "/CCM_" + getName() + 681 ':' + getVersion(); 682 683 local_mapping_ = (InterfaceDeclImpl)getRepository(). 684 loadMapping(getParent(), id); 685 } 686 return local_mapping_; 687 } 688 } 689 | Popular Tags |