1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 40 abstract public class CCMObjectBase 41 extends org.omg.CORBA.LocalObject 42 implements org.omg.Components.CCMObjectOperations, 43 org.omg.Components.ExecutorSegmentBase, 44 org.omg.Components.SessionComponent, 45 java.io.Serializable 46 { 47 static private String _class_name = "CCMObjectBase"; 49 transient private org.omg.Components.CCM2Context _context; 50 transient private org.omg.Components.Session2Context _mono_ctx; 51 transient private org.omg.Components.SegmentedSession2Context _segmented_ctx; 52 transient private org.coach.ECM.ECMContext _ecm_ctx; 53 private boolean _initialized; 54 protected FacetSet _facets; 56 protected ReceptacleSet _receptacles; 57 protected SinkSet _sinks; 58 protected EmitterSet _emitters; 59 protected PublisherSet _publishers; 60 61 protected 63 CCMObjectBase() 64 { 65 _context = null; 67 _mono_ctx = null; 68 _segmented_ctx = null; 69 _ecm_ctx = null; 70 _initialized = false; 71 _facets = new FacetSet(); 72 _receptacles = new ReceptacleSet(); 73 _sinks = new SinkSet(); 74 _emitters = new EmitterSet(); 75 _publishers = new PublisherSet(); 76 } 77 78 82 private org.omg.CORBA.Object 83 createReference(String tid, short fid, short sid) 84 { 85 final String opname = "createReference"; 86 if (_mono_ctx!=null) { 88 try { 89 return _mono_ctx.create_with_new_target(tid); 90 } catch (org.omg.Components.IllegalState ex) { 91 final String msg = "FAILED (illegal state)"; 93 TheLogger.error(_class_name, opname, msg); 94 return null; 95 } 96 } else if (_segmented_ctx!=null) { 97 try { 98 org.omg.Components.ComponentId cid = _segmented_ctx.get_component_id(); 99 org.omg.Components.ComponentId ncid = cid.create_with_new_target(fid, sid); 100 return _segmented_ctx.create_ref_from_cid(tid, ncid); 101 } catch (org.omg.Components.IllegalState ex) { 102 final String msg = "FAILED (illegal state)"; 104 TheLogger.error(_class_name, opname, msg); 105 return null; 106 } 107 } else { 108 final String msg = "FAILED (no context)"; 110 TheLogger.error(_class_name, opname, msg); 111 return null; 112 } 113 } 114 115 119 abstract protected void 120 initializePorts(); 121 122 126 final protected org.coach.ECM.ECMContext 127 getECMContext() 128 { 129 return _ecm_ctx; 130 } 131 132 final protected org.omg.Components.CCM2Context 133 getCCM2Context() 134 { 135 return _context; 136 } 137 138 final protected org.omg.Components.Session2Context 139 getSession2Context() 140 { 141 return _mono_ctx; 142 } 143 144 final protected org.omg.Components.SegmentedSession2Context 145 getSegSession2Context() 146 { 147 return _segmented_ctx; 148 } 149 150 154 final public void 155 set_session_context(org.omg.Components.SessionContext ctx) 156 throws org.omg.Components.CCMException 157 { 158 final String opname = "set_session_context"; 159 160 if (ctx instanceof org.omg.Components.CCM2Context) { 161 _context = (org.omg.Components.CCM2Context)ctx; 162 } else { 163 final String msg = "FAILED (was expecting CCM2Context: "+ctx.getClass()+")"; 165 TheLogger.error(_class_name, opname, msg); 166 } 167 168 if (ctx instanceof org.omg.Components.Session2Context) { 169 _mono_ctx = (org.omg.Components.Session2Context)ctx; 170 } else if (ctx instanceof org.omg.Components.SegmentedSession2Context) { 171 _segmented_ctx = (org.omg.Components.SegmentedSession2Context)ctx; 172 } else { 173 final String msg = "FAILED (unsupported context: "+ctx.getClass()+")"; 175 TheLogger.error(_class_name, opname, msg); 176 } 177 178 if (ctx instanceof org.coach.ECM.ECMContext) { 179 _ecm_ctx = (org.coach.ECM.ECMContext)ctx; 180 } else { 181 final String msg = "FAILED (was expecting ECMContext: "+ctx.getClass()+")"; 183 TheLogger.error(_class_name, opname, msg); 184 } 185 186 if (!_initialized) { 188 initializePorts(); 189 _publishers.initializeChannel(_context); 191 _emitters.initializeChannel(_context); 192 _initialized = true; 193 } 194 } 195 196 public void 198 ccm_activate() 199 throws org.omg.Components.CCMException 200 { 201 } 202 203 public void 205 ccm_passivate() 206 throws org.omg.Components.CCMException 207 { 208 } 209 210 public void 212 ccm_remove() 213 throws org.omg.Components.CCMException 214 { 215 } 216 217 221 final public org.omg.Components.EventConsumerBase 222 get_consumer(String name) 223 throws org.omg.Components.InvalidName 224 { 225 final String opname = "get_consumer"; 226 Sink sink = _sinks.get(name); 228 if (sink==null) { 229 throw new org.omg.Components.InvalidName(); 230 } 231 232 org.omg.CORBA.Object obj = createReference(sink.type_id, sink.facet_id, sink.segment_id); 234 return org.omg.Components.EventConsumerBaseHelper.unchecked_narrow(obj); 235 } 236 237 final public org.omg.Components.Cookie 238 subscribe(String name, 239 org.omg.Components.EventConsumerBase consumer) 240 throws org.omg.Components.InvalidName, 241 org.omg.Components.InvalidConnection, 242 org.omg.Components.ExceededConnectionLimit 243 { 244 final String opname = "subscribe"; 245 Publisher pub = _publishers.get(name); 247 if (pub==null) { 248 throw new org.omg.Components.InvalidName(); 249 } 250 251 if (!consumer._is_a(pub.type_id)) { 253 throw new org.omg.Components.InvalidConnection(); 254 } 255 256 259 org.omg.Components.Cookie ck = null; 261 try { 262 ck = _context.get_events().subscribe(consumer, pub.channel_id); 263 } catch (org.omg.Components.InvalidChannel ex) { 264 TheLogger.error(_class_name, opname, "FAILED", ex); 266 } 267 268 return ck; 269 } 270 271 final public org.omg.Components.EventConsumerBase 272 unsubscribe(String name, org.omg.Components.Cookie ck) 273 throws org.omg.Components.InvalidName, 274 org.omg.Components.InvalidConnection 275 { 276 final String opname = "unsubscribe"; 277 Publisher pub = _publishers.get(name); 279 if (pub==null) { 280 throw new org.omg.Components.InvalidName(); 281 } 282 283 org.omg.Components.EventConsumerBase consumer = null; 285 try { 286 consumer = _context.get_events().unsubscribe(ck); 287 } catch (org.omg.Components.InvalidSubscription ex) { 288 throw new org.omg.Components.InvalidConnection(); 289 } 290 291 return consumer; 292 } 293 294 final public void 295 connect_consumer(String name, 296 org.omg.Components.EventConsumerBase consumer) 297 throws org.omg.Components.InvalidName, 298 org.omg.Components.AlreadyConnected, 299 org.omg.Components.InvalidConnection 300 { 301 final String opname = "connect_consumer"; 302 Emitter emitter = _emitters.get(name); 304 if (emitter==null) { 305 throw new org.omg.Components.InvalidName(); 306 } 307 308 if (!consumer._is_a(emitter.type_id)) { 310 throw new org.omg.Components.InvalidConnection(); 311 } 312 313 if (emitter.cookie!=null) { 315 throw new org.omg.Components.AlreadyConnected(); 316 } 317 318 try { 320 emitter.cookie = _context.get_events().subscribe(consumer, emitter.channel_id); 321 } catch (org.omg.Components.InvalidChannel ex) { 322 TheLogger.error(_class_name, opname, "FAILED", ex); 324 } 325 } 326 327 final public org.omg.Components.EventConsumerBase 328 disconnect_consumer(String name) 329 throws org.omg.Components.InvalidName, 330 org.omg.Components.NoConnection 331 { 332 final String opname = "disconnect_consumer"; 333 Emitter emitter = _emitters.get(name); 335 if (emitter==null) { 336 throw new org.omg.Components.InvalidName(); 337 } 338 339 if (emitter.cookie==null) { 341 throw new org.omg.Components.NoConnection(); 342 } 343 344 org.omg.Components.EventConsumerBase consumer = null; 346 try { 347 consumer = _context.get_events().unsubscribe(emitter.cookie); 348 emitter.cookie = null; 349 } catch (org.omg.Components.InvalidSubscription ex) { 350 throw new org.omg.Components.NoConnection(); 351 } 352 353 return consumer; 354 } 355 356 final public org.omg.Components.ConsumerDescription[] 357 get_all_consumers() 358 { 359 final String opname = "get_all_consumers"; 360 final String msg = "FAILED (op not impl, rethrown)"; 361 TheLogger.log(_class_name, opname, msg); 362 363 throw new org.omg.CORBA.NO_IMPLEMENT (); 364 } 365 366 final public org.omg.Components.ConsumerDescription[] 367 get_named_consumers(String [] names) 368 throws org.omg.Components.InvalidName 369 { 370 final String opname = "get_named_consumers"; 371 final String msg = "FAILED (op not impl, rethrown)"; 372 TheLogger.log(_class_name, opname, msg); 373 374 throw new org.omg.CORBA.NO_IMPLEMENT (); 375 } 376 377 final public org.omg.Components.EmitterDescription[] 378 get_all_emitters() 379 { 380 final String opname = "get_all_emitters"; 381 final String msg = "FAILED (op not impl, rethrown)"; 382 TheLogger.log(_class_name, opname, msg); 383 384 throw new org.omg.CORBA.NO_IMPLEMENT (); 385 } 386 387 final public org.omg.Components.EmitterDescription[] 388 get_named_emitters(String [] names) 389 throws org.omg.Components.InvalidName 390 { 391 final String opname = "get_named_emitters"; 392 final String msg = "FAILED (op not impl, rethrown)"; 393 TheLogger.log(_class_name, opname, msg); 394 395 throw new org.omg.CORBA.NO_IMPLEMENT (); 396 } 397 398 final public org.omg.Components.PublisherDescription[] 399 get_all_publishers() 400 { 401 final String opname = "get_all_publishers"; 402 final String msg = "FAILED (op not impl, rethrown)"; 403 TheLogger.log(_class_name, opname, msg); 404 405 throw new org.omg.CORBA.NO_IMPLEMENT (); 406 } 407 408 final public org.omg.Components.PublisherDescription[] 409 get_named_publishers(String [] names) 410 throws org.omg.Components.InvalidName 411 { 412 final String opname = "get_named_publishers"; 413 final String msg = "FAILED (op not impl, rethrown)"; 414 TheLogger.log(_class_name, opname, msg); 415 416 throw new org.omg.CORBA.NO_IMPLEMENT (); 417 } 418 419 423 final public org.omg.Components.Cookie 424 connect(String name, org.omg.CORBA.Object connection) 425 throws org.omg.Components.InvalidName, 426 org.omg.Components.InvalidConnection, 427 org.omg.Components.AlreadyConnected, 428 org.omg.Components.ExceededConnectionLimit 429 { 430 final String opname = "connect"; 431 Receptacle rec = _receptacles.get(name); 433 if (rec==null) { 434 throw new org.omg.Components.InvalidName(); 435 } 436 437 if (!rec.is_multiple && (rec.cookie!=null)) { 439 throw new org.omg.Components.AlreadyConnected(); 440 } 441 442 445 if (!connection._is_a(rec.type_id)) { 447 throw new org.omg.Components.InvalidConnection(); 448 } 449 450 org.omg.Components.Cookie ck = _context.get_receptacles().connect(rec.name, connection); 452 453 if (!rec.is_multiple) { 455 rec.cookie = ck; 456 } 457 458 return ck; 459 } 460 461 final public org.omg.CORBA.Object 462 disconnect(String name, org.omg.Components.Cookie ck) 463 throws org.omg.Components.InvalidName, 464 org.omg.Components.InvalidConnection, 465 org.omg.Components.CookieRequired, 466 org.omg.Components.NoConnection 467 { 468 final String opname = "disconnect"; 469 Receptacle rec = _receptacles.get(name); 471 if (rec==null) { 472 throw new org.omg.Components.InvalidName(); 473 } 474 475 if (!rec.is_multiple && (rec.cookie==null)) { 477 throw new org.omg.Components.NoConnection(); 478 } 479 480 if (rec.is_multiple && (ck==null)) { 482 throw new org.omg.Components.CookieRequired(); 483 } 484 485 org.omg.Components.Cookie rck = null; 487 if (!rec.is_multiple) { 488 rck = rec.cookie; 489 rec.cookie = null; 490 } else { 491 rck = ck; 492 } 493 494 if (rck==null) { 495 throw new org.omg.Components.InvalidConnection(); 496 } 497 498 org.omg.CORBA.Object obj = null; 500 try { 501 obj = _context.get_receptacles().disconnect(rck); 502 } catch (org.omg.Components.InvalidSubscription ex) { 503 TheLogger.error(_class_name, opname, "FAILED", ex); 505 } 506 507 if (obj==null) { 509 TheLogger.error(_class_name, opname, "FAILED (object is null)"); 511 } 512 513 return obj; 514 } 515 516 final public org.omg.Components.ConnectionDescription[] 517 get_connections(String name) 518 throws org.omg.Components.InvalidName 519 { 520 final String opname = "get_connections"; 521 Receptacle rec = _receptacles.get(name); 523 if (rec==null) { 524 throw new org.omg.Components.InvalidName(); 525 } 526 527 org.omg.Components.LocalConnection[] cnxs = null; 529 try { 530 cnxs = _context.get_receptacles().get_connections(rec.name); 531 } catch (org.omg.Components.InvalidName ex) { 532 TheLogger.error(_class_name, opname, "FAILED", ex); 534 } 535 536 if (cnxs.length==0) { 538 return new org.omg.Components.ConnectionDescription[0]; 539 } 540 541 org.omg.Components.ConnectionDescription[] descrs = null; 543 if (!rec.is_multiple) { 544 descrs = new org.omg.Components.ConnectionDescription[1]; 546 descrs[0] = org.objectweb.ccm.runtime.ConnectionDescriptionFactoryImpl.create_valuetype(); 547 descrs[0].ck = rec.cookie; 548 descrs[0].objref = cnxs[0].ref(); 549 } else { 550 descrs = new org.omg.Components.ConnectionDescription[cnxs.length]; 551 for (int i=0;i<cnxs.length;i++) { 552 descrs[i] = org.objectweb.ccm.runtime.ConnectionDescriptionFactoryImpl.create_valuetype(); 553 descrs[i].ck = cnxs[i].ck(); 554 descrs[i].objref = cnxs[i].ref(); 555 } 556 } 557 558 return descrs; 559 } 560 561 final public org.omg.Components.ReceptacleDescription[] 562 get_all_receptacles() 563 { 564 final String opname = "get_all_receptacles"; 565 final String msg = "FAILED (op not impl, rethrown)"; 566 TheLogger.log(_class_name, opname, msg); 567 568 throw new org.omg.CORBA.NO_IMPLEMENT (); 569 } 570 571 final public org.omg.Components.ReceptacleDescription[] 572 get_named_receptacles(String [] names) 573 throws org.omg.Components.InvalidName 574 { 575 final String opname = "get_named_receptacles"; 576 final String msg = "FAILED (op not impl, rethrown)"; 577 TheLogger.log(_class_name, opname, msg); 578 579 throw new org.omg.CORBA.NO_IMPLEMENT (); 580 } 581 582 586 final public org.omg.CORBA.Object 587 provide_facet(String name) 588 throws org.omg.Components.InvalidName 589 { 590 final String opname = "get_consumer"; 591 Facet facet = _facets.get(name); 593 if (facet==null) { 594 throw new org.omg.Components.InvalidName(); 595 } 596 597 return createReference(facet.type_id, facet.facet_id, facet.segment_id); 599 } 600 601 final public org.omg.Components.FacetDescription[] 602 get_all_facets() 603 { 604 final String opname = "get_all_facets"; 605 final String msg = "FAILED (op not impl, rethrown)"; 606 TheLogger.log(_class_name, opname, msg); 607 608 throw new org.omg.CORBA.NO_IMPLEMENT (); 609 } 610 611 final public org.omg.Components.FacetDescription[] 612 get_named_facets(String [] names) 613 throws org.omg.Components.InvalidName 614 { 615 final String opname = "get_named_facets"; 616 final String msg = "FAILED (op not impl, rethrown)"; 617 TheLogger.log(_class_name, opname, msg); 618 619 throw new org.omg.CORBA.NO_IMPLEMENT (); 620 } 621 622 final public boolean 623 same_component(org.omg.CORBA.Object objref) 624 { 625 final String opname = "same_component"; 626 final String msg = "FAILED (op not impl, rethrown)"; 627 TheLogger.log(_class_name, opname, msg); 628 629 throw new org.omg.CORBA.NO_IMPLEMENT (); 630 } 631 632 636 final public org.omg.CORBA.IRObject 637 get_component_def() 638 { 639 final String opname = "get_component_def"; 640 final String msg = "FAILED (op not impl, rethrown)"; 641 TheLogger.log(_class_name, opname, msg); 642 643 throw new org.omg.CORBA.NO_IMPLEMENT (); 644 } 645 646 final public org.omg.Components.CCMHome 647 get_ccm_home() 648 { 649 return _context.get_CCM_home(); 650 } 651 652 final public org.omg.Components.PrimaryKeyBase 653 get_primary_key() 654 throws org.omg.Components.NoKeyAvailable 655 { 656 throw new org.omg.Components.NoKeyAvailable(); 657 } 658 659 public void 661 configuration_complete() 662 throws org.omg.Components.InvalidConfiguration 663 { 664 } 665 666 final public void 667 remove() 668 throws org.omg.Components.RemoveFailure 669 { 670 } 672 673 final public org.omg.Components.ComponentPortDescription 674 get_all_ports() 675 { 676 final String opname = "get_all_ports"; 677 final String msg = "FAILED (op not impl, rethrown)"; 678 TheLogger.log(_class_name, opname, msg); 679 680 throw new org.omg.CORBA.NO_IMPLEMENT (); 681 } 682 } 683 | Popular Tags |