1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 import org.objectweb.corba.ast.api.*; 35 import org.objectweb.corba.ast.lib.*; 36 import org.objectweb.corba.generator.java.lib.*; 37 import org.objectweb.corba.generator.java.ast.api.*; 38 import org.objectweb.corba.generator.java.ast.lib.*; 39 import org.objectweb.corba.generator.common.lib.GenerationException; 40 41 44 public class CIDLCOPIGenerator 45 extends org.objectweb.corba.generator.common.lib.GeneratorBase 46 { 47 private ExtendedJavaTranslator _translator; 49 private RepositoryImpl _repository; 50 51 public 53 CIDLCOPIGenerator(AST ast) 54 { 55 super(ast); 56 57 _translator = new ExtendedJavaTranslator(); 58 _repository = null; 59 } 60 61 65 private ExtendedJavaTranslator 66 getTranslator() 67 { 68 return _translator; 69 } 70 71 private RepositoryImpl 72 getRepository() 73 { 74 return _repository; 75 } 76 77 private void 79 generateForModule(ModuleDecl module) 80 { 81 Declaration[] decls = null; 82 decls = module.getContents(false, DeclarationKind.dk_component); 84 for (int i=0;i<decls.length;i++) { 85 generateForComponent((ComponentDecl)decls[i]); 86 } 87 88 decls = module.getContents(false, DeclarationKind.dk_home); 90 for (int i=0;i<decls.length;i++) { 91 generateForHome((HomeDecl)decls[i]); 92 } 93 94 decls = module.getContents(false, DeclarationKind.dk_module); 96 for (int i=0;i<decls.length;i++) { 97 generateForModule((ModuleDecl)decls[i]); 98 } 99 } 100 101 private void 102 generateForHome(HomeDecl home) 103 { 104 107 generateIFactory(home); 109 } 110 111 private void 112 generateForComponent(ComponentDecl comp) 113 { 114 Declaration[] facets = comp.getContents(false, DeclarationKind.dk_provides); 118 Declaration[] sinks = comp.getContents(false, DeclarationKind.dk_consumes); 119 Declaration[] mainseg = new Declaration[facets.length+sinks.length+1]; 120 121 mainseg[0] = comp; 122 System.arraycopy(facets, 0, mainseg, 1, facets.length); 123 System.arraycopy(sinks, 0, mainseg, facets.length+1, sinks.length); 124 generateForSegment(org.omg.Components.COMPONENT_ID.value, comp, mainseg); 125 126 Declaration[] decls = null; 128 decls = comp.getContents(false, DeclarationKind.dk_uses); 129 for (int i=0;i<decls.length;i++) { 130 UsesDecl rec = (UsesDecl)decls[i]; 132 InterfaceDecl itf = rec.getInterface(); 133 if (itf.getDeclKind()==DeclarationKind.dk_home) { 136 HomeDecl home = (HomeDecl)itf; 137 itf = home.getClientMapping(); 138 } 139 140 generateStubI(itf, rec); 141 } 142 143 decls = comp.getContents(false, DeclarationKind.dk_emits); 145 for (int i=0;i<decls.length;i++) { 146 EmitsDecl emitter = (EmitsDecl)decls[i]; 148 generateStubI(emitter.getEvent().getClientMapping(), emitter); 149 } 150 151 decls = comp.getContents(false, DeclarationKind.dk_publishes); 153 for (int i=0;i<decls.length;i++) { 154 PublishesDecl publisher = (PublishesDecl)decls[i]; 156 generateStubI(publisher.getEvent().getClientMapping(), publisher); 157 } 158 } 159 160 private void 161 generateIFactory(HomeDecl home) 162 { 163 ComponentDecl comp = home.getManagedComponent(); 164 String classname = home.getName()+"_IFact"; 165 ClassObject ski = new ClassObjectImpl(classname); 166 167 ski.setPackage(getTranslator().getPackage(comp)); 169 ski.addImport("org.objectweb.corba.runtime.*"); 170 ski.addImport("org.objectweb.ccm.runtime.*"); 171 172 ski.addComment(" "); 176 ski.addComment("Java interceptor factory for component "+comp.getName()); 177 ski.addComment(" "); 178 ski.addComment("NOTE: generated class; DO NOT EDIT !"); 179 ski.addComment(" "); 180 ski.setModifier(ModifierKindImpl.mk_public); 181 ski.addImplementedObject("CallInterceptorFactory"); 182 183 AttributeObject attr = null; 185 attr = new AttributeObjectImpl(); 187 attr.addComment("Class name of this class (used for debugging)."); 188 attr.setStatic(true); 189 attr.setModifier(ModifierKindImpl.mk_private); 190 attr.setType("String"); 191 attr.setName("_class_name"); 192 attr.setInitialValue("\""+classname+"\""); 193 ski.addAttribute(attr); 194 195 attr = new AttributeObjectImpl(); 197 attr.addComment("."); 198 attr.setModifier(ModifierKindImpl.mk_private); 199 attr.setType("ORBService"); 200 attr.setName("_orb_service"); 201 ski.addAttribute(attr); 202 203 attr = new AttributeObjectImpl(); 205 attr.addComment("."); 206 attr.setModifier(ModifierKindImpl.mk_private); 207 attr.setType("ServicesSet"); 208 attr.setName("_services_set"); 209 ski.addAttribute(attr); 210 211 attr = new AttributeObjectImpl(); 213 attr.addComment("."); 214 attr.setModifier(ModifierKindImpl.mk_private); 215 attr.setType("String"); 216 attr.setName("_uuid"); 217 ski.addAttribute(attr); 218 219 ConstructorObject constructor = new ConstructorObjectImpl(); 222 constructor.getImpl().setMacro("IFACT_CONSTRUCTOR_BODY"); 223 ski.addConstructor(constructor); 224 225 MethodObject operation = new MethodObjectImpl(); 228 operation.addComment("."); 229 operation.setStatic(true); 230 operation.setModifier(ModifierKindImpl.mk_public); 231 operation.setReturnType("CallInterceptorFactory"); 232 operation.setName("create_factory"); 233 operation.getImpl().setMacro("IFACT_CREATEFACTORY_BODY"); 234 operation.getImpl().addContextValue("classname", classname); 235 ski.addMethod(operation); 236 237 operation = new MethodObjectImpl(); 240 operation.addComment("."); 241 operation.setFinal(true); 242 operation.setModifier(ModifierKindImpl.mk_public); 243 operation.setReturnType("void"); 244 operation.setName("setContextInfo"); 245 ParameterObject parameter = new ParameterObjectImpl(); 246 parameter.setName("orbs"); 247 parameter.setType("ORBService"); 248 operation.addParameter(parameter); 249 parameter = new ParameterObjectImpl(); 250 parameter.setName("sset"); 251 parameter.setType("ServicesSet"); 252 operation.addParameter(parameter); 253 parameter = new ParameterObjectImpl(); 254 parameter.setName("uuid"); 255 parameter.setType("String"); 256 operation.addParameter(parameter); 257 operation.getImpl().setMacro("IFACT_SETCONTEXTINFO_BODY"); 258 ski.addMethod(operation); 259 260 operation = new MethodObjectImpl(); 263 operation.addComment("."); 264 operation.setFinal(true); 265 operation.setModifier(ModifierKindImpl.mk_public); 266 operation.setReturnType("org.omg.PortableServer.Servant"); 267 operation.setName("createSkeletonInterceptor"); 268 parameter = new ParameterObjectImpl(); 269 parameter.setName("sid"); 270 parameter.setType("short"); 271 operation.addParameter(parameter); 272 parameter = new ParameterObjectImpl(); 273 parameter.setName("executor"); 274 parameter.setType("org.omg.CORBA.Object"); 275 operation.addParameter(parameter); 276 operation.getImpl().setMacro("IFACT_CREATESKINTERCEPTOR_BODY"); 277 String mainseg_classname = comp.getName()+"_MainSegSkI"; 279 operation.getImpl().addContextValue("mainseg_classname", mainseg_classname); 280 ski.addMethod(operation); 281 282 operation = new MethodObjectImpl(); 285 operation.addComment("."); 286 operation.setFinal(true); 287 operation.setModifier(ModifierKindImpl.mk_public); 288 operation.setReturnType("org.omg.CORBA.Object"); 289 operation.setName("createStubInterceptor"); 290 parameter = new ParameterObjectImpl(); 291 parameter.setName("name"); 292 parameter.setType("String"); 293 operation.addParameter(parameter); 294 parameter = new ParameterObjectImpl(); 295 parameter.setName("delegate"); 296 parameter.setType("org.omg.CORBA.Object"); 297 operation.addParameter(parameter); 298 operation.getImpl().setMacro("IFACT_CREATESTUBINTERCEPTOR_BODY"); 299 Declaration[] receptacles = comp.getContents(false, DeclarationKind.dk_uses); 300 Declaration[] emitters = comp.getContents(false, DeclarationKind.dk_emits); 301 Declaration[] publishers = comp.getContents(false, DeclarationKind.dk_publishes); 302 Boolean has_receptacles = new Boolean ((receptacles.length!=0)); 303 Boolean has_emitters = new Boolean ((emitters.length!=0)); 304 Boolean has_publishers = new Boolean ((publishers.length!=0)); 305 operation.getImpl().addContextValue("receptacles", receptacles); 306 operation.getImpl().addContextValue("emitters", emitters); 307 operation.getImpl().addContextValue("publishers", publishers); 308 operation.getImpl().addContextValue("has_receptacles", has_receptacles); 309 operation.getImpl().addContextValue("has_emitters", has_emitters); 310 operation.getImpl().addContextValue("has_publishers", has_publishers); 311 ski.addMethod(operation); 312 313 operation = new MethodObjectImpl(); 316 operation.addComment("."); 317 operation.setFinal(true); 318 operation.setModifier(ModifierKindImpl.mk_public); 319 operation.setReturnType("org.omg.CORBA.Object"); 320 operation.setName("createUntypedStubInterceptor"); 321 parameter = new ParameterObjectImpl(); 322 parameter.setName("name"); 323 parameter.setType("String"); 324 operation.addParameter(parameter); 325 parameter = new ParameterObjectImpl(); 326 parameter.setName("delegate"); 327 parameter.setType("org.omg.CORBA.Object"); 328 operation.addParameter(parameter); 329 operation.getImpl().setMacro("IFACT_CREATEUNTYPEDSTUBINTERCEPTOR_BODY"); 330 operation.getImpl().addContextValue("emitters", emitters); 331 operation.getImpl().addContextValue("publishers", publishers); 332 operation.getImpl().addContextValue("has_emitters", has_emitters); 333 operation.getImpl().addContextValue("has_publishers", has_publishers); 334 ski.addMethod(operation); 335 336 getRepository().addObject(ski); 338 } 339 340 private void 341 generateForSegment(short segid, ComponentDecl comp, Declaration[] idl3decls) 342 { 343 String classname = ""; 344 String ssegid = java.lang.Short.toString(segid); 345 if (segid==org.omg.Components.COMPONENT_ID.value) { 346 classname = comp.getName()+"_MainSegSkI"; 348 } else { 349 classname = comp.getName()+"_Seg"+ssegid+"SkI"; 351 } 352 353 ClassObject ski = new ClassObjectImpl(classname); 354 355 ski.setPackage(getTranslator().getPackage(comp)); 357 ski.addImport("org.objectweb.corba.runtime.*"); 358 ski.addImport("org.objectweb.ccm.runtime.*"); 359 360 ski.addComment(" "); 367 if (segid==org.omg.Components.COMPONENT_ID.value) { 368 ski.addComment("Java server-side interceptor for main segment of component "+comp.getName()); 369 } else { 370 ski.addComment("Java server-side interceptor for segment "+ssegid+" of component "+comp.getName()); 371 } 372 ski.addComment(" "); 373 ski.addComment("NOTE: generated class; DO NOT EDIT !"); 374 ski.addComment(" "); 375 ski.setModifier(ModifierKindImpl.mk_public); 376 if (segid==org.omg.Components.COMPONENT_ID.value) { 377 ski.addInheritedObject(comp.getName()+"_MainSegPOA"); 378 } else { 379 ski.addInheritedObject(comp.getName()+"_Seg"+ssegid+"POA"); 380 } 381 382 AttributeObject attr = null; 384 attr = new AttributeObjectImpl(); 386 attr.addComment("Class name of this class (used for debugging)."); 387 attr.setStatic(true); 388 attr.setModifier(ModifierKindImpl.mk_private); 389 attr.setType("String"); 390 attr.setName("_class_name"); 391 attr.setInitialValue("\""+classname+"\""); 392 ski.addAttribute(attr); 393 394 attr = new AttributeObjectImpl(); 396 attr.addComment("."); 397 attr.setModifier(ModifierKindImpl.mk_private); 398 attr.setType("ORBService"); 399 attr.setName("_orb_service"); 400 ski.addAttribute(attr); 401 402 attr = new AttributeObjectImpl(); 404 attr.addComment("."); 405 attr.setModifier(ModifierKindImpl.mk_private); 406 attr.setType("ServicesSet"); 407 attr.setName("_services_set"); 408 ski.addAttribute(attr); 409 410 attr = new AttributeObjectImpl(); 412 attr.addComment("."); 413 attr.setModifier(ModifierKindImpl.mk_private); 414 attr.setType("String"); 415 attr.setName("_uuid"); 416 ski.addAttribute(attr); 417 418 attr = new AttributeObjectImpl(); 420 attr.addComment("."); 421 attr.setModifier(ModifierKindImpl.mk_private); 422 attr.setType("ServerCallContextImpl"); 423 attr.setName("_call_ctx"); 424 ski.addAttribute(attr); 425 426 attr = new AttributeObjectImpl(); 428 attr.addComment("."); 429 attr.setModifier(ModifierKindImpl.mk_private); 430 attr.setType("java.util.Hashtable"); 431 attr.setName("_informations"); 432 ski.addAttribute(attr); 433 434 attr = new AttributeObjectImpl(); 438 attr.addComment("Typed delegate."); 439 attr.setModifier(ModifierKindImpl.mk_private); 440 String delegate_type = null; 441 if (segid==org.omg.Components.COMPONENT_ID.value) { 442 delegate_type = comp.getName()+"_MainSegOperations"; 443 } else { 444 delegate_type = comp.getName()+"_Seg"+ssegid+"Operations"; 445 } 446 attr.setType(delegate_type); 447 attr.setName("_delegate"); 448 ski.addAttribute(attr); 449 450 ConstructorObject constructor = new ConstructorObjectImpl(); 454 ParameterObject parameter = new ParameterObjectImpl(); 456 parameter.setName("orbs"); 457 parameter.setType("ORBService"); 458 constructor.addParameter(parameter); 459 parameter = new ParameterObjectImpl(); 460 parameter.setName("sset"); 461 parameter.setType("ServicesSet"); 462 constructor.addParameter(parameter); 463 parameter = new ParameterObjectImpl(); 464 parameter.setName("uuid"); 465 parameter.setType("String"); 466 constructor.addParameter(parameter); 467 parameter = new ParameterObjectImpl(); 468 parameter.setName("executor"); 469 parameter.setType("org.omg.CORBA.Object"); 470 constructor.addParameter(parameter); 471 constructor.getImpl().addContextValue("delegate_type", delegate_type); 473 constructor.getImpl().setMacro("SKI_CONSTRUCTOR_BODY"); 474 ski.addConstructor(constructor); 475 476 MethodObject operation = new MethodObjectImpl(); 479 operation.addComment("."); 480 operation.setModifier(ModifierKindImpl.mk_private); 481 operation.setReturnType("CallInformation"); 482 operation.setName("_getCallInformation"); 483 parameter = new ParameterObjectImpl(); 484 parameter.setName("name"); 485 parameter.setType("String"); 486 operation.addParameter(parameter); 487 operation.getImpl().setMacro("SKI_GETCALLINFORMATION_BODY"); 488 ski.addMethod(operation); 489 490 operation = new MethodObjectImpl(); 492 operation.addComment("."); 493 operation.setModifier(ModifierKindImpl.mk_private); 494 operation.setReturnType("short"); 495 operation.setName("_preinvoke"); 496 parameter = new ParameterObjectImpl(); 497 parameter.setName("ctrls"); 498 parameter.setType("org.coach.ECA.ServerCallController[]"); 499 operation.addParameter(parameter); 500 operation.getImpl().setMacro("SKI_PREINVOKE_BODY"); 501 ski.addMethod(operation); 502 503 operation = new MethodObjectImpl(); 505 operation.addComment("."); 506 operation.setModifier(ModifierKindImpl.mk_private); 507 operation.setReturnType("short"); 508 operation.setName("_postinvoke"); 509 parameter = new ParameterObjectImpl(); 510 parameter.setName("fstate"); 511 parameter.setType("short"); 512 operation.addParameter(parameter); 513 operation.getImpl().setMacro("SKI_POSTINVOKE_BODY"); 514 ski.addMethod(operation); 515 516 for (int i=0;i<idl3decls.length;i++) { 518 generateSkIOps(ski, idl3decls[i]); 519 } 520 521 getRepository().addObject(ski); 523 } 524 525 private void 526 generateSkIOps(ClassObject ski, Declaration idl3decl) 527 { 528 InterfaceDecl itf = null; 529 String sname = "::"+idl3decl.getName(); 530 531 if (idl3decl.getDeclKind()==DeclarationKind.dk_component) { 532 ComponentDecl comp = (ComponentDecl)idl3decl; 533 itf = comp.getClientMapping(); 534 } else if (idl3decl.getDeclKind()==DeclarationKind.dk_provides) { 535 ProvidesDecl facet = (ProvidesDecl)idl3decl; 536 itf = facet.getInterface(); 537 538 sname = "::"+idl3decl.getParent().getName()+sname; 540 } else if (idl3decl.getDeclKind()==DeclarationKind.dk_consumes) { 541 ConsumesDecl sink = (ConsumesDecl)idl3decl; 542 itf = sink.getEvent().getClientMapping(); 543 544 sname = "::"+idl3decl.getParent().getName()+sname; 546 } 547 548 Declaration[] decls = itf.getContents(false, DeclarationKind.dk_operation); 550 OperationDecl op = null; 551 for (int i=0;i<decls.length;i++) { 552 op = (OperationDecl)decls[i]; 553 554 String ciname = null; 555 if (idl3decl.getDeclKind()==DeclarationKind.dk_consumes) { 556 ciname = sname; 559 } else { 560 ciname = sname+"::"+op.getName(); 561 } 562 563 addWrappedOperation(ski, op, op.getType(), ciname, 564 op.getParameterList().getParameters(), 565 op.getExceptionList().getExceptions(), 566 "SKI_WRAPPED_OPERATION"); 567 } 568 569 decls = itf.getContents(false, DeclarationKind.dk_attribute); 571 AttributeDecl attrdecl = null; 572 for (int i=0;i<decls.length;i++) { 573 attrdecl = (AttributeDecl)decls[i]; 574 575 if (attrdecl.isReadonly()) { 577 addWrappedOperation(ski, attrdecl, attrdecl.getType(), sname+"::_get_"+attrdecl.getName(), 579 new Parameter[0], attrdecl.getExceptions(), 580 "SKI_WRAPPED_OPERATION"); 581 } 582 else { 583 addWrappedOperation(ski, attrdecl, attrdecl.getType(), sname+"::_get_"+attrdecl.getName(), 585 new Parameter[0], attrdecl.getGetExceptions(), 586 "SKI_WRAPPED_OPERATION"); 587 588 Parameter[] params = new Parameter[] { 591 new ParameterImpl(attrdecl.getName(), attrdecl.getType(), org.omg.CORBA.ParameterMode.PARAM_IN) 592 }; 593 594 addWrappedOperation(ski, attrdecl, getAST().getVoidType(), sname+"::_set_"+attrdecl.getName(), 595 params, attrdecl.getSetExceptions(), 596 "SKI_WRAPPED_OPERATION"); 597 598 } 599 } 600 } 601 602 private void 603 generateStubI(InterfaceDecl itf, Declaration idl3decl) 604 { 605 String classname = ""; 606 607 if (idl3decl.getDeclKind()==DeclarationKind.dk_uses) { 609 classname = idl3decl.getParent().getName()+"_"+idl3decl.getName()+"StubI"; 610 } 611 if (idl3decl.getDeclKind()==DeclarationKind.dk_emits) { 612 classname = idl3decl.getParent().getName()+"_"+idl3decl.getName()+"StubI"; 613 } 614 if (idl3decl.getDeclKind()==DeclarationKind.dk_publishes) { 615 classname = idl3decl.getParent().getName()+"_"+idl3decl.getName()+"StubI"; 616 } 617 618 ClassObject ski = new ClassObjectImpl(classname); 619 620 ski.setPackage(getTranslator().getPackage(itf)); 622 ski.addImport("org.objectweb.corba.runtime.*"); 623 ski.addImport("org.objectweb.ccm.runtime.*"); 624 625 ski.addComment(" "); 629 ski.addComment("Java client-side interceptor for interface "+itf.getName()); 630 ski.addComment(" "); 631 ski.addComment("NOTE: generated class; DO NOT EDIT !"); 632 ski.addComment(" "); 633 ski.setModifier(ModifierKindImpl.mk_public); 634 ski.addInheritedObject("_"+itf.getName()+"Stub"); 635 636 AttributeObject attr = null; 638 attr = new AttributeObjectImpl(); 640 attr.addComment("Class name of this class (used for debugging)."); 641 attr.setStatic(true); 642 attr.setModifier(ModifierKindImpl.mk_private); 643 attr.setType("String"); 644 attr.setName("_class_name"); 645 attr.setInitialValue("\""+classname+"\""); 646 ski.addAttribute(attr); 647 648 attr = new AttributeObjectImpl(); 650 attr.addComment("."); 651 attr.setModifier(ModifierKindImpl.mk_private); 652 attr.setType("ORBService"); 653 attr.setName("_orb_service"); 654 ski.addAttribute(attr); 655 656 attr = new AttributeObjectImpl(); 658 attr.addComment("."); 659 attr.setModifier(ModifierKindImpl.mk_private); 660 attr.setType("ServicesSet"); 661 attr.setName("_services_set"); 662 ski.addAttribute(attr); 663 664 attr = new AttributeObjectImpl(); 666 attr.addComment("."); 667 attr.setModifier(ModifierKindImpl.mk_private); 668 attr.setType("String"); 669 attr.setName("_uuid"); 670 ski.addAttribute(attr); 671 672 attr = new AttributeObjectImpl(); 674 attr.addComment("."); 675 attr.setModifier(ModifierKindImpl.mk_private); 676 attr.setType("ClientCallContextImpl"); 677 attr.setName("_call_ctx"); 678 ski.addAttribute(attr); 679 680 attr = new AttributeObjectImpl(); 682 attr.addComment("."); 683 attr.setModifier(ModifierKindImpl.mk_private); 684 attr.setType("java.util.Hashtable"); 685 attr.setName("_informations"); 686 ski.addAttribute(attr); 687 688 attr = new AttributeObjectImpl(); 690 attr.addComment("."); 691 attr.setModifier(ModifierKindImpl.mk_private); 692 attr.setType("org.omg.Components.EventConsumerBase"); 693 attr.setName("_consbase"); 694 ski.addAttribute(attr); 695 696 attr = new AttributeObjectImpl(); 698 attr.addComment("Typed delegate."); 699 attr.setModifier(ModifierKindImpl.mk_private); 700 attr.setType(getTranslator().getAbsoluteName(itf)); 701 attr.setName("_delegate"); 702 ski.addAttribute(attr); 703 704 ConstructorObject constructor = new ConstructorObjectImpl(); 707 ParameterObject parameter = new ParameterObjectImpl(); 709 parameter.setName("orbs"); 710 parameter.setType("ORBService"); 711 constructor.addParameter(parameter); 712 parameter = new ParameterObjectImpl(); 713 parameter.setName("sset"); 714 parameter.setType("ServicesSet"); 715 constructor.addParameter(parameter); 716 parameter = new ParameterObjectImpl(); 717 parameter.setName("uuid"); 718 parameter.setType("String"); 719 constructor.addParameter(parameter); 720 parameter = new ParameterObjectImpl(); 721 parameter.setName("del"); 722 parameter.setType("org.omg.CORBA.Object"); 723 constructor.addParameter(parameter); 724 constructor.getImpl().setMacro("STUBI_CONSTRUCTOR_BODY"); 726 constructor.getImpl().addContextValue("interface", itf); 727 ski.addConstructor(constructor); 728 729 MethodObject operation = new MethodObjectImpl(); 732 operation.addComment("."); 733 operation.setModifier(ModifierKindImpl.mk_private); 734 operation.setReturnType("CallInformation"); 735 operation.setName("_getCallInformation"); 736 parameter = new ParameterObjectImpl(); 737 parameter.setName("name"); 738 parameter.setType("String"); 739 operation.addParameter(parameter); 740 operation.getImpl().setMacro("STUBI_GETCALLINFORMATION_BODY"); 741 ski.addMethod(operation); 742 743 operation = new MethodObjectImpl(); 745 operation.addComment("."); 746 operation.setModifier(ModifierKindImpl.mk_private); 747 operation.setReturnType("short"); 748 operation.setName("_preinvoke"); 749 parameter = new ParameterObjectImpl(); 750 parameter.setName("ctrls"); 751 parameter.setType("org.coach.ECA.ClientCallController[]"); 752 operation.addParameter(parameter); 753 operation.getImpl().setMacro("STUBI_PREINVOKE_BODY"); 754 ski.addMethod(operation); 755 756 operation = new MethodObjectImpl(); 758 operation.addComment("."); 759 operation.setModifier(ModifierKindImpl.mk_private); 760 operation.setReturnType("short"); 761 operation.setName("_postinvoke"); 762 parameter = new ParameterObjectImpl(); 763 parameter.setName("fstate"); 764 parameter.setType("short"); 765 operation.addParameter(parameter); 766 operation.getImpl().setMacro("STUBI_POSTINVOKE_BODY"); 767 ski.addMethod(operation); 768 769 String sname = "::"+idl3decl.getName(); 772 if (idl3decl.getDeclKind()==DeclarationKind.dk_uses) { 773 sname = "::"+idl3decl.getParent().getName()+sname; 775 } 776 if (idl3decl.getDeclKind()==DeclarationKind.dk_emits) { 777 sname = "::"+idl3decl.getParent().getName()+sname; 779 } 780 if (idl3decl.getDeclKind()==DeclarationKind.dk_publishes) { 781 sname = "::"+idl3decl.getParent().getName()+sname; 783 } 784 785 Declaration[] decls = itf.getContents(false, DeclarationKind.dk_operation); 787 OperationDecl op = null; 788 for (int i=0;i<decls.length;i++) { 789 op = (OperationDecl)decls[i]; 790 791 792 addWrappedOperation(ski, op, op.getType(), sname+"::"+op.getName(), 793 op.getParameterList().getParameters(), 794 op.getExceptionList().getExceptions(), 795 "STUBI_WRAPPED_OPERATION"); 796 } 797 798 decls = itf.getContents(false, DeclarationKind.dk_attribute); 800 AttributeDecl attrdecl = null; 801 for (int i=0;i<decls.length;i++) { 802 attrdecl = (AttributeDecl)decls[i]; 803 804 if (attrdecl.isReadonly()) { 806 addWrappedOperation(ski, attrdecl, attrdecl.getType(), sname+"::_get_"+attrdecl.getName(), 808 new Parameter[0], attrdecl.getExceptions(), 809 "STUBI_WRAPPED_OPERATION"); 810 } 811 else { 812 addWrappedOperation(ski, attrdecl, attrdecl.getType(), sname+"::_get_"+attrdecl.getName(), 814 new Parameter[0], attrdecl.getGetExceptions(), 815 "STUBI_WRAPPED_OPERATION"); 816 817 Parameter[] params = new Parameter[] { 820 new ParameterImpl(attrdecl.getName(), attrdecl.getType(), org.omg.CORBA.ParameterMode.PARAM_IN) 821 }; 822 823 addWrappedOperation(ski, attrdecl, getAST().getVoidType(), sname+"::_set_"+attrdecl.getName(), 824 params, attrdecl.getSetExceptions(), 825 "STUBI_WRAPPED_OPERATION"); 826 827 } 828 } 829 830 getRepository().addObject(ski); 832 } 833 834 private void 835 addWrappedOperation(ClassObject ski, Declaration decl, TypeRef rtype, String ciname, 836 Parameter[] params, ExceptionDecl[] exceptions, 837 String macroname) 838 { 839 addWrappedOperation(ski, decl, rtype, ciname, params, exceptions, macroname, new String [0], new Object [0]); 840 } 841 842 private void 843 addWrappedOperation(ClassObject ski, Declaration decl, TypeRef rtype, String ciname, 844 Parameter[] params, ExceptionDecl[] exceptions, 845 String macroname, String ctxkey, Object ctxval) 846 { 847 String [] ctxkeys = { ctxkey }; 848 Object [] ctxvals = { ctxval }; 849 850 addWrappedOperation(ski, decl, rtype, ciname, params, exceptions, macroname, ctxkeys, ctxvals); 851 } 852 853 private void 854 addWrappedOperation(ClassObject ski, Declaration decl, TypeRef rtype, String ciname, 855 Parameter[] params, ExceptionDecl[] exceptions, 856 String macroname, String [] ctxkeys, Object [] ctxvals) 857 { 858 MethodObject operation = new MethodObjectImpl(); 859 operation.setReturnType(getTranslator().toJava(rtype)); 861 862 operation.setName(decl.getName()); 864 865 ParameterObject parameter = null; 867 for (int j=0;j<params.length;j++) { 868 parameter = new ParameterObjectImpl(); 869 parameter.setName(params[j].getName()); 870 parameter.setType(getTranslator().toJava(params[j].getType(), params[j].getMode())); 871 operation.addParameter(parameter); 872 } 873 String param_names = ""; 875 if (params.length!=0) { 877 for (int j=0;j<params.length-1;j++) { 878 param_names = param_names + params[j].getName() + ", "; 879 } 880 881 param_names = param_names + params[params.length-1].getName(); 882 } 883 operation.getImpl().addContextValue("parameter_list", param_names); 884 885 if (exceptions.length!=0) { 887 operation.getImpl().addContextValue("has_exceptions", new Boolean (true)); 888 String [] exc_absnames = new String [exceptions.length]; 889 for (int j=0;j<exceptions.length;j++) { 890 exc_absnames[j] = getTranslator().getAbsoluteName(exceptions[j]); 891 operation.addException(exc_absnames[j]); 892 } 893 operation.getImpl().addContextValue("exception_absnames", exc_absnames); 894 } 895 else { 896 operation.getImpl().addContextValue("has_exceptions", new Boolean (false)); 897 } 898 899 operation.getImpl().setMacro(macroname); 902 operation.getImpl().addContextValue("declaration", decl); 903 operation.getImpl().addContextValue("callinfo_name", ciname); 904 operation.getImpl().addContextValue("return_type", getTranslator().toJava(rtype)); 905 906 for (int i=0;i<ctxkeys.length;i++) { 908 operation.getImpl().addContextValue(ctxkeys[i], ctxvals[i]); 909 } 910 911 if (rtype.getTypeKind()!=TypeKind.tk_void) { 912 operation.getImpl().addContextValue("has_return_type", new Boolean (true)); 913 String return_type_extractor = getTranslator().toJavaAnyExtractor(rtype); 915 String return_type_insertor = getTranslator().toJavaAnyInsertor(rtype); 916 String return_null_value = getTranslator().toJavaNullValue(rtype); 918 if (rtype.isDeclaration()) { 919 return_type_extractor = return_type_extractor+"(_call_ctx.result())"; 920 return_type_insertor = return_type_insertor+"(anyres, res)"; 921 } 922 else { 923 return_type_extractor = "_call_ctx.result()."+return_type_extractor+"()"; 924 return_type_insertor = "anyres."+return_type_insertor+"(res)"; 925 } 926 operation.getImpl().addContextValue("return_type_extractor", return_type_extractor); 927 operation.getImpl().addContextValue("return_type_insertor", return_type_insertor); 928 operation.getImpl().addContextValue("return_null_value", return_null_value); 929 } 930 else { 931 operation.getImpl().addContextValue("has_return_type", new Boolean (false)); 932 } 933 934 935 ski.addMethod(operation); 937 } 938 939 943 final public void 944 generate(String basedir, Scope scope) 945 throws GenerationException 946 { 947 _repository = new RepositoryImpl(); 948 949 if (scope.getDeclKind()==DeclarationKind.dk_component) { 954 generateForComponent((ComponentDecl)scope); 955 } 956 else if (scope.getDeclKind()==DeclarationKind.dk_module) { 957 generateForModule((ModuleDecl)scope); 958 } 959 else { 960 System.err.println("object is not a component: aborting"); 961 return ; 962 } 963 964 971 String tpath = System.getProperty("ecm.templates"); 972 java.io.File tdir = new java.io.File (tpath); 973 974 JavaGenerator javagen = new JavaGenerator(); 976 java.util.Vector v = new java.util.Vector (); 977 v.add("ski.vm"); 978 v.add("stubi.vm"); 979 v.add("ifact.vm"); 980 javagen.initialize("Container Interceptors", v); 981 javagen.generate(getRepository(), basedir); 982 } 983 984 } 985 986 987 | Popular Tags |