1 26 27 package org.objectweb.openccm.Containers; 28 29 import org.objectweb.openccm.Containers.MetaInformation.ComponentInstance; 30 31 38 39 public class ComponentServantImpl 40 extends org.omg.CORBA.LocalObject 41 implements ComponentServant, 42 ActivationContext 43 { 44 50 53 protected HomeServant the_home_servant_; 54 55 58 protected ComponentExecutor the_component_executor_; 59 60 64 65 protected ComponentInstance the_component_instance_MI; 66 67 70 protected org.objectweb.ccm.util.WeakTable active_objects_; 71 72 75 protected org.objectweb.ccm.util.WeakTable activation_coords_; 76 77 80 protected org.omg.CORBA.Object [] the_port_references_; 81 82 85 protected org.omg.Components.CCMObject the_component_ref_; 86 87 90 protected org.omg.Components.EnterpriseComponent the_component_instance_; 91 92 95 protected short state_; 96 97 100 protected org.omg.Components.PrimaryKeyBase the_primary_key_; 101 102 105 protected ServantLocatorImpl the_servant_locator_; 106 107 113 117 public 118 ComponentServantImpl(ServantLocatorImpl locator, 119 HomeServant home_servant, 120 org.omg.Components.EnterpriseComponent instance, 121 org.omg.Components.PrimaryKeyBase key) 122 { 123 the_servant_locator_ = locator; 124 the_home_servant_ = home_servant; 125 the_primary_key_ = key; 126 the_component_executor_ = null; 127 the_port_references_ = new org.omg.CORBA.Object [home_servant.the_home_executor()._the_port_uids().length]; 128 for (int i=0;i<the_port_references_.length;i++) 129 the_port_references_[i] = null; 130 the_component_ref_ = null; 131 active_objects_ = null; 132 activation_coords_ = null; 133 state_ = ActivationContext.DEACTIVATED; 134 135 137 139 if(home_servant.the_home_instance() != null) 140 { 141 the_component_instance_MI = home_servant. 142 the_home_instance(). 143 create_component_instance(); 144 } 145 147 initializeComponentExecutor(instance); 148 } 149 150 156 163 protected org.omg.Components.SessionComponent 164 castToSessionComponent(org.omg.Components.EnterpriseComponent executor) 165 { 166 return (executor instanceof org.omg.Components.SessionComponent)? 167 (org.omg.Components.SessionComponent)executor : null; 168 } 169 170 173 protected void 174 initializeComponentExecutor(org.omg.Components.EnterpriseComponent instance) 175 { 176 if (instance==null) 177 return ; 178 179 active_objects_ = new org.objectweb.ccm.util.WeakTable(); 181 182 activation_coords_ = new org.objectweb.ccm.util.WeakTable(); 184 185 HomeExecutorBase home = the_home_servant_.the_home_executor(); 186 187 the_component_executor_ = home._get_component_executor(); 189 190 org.omg.Components.SessionComponent sc = castToSessionComponent(instance); 192 if(sc != null) 193 { 194 try 195 { 196 sc.set_session_context((org.omg.Components.SessionContext)the_component_executor_); 197 } catch(org.omg.Components.CCMException ex) { 198 throw new Error ("Activation failed"); 202 } 203 } 204 205 org.omg.Components.ExecutorLocator locator = null; 207 if (instance instanceof org.omg.Components.ExecutorLocator) 208 locator = (org.omg.Components.ExecutorLocator)instance; 209 else 211 locator = home._get_executor_locator(instance); 212 213 the_component_executor_._executor_locator(locator); 215 the_component_executor_._component_servant(this); 216 } 217 218 219 225 228 public org.omg.CORBA.Object 229 get_reference(java.lang.String uid) 230 { 231 HomeExecutorBase home = the_home_servant_.the_home_executor(); 232 java.lang.String comp_uid = home._the_component_uid(); 233 if (comp_uid.equals(uid)) 234 return the_component_ref_; 235 236 java.lang.String [] uids = home._the_port_uids(); 237 int i=0; 238 while (!uids[i].equals(uid)) 239 i++; 240 241 if (the_port_references_[i]==null) 242 the_port_references_[i] = the_servant_locator_.createPortReference(this, uid); 243 244 return the_port_references_[i]; 245 } 246 247 250 public Interceptor 251 get_native_interface(java.lang.String uid) 252 { 253 HomeExecutorBase home = the_home_servant_.the_home_executor(); 254 255 277 278 Interceptor inter = (Interceptor)active_objects_.get(uid); 280 281 if (inter==null) 282 { 283 inter = home._get_interceptor(uid); 285 286 288 291 CallContext context = new ComponentCallContext(this, the_home_servant_, uid); 293 294 296 inter._call_context(context); 297 298 active_objects_.put(uid, inter); 300 } 301 302 int idx = uid.lastIndexOf('/'); 304 if (idx==-1) idx = uid.indexOf(':'); 305 int idx2 = uid.lastIndexOf(':'); 306 java.lang.String name = uid.substring(idx+1, idx2); 307 308 try 310 { 311 org.omg.CORBA.Object exe = 312 the_component_executor_._executor_locator().obtain_executor(name); 313 314 if (uid.equals(home._the_component_uid())) 316 { 317 the_component_executor_._delegate((org.omg.Components.EnterpriseComponent)exe); 318 inter._delegate((java.lang.Object )the_component_executor_); 319 } 320 else 321 { 322 inter._delegate(home._get_executor_wrapper(exe, uid)); 323 } 324 } 325 catch(org.omg.Components.CCMException ex) 326 { 327 } 331 332 return inter; 333 } 334 335 338 public void 339 release_native_interface(Interceptor inter) 340 { 341 HomeExecutorBase home = the_home_servant_.the_home_executor(); 342 java.lang.String uid = inter._call_context().uid(); 343 344 354 355 try 356 { 357 org.omg.CORBA.Object exe = null; 358 if (uid.equals(home._the_component_uid())) 360 { 361 exe = (org.omg.CORBA.Object )the_component_executor_._delegate(); 362 363 } 370 else 371 { 372 exe = (org.omg.CORBA.Object )inter._delegate(); 373 } 374 the_component_executor_._executor_locator().release_executor(exe); 375 376 383 } 384 catch(org.omg.Components.CCMException ex) 385 { 386 } 390 } 391 392 395 public ActivationContext 396 activation_context() 397 { 398 return this; 399 } 400 401 404 public HomeServant 405 the_home_servant() 406 { 407 return the_home_servant_; 408 } 409 410 413 public ComponentExecutor 414 the_component_executor() 415 { 416 return the_component_executor_; 417 } 418 419 422 public org.omg.Components.CCMObject 423 the_component_ref() 424 { 425 return the_component_ref_; 426 } 427 428 431 public org.omg.Components.PrimaryKeyBase 432 the_registration_info() 433 { 434 return the_primary_key_; 435 } 436 437 443 449 public void 450 state(short new_state) 451 { 452 if (state_==new_state) 454 return ; 455 456 switch (new_state) 461 { 462 case DEACTIVATED : 463 the_component_executor_ = null; 465 active_objects_ = null; 467 activation_coords_ = null; 468 break; 469 case ACTIVATED : 470 if ((the_component_executor_==null) && (the_component_instance_==null)) 472 { 473 HomeExecutorBase home = null; 475 home = the_home_servant_.the_home_executor(); 476 477 try 479 { 480 if (!home._has_primary_key()) 481 the_component_instance_ = ((HomeExecutor)home)._get_enterprise_component(); 482 else 483 the_component_instance_ = ((HomeExecutorWithPK)home)._get_enterprise_component(the_primary_key_); 484 } 485 catch(org.omg.Components.CCMException ex) 486 { 487 throw new Error ("Creation of instance failed !"); 491 } 492 493 initializeComponentExecutor(the_component_instance_); 495 } 496 else if (the_component_executor_==null) 497 { 498 initializeComponentExecutor(the_component_instance_); 500 } 501 break; 502 default : 503 break; 504 } 505 506 state_ = new_state; 508 } 509 510 516 public short 517 state() 518 { 519 return state_; 520 } 521 522 528 531 public void 532 setComponentRef(org.omg.Components.CCMObject ref) 533 { 534 the_component_ref_ = ref; 535 } 536 537 540 public org.omg.CORBA.Object 541 getReferenceWithInstance(org.omg.Components.EnterpriseComponent instance) 542 { 543 if (the_component_instance_==instance) 544 return the_component_ref_; 545 546 return null; 547 } 548 549 552 public void 553 remove() 554 throws org.omg.Components.RemoveFailure 555 { 556 the_servant_locator_.removeReference(the_component_ref_); 557 558 org.omg.Components.EnterpriseComponent delegate = the_component_executor_._delegate(); 559 560 org.omg.Components.SessionComponent sc = castToSessionComponent(delegate); 561 if(sc != null) 562 { 563 try 564 { 565 sc.ccm_remove(); 566 } catch (org.omg.Components.CCMException ex) { 567 throw new org.omg.Components.RemoveFailure(); 570 } 571 } 572 } 573 574 577 public ComponentInstance the_component_instance() 578 { 579 return the_component_instance_MI; 580 } 581 } 582 | Popular Tags |