1 26 package org.objectweb.corba.generator.metainformation.lib; 27 28 29 31 import org.objectweb.openccm.ast.api.*; 32 import org.objectweb.openccm.generator.java.core.lib.*; 33 import org.objectweb.openccm.generator.java.ast.api.*; 34 import org.objectweb.openccm.generator.java.ast.lib.*; 35 import org.objectweb.openccm.generator.translator.idl2java.lib.CommonTranslator; 36 import org.objectweb.openccm.generator.common.lib.FileManager; 37 import org.objectweb.openccm.generator.common.lib.GenerationException; 38 39 52 53 public class IDL_JavaMIGenerator 54 extends org.objectweb.openccm.generator.common.lib.GeneratorBase 55 implements org.objectweb.corba.generator.metainformation.api.IDL_JavaMIGenerator 56 { 57 63 64 private Repository _repository; 65 private Scope CCMObj_scope; 66 67 public CommonTranslator _translator; 68 private AST _ast; 69 private String _scope_name; 70 71 74 75 81 92 93 public IDL_JavaMIGenerator(AST ast) 94 { 95 super(ast); 96 _repository = null; 97 _translator = new CommonTranslator(); 98 CCMObj_scope = null; 99 try 100 { 101 CCMObj_scope = (Scope) ast.lookup("::Components::CCMObject"); 102 } 103 catch (ClassCastException e) 104 { 105 System.err.println("Declaration of CCMObject not found!"); 106 } 107 108 _ast = ast; 109 } 110 111 112 118 128 129 private void mapHomeMI(HomeDecl _home_decl, String pkg_name) 130 { 131 int i; 132 133 ClassObject clazz = null; 134 ConstructorObject _cstr = null; 135 136 138 String home_mi_class_name = _home_decl.getName() + "_homeMI"; clazz = new ClassObjectImpl(home_mi_class_name); 141 143 clazz.addComment("This class represents the home type MetaInformation for the given " + _home_decl.getName()); 145 clazz.setModifier(ModifierKindImpl.mk_public); 147 clazz.setPackage(pkg_name); 149 clazz.addInheritedObject("org.objectweb.openccm.Containers.MetaInformation.HomeTypeImpl"); 151 152 clazz.addImport("org.objectweb.openccm.Containers.MetaInformation.*"); 153 156 _cstr = new ConstructorObjectImpl(); 157 _cstr.getImpl().setMacro("HOME_MI_CONSTRUCTOR"); 159 161 _cstr.getImpl().addContextValue("name", _home_decl.getName()); _cstr.getImpl().addContextValue("rep_id", _home_decl.getId()); _cstr.getImpl().addContextValue("type_instance_factory_entrypt", 164 pkg_name + "."+_home_decl.getName() + "CCM"); 165 166 170 _cstr.getImpl().addContextValue("component_class_name", 171 _home_decl.getManagedComponent().getName()); 172 174 Declaration[] _home_atts = _home_decl.getContents(true,DeclarationKind.dk_attribute); 175 if(_home_atts.length != 0) 176 { 177 _cstr.getImpl().addContextValue("att_list", _home_atts); 178 } 179 180 184 InterfaceDecl[] intfs = _home_decl.getSupportedInterfaceList().getInterfaces(); 186 if (intfs.length != 0) 188 { 189 _cstr.getImpl().addContextValue("interface_list", intfs); 190 for (int j = 0; j < intfs.length; j++) 193 { 194 if (!(intfs[j].getAbsoluteName().startsWith(_scope_name))) 196 { 197 Declaration _imported = _ast.lookup(intfs[j].getAbsoluteName()); 199 mapInterfaceMI((InterfaceDecl) _imported, pkg_name); 200 } 201 } 202 } 203 204 207 clazz.addConstructor(_cstr); 208 209 211 MethodObjectImpl _met = new MethodObjectImpl(); 212 213 _met.setName("create_type_MI"); 214 _met.setReturnType("HomeType"); 215 _met.setModifier(ModifierKindImpl.mk_public); 216 _met.setStatic(true); 217 _met.addComment("static entrypt for container and installation"); 218 219 _met.getImpl().setMacro("STATIC_CALL_HOME_MI"); 220 _met.getImpl().addContextValue("classname",_home_decl.getName() + "_homeMI"); 221 222 clazz.addMethod(_met); 223 226 _repository.addObject(clazz); 227 228 233 235 String home_equv_itf_mi_class_name = _home_decl.getName() + "_interfaceMI"; clazz = new ClassObjectImpl(home_equv_itf_mi_class_name); 238 240 clazz.addComment("This class represents the home equivalent interface type MetaInformation "); 242 clazz.addComment("for the given " + _home_decl.getName()); 243 clazz.setModifier(ModifierKindImpl.mk_public); 245 clazz.setPackage(pkg_name); 247 clazz.addInheritedObject("org.objectweb.openccm.Containers.MetaInformation.InterfaceTypeImpl"); 249 250 clazz.addImport("org.objectweb.openccm.Containers.MetaInformation.*"); 251 254 _cstr = new ConstructorObjectImpl(); 255 _cstr.getImpl().setMacro("HOME_EQUIV_ITF"); AttributeObject param1 = new AttributeObjectImpl(); 257 param1.setName("type_ref"); 258 param1.setType("TypeImpl"); 259 _cstr.addParameter(param1); 260 AttributeObject param2 = new AttributeObjectImpl(); 261 param2.setName("type_ki"); 262 param2.setType("type_kind"); 263 _cstr.addParameter(param2); 264 265 267 _cstr.getImpl().addContextValue("name", "???"); _cstr.getImpl().addContextValue("rep_id", "???"); _cstr.getImpl().addContextValue("type_instance_factory_entrypt", 270 "???"); 272 274 Declaration[] _equiv_itf_decl = _home_decl 275 .getClientMapping() 276 .getContents(false, DeclarationKind.dk_operation); 277 278 _cstr.getImpl().addContextValue("opt_list",_equiv_itf_decl); 279 280 clazz.addConstructor(_cstr); 281 282 284 _repository.addObject(clazz); 285 }; 286 287 298 299 private void mapComponentMI(ComponentDecl decl, String pkg_name) 300 { 301 ClassObject clazz = null; 302 ConstructorObject ct = null; 303 304 306 String class_name = new String (decl.getName() + "_componentMI"); 307 clazz = new ClassObjectImpl(class_name); 308 309 311 clazz.addImport("org.objectweb.openccm.Containers.MetaInformation.*"); 312 313 clazz.addComment("This class is the component type MetaInformation"); 314 clazz.addComment("for the given component. It gathers static properties"); 315 clazz.addComment("of CCM concepts managed by the related component"); 316 clazz.setModifier(ModifierKindImpl.mk_public); clazz.setPackage(pkg_name); clazz.addInheritedObject("org.objectweb.openccm.Containers.MetaInformation.ComponentTypeImpl"); 319 320 323 ct = new ConstructorObjectImpl(); 324 ct.getImpl().setMacro("COMPONENT_MI_CONSTRUCTOR"); AttributeObject param = new AttributeObjectImpl(); 326 param.setName("home_type"); 327 param.setType("HomeTypeImpl"); 328 ct.addParameter(param); 329 330 332 ct.getImpl().addContextValue("name", decl.getName()); 333 ct.getImpl().addContextValue("rep_id", decl.getId()); 334 ct.getImpl().addContextValue("type_instance_factory_entrypt", "???"); 335 336 339 ComponentDecl _tmp_comp = decl.getBaseComponent(); 340 341 345 InterfaceDecl[] _intf_decl = decl.getSupportedInterfaceList().getInterfaces(); 347 if(_intf_decl.length != 0) 349 { 350 ct.getImpl().addContextValue("int_list", _intf_decl); 351 } 352 for (int i = 0; i < _intf_decl.length; i++) 354 { 355 if(!(_intf_decl[i].getAbsoluteName().startsWith(_scope_name))) 357 { 358 Declaration _imported = _ast.lookup(_intf_decl[i].getAbsoluteName()); 360 mapInterfaceMI((InterfaceDecl) _imported, pkg_name); 361 } 362 } 363 364 368 Declaration[] _att_decl = decl.getContents(false,DeclarationKind.dk_attribute); 369 370 if(_att_decl.length != 0) 371 { 372 ct.getImpl().addContextValue("att_list", _att_decl); 373 } 374 375 379 381 Declaration[] _facet_decl = decl.getContents(false, DeclarationKind.dk_provides); 382 383 if (_facet_decl.length != 0) 384 { 385 ct.getImpl().addContextValue("facet_list", _facet_decl); 386 } 387 388 390 ProvidesDecl _prov_decl = null; 391 Declaration[] _tmp; 392 393 for (int i = 0; i < _facet_decl.length; i++) 394 { 395 _prov_decl = (ProvidesDecl) _facet_decl[i]; 397 _tmp = _prov_decl.getDependencies(); 399 Declaration itf_decl = _ast.lookup(_tmp[0].getAbsoluteName()); 401 if(!(itf_decl.getAbsoluteName().startsWith(_scope_name)) && (itf_decl != null)) 403 { 404 mapInterfaceMI((InterfaceDecl) itf_decl, pkg_name); 405 } 406 } 407 408 412 414 Declaration[] _receptacle_decl = decl.getContents(false,DeclarationKind.dk_uses); 415 416 if(_receptacle_decl.length != 0) 417 { 418 ct.getImpl().addContextValue("receptacle_list", _receptacle_decl); 419 } 420 421 423 UsesDecl _uses_decl = null; 424 425 for (int i = 0; i < _receptacle_decl.length; i++) 426 { 427 _uses_decl = (UsesDecl) _receptacle_decl[i]; 429 _tmp = _uses_decl.getDependencies(); 431 Declaration itf_decl = _ast.lookup(_tmp[0].getAbsoluteName()); 433 if (!(itf_decl.getAbsoluteName().startsWith(_scope_name)) 435 && (itf_decl != null)) 436 { 437 mapInterfaceMI((InterfaceDecl) itf_decl, pkg_name); 438 } 439 } 440 441 443 Declaration[] _consumer_decl = decl.getContents(false,DeclarationKind.dk_consumes); 444 445 if(_consumer_decl.length != 0) 446 { 447 ct.getImpl().addContextValue("consumer_list", _consumer_decl); 448 } 449 450 452 Declaration[] _emitter_decl = decl.getContents(false, DeclarationKind.dk_emits); 453 454 if(_emitter_decl.length != 0) 455 { 456 ct.getImpl().addContextValue("emitter_list", _emitter_decl); 457 } 458 459 461 Declaration[] _publisher_decl = decl.getContents(false, DeclarationKind.dk_publishes); 462 463 if(_publisher_decl.length != 0) 464 { 465 ct.getImpl().addContextValue("publisher_list", _publisher_decl); 466 } 467 468 470 clazz.addConstructor(ct); 471 _repository.addObject(clazz); 472 473 474 480 482 String comp_equv_itf_mi_class_name = decl.getName() + "_interfaceMI"; clazz = new ClassObjectImpl(comp_equv_itf_mi_class_name); 485 487 clazz.addComment("This class represents the component equivalent interface type MetaInformation "); 489 clazz.addComment("for the given " + decl.getName()); 490 clazz.setModifier(ModifierKindImpl.mk_public); 492 clazz.setPackage(pkg_name); 494 clazz.addInheritedObject("org.objectweb.openccm.Containers.MetaInformation.InterfaceTypeImpl"); 496 497 clazz.addImport("org.objectweb.openccm.Containers.MetaInformation.*"); 498 501 ct = new ConstructorObjectImpl(); 502 ct.getImpl().setMacro("COMP_EQUIV_ITF"); AttributeObject param1 = new AttributeObjectImpl(); 504 param1.setName("type_ref"); 505 param1.setType("TypeImpl"); 506 ct.addParameter(param1); 507 AttributeObject param2 = new AttributeObjectImpl(); 508 param2.setName("type_ki"); 509 param2.setType("type_kind"); 510 ct.addParameter(param2); 511 512 514 ct.getImpl().addContextValue("name", "???"); ct.getImpl().addContextValue("rep_id", "???"); ct.getImpl().addContextValue("type_instance_factory_entrypt", 517 "???"); 519 521 Declaration[] _equiv_itf_decl = CCMObj_scope.getContents(false, DeclarationKind.dk_operation); 522 523 ct.getImpl().addContextValue("opt_list",_equiv_itf_decl); 524 525 clazz.addConstructor(ct); 526 527 529 _repository.addObject(clazz); 530 531 }; 532 533 544 545 private void mapInterfaceMI(InterfaceDecl decl, String pkg_name) 546 { 547 ClassObject clazz = null; 548 ConstructorObject ct = null; 549 550 552 String class_name = new String (decl.getName() + "_interfaceMI"); 553 clazz = new ClassObjectImpl(class_name); 554 555 clazz.addImport("org.objectweb.openccm.Containers.MetaInformation.*"); 557 clazz.addComment("This class is the interface type MetaInformation"); 558 clazz.addComment("for the given interface. It gathers static properties"); 559 clazz.addComment("of CCM concepts managed by the related interface"); 560 clazz.setModifier(ModifierKindImpl.mk_public); clazz.setPackage(pkg_name); clazz.addInheritedObject("org.objectweb.openccm.Containers.MetaInformation.InterfaceTypeImpl"); 563 564 567 ct = new ConstructorObjectImpl(); 568 ct.getImpl().setMacro("INTERFACE_MI_CONSTRUCTOR"); AttributeObject param1 = new AttributeObjectImpl(); 570 param1.setName("type_ref"); 571 param1.setType("TypeImpl"); 572 ct.addParameter(param1); 573 AttributeObject param2 = new AttributeObjectImpl(); 574 param2.setName("type_ki"); 575 param2.setType("type_kind"); 576 ct.addParameter(param2); 577 578 580 ct.getImpl().addContextValue("name", decl.getName()); 581 ct.getImpl().addContextValue("rep_id",decl.getId()); 582 ct.getImpl().addContextValue("type_instance_factory_entrypt", 583 "???"); 584 586 Declaration[] att_decl = decl.getContents(true, DeclarationKind.dk_attribute); 587 588 if(att_decl.length != 0) 589 { 590 ct.getImpl().addContextValue("att_list", att_decl); 591 } 592 593 595 Declaration[] opt_decl = decl.getContents(true, DeclarationKind.dk_operation); 596 597 if(opt_decl.length != 0) 598 { 599 ct.getImpl().addContextValue("opt_list", opt_decl); 600 } 601 602 clazz.addConstructor(ct); 603 _repository.addObject(clazz); 604 }; 605 606 607 613 622 623 public void idl_to_java(String outputDir, Scope scope) 624 throws org.objectweb.openccm.generator.common.lib.GenerationException 625 { 626 int i; 628 String package_name; 629 java.io.File out_dir = null; 630 _repository = new RepositoryImpl(); 631 632 Declaration[] declared_homes = null; 633 Declaration[] declared_components = null; 634 Declaration[] declared_interfaces = null; 635 636 _scope_name = scope.getAbsoluteName(); 638 639 try{ 641 out_dir = FileManager.mkdir(outputDir); 642 }catch(GenerationException ex){ 644 System.err.println(ex.getMessage()); 645 return; 646 } 647 648 652 declared_homes = scope.getContents(false, DeclarationKind.dk_home); declared_components = scope.getContents(false, DeclarationKind.dk_component); declared_interfaces = scope.getContents(false, DeclarationKind.dk_interface); 656 659 661 for(i=0;i<declared_homes.length;i++) 662 { 663 665 HomeDecl _home_decl = (HomeDecl) declared_homes[i]; package_name = _translator.getPackage(_home_decl); mapHomeMI(_home_decl, package_name); } 669 670 672 for(i=0;i<declared_components.length;i++) 673 { 674 ComponentDecl _comp_decl = (ComponentDecl) declared_components[i]; package_name = _translator.getPackage(_comp_decl); mapComponentMI(_comp_decl,package_name); } 678 679 681 for(i=0;i<declared_interfaces.length;i++) 682 { 683 InterfaceDecl _intf_decls = (InterfaceDecl) declared_interfaces[i]; 684 package_name = _translator.getPackage(_intf_decls); 685 mapInterfaceMI(_intf_decls, package_name); 686 } 687 688 691 org.objectweb.openccm.generator.java.core.lib.JavaGenerator java_gen = new JavaGenerator(); 692 java.util.Vector v = new java.util.Vector (); 693 v.add("org/objectweb/corba/generator/metainformation/metainformation.vm"); 694 java_gen.initialize("metainformation", v); 695 java_gen.generate(_repository, outputDir); 696 } 697 } 698 | Popular Tags |