# encoding: utf-8 """ Docstring for comp2java """ __author__ = 'Raphael.Marvie@lifl.fr' __date__ = '2007-11-12' from component.loader import Loader from java.core import Repository, Factory from java.dumper import Dumper # chargement du modele composant crepository = Loader().load('cobserver.xmi') # initialiser le modele java jrepository = Repository() factory = Factory(jrepository) # transformation interface vers classe for itf in crepository.Interface: clss = factory.create_Class() clss.name = itf.name for o in itf.operations: meth = factory.create_Method() meth.return_type = o.return_type meth.name = o.name clss.methods.append(meth) for a in o.arguments: arg = factory.create_Argument() arg.name = a.name arg.type = a.type meth.arguments.append(arg) # transformation composant vers classe for c in crepository.Component: clss = factory.create_Class() clss.name = c.name for p in c.provides: attr = factory.create_Attribute() attr.name = '_' + p.name.lower() attr.type = p.name clss.attributes.append(attr) meth = factory.create_Method() meth.return_type = 'void' meth.name = 'provides_' + p.name.lower() clss.methods.append(meth) for p in c.uses: attr = factory.create_Attribute() attr.name = '_' + p.name.lower() attr.type = p.name clss.attributes.append(attr) meth = factory.create_Method() meth.return_type = 'void' meth.name = 'connect_' + p.name.lower() clss.methods.append(meth) meth = factory.create_Method() meth.return_type = 'void' meth.name = 'disconnect_' + p.name.lower() clss.methods.append(meth) # serialisation du modèle résultat en XMI Dumper().dump(jrepository, 'jobserver.xmi') # eof