- if not os.path.exists(notification_package):
- os.mkdir(notification_package)
-
- callbacks = []
- register_callback_methods = []
- register_callback_methods_impl = []
- handler_methods = []
- for func in func_list:
-
- if not util.is_reply(func['name']) and not util.is_notification(func['name']):
- continue
-
- camel_case_name_with_suffix = util.underscore_to_camelcase_upper(func['name'])
- if util.is_control_ping(camel_case_name_with_suffix):
- continue
- notification_dto = camel_case_name_with_suffix
- callback_ifc = camel_case_name_with_suffix + callback_gen.callback_suffix
- fully_qualified_callback_ifc = "{0}.{1}.{2}".format(plugin_package, callback_package, callback_ifc)
- callbacks.append(fully_qualified_callback_ifc)
-
- # TODO create NotificationListenerRegistration and return that instead of AutoCloseable to better indicate
- # that the registration should be closed
- register_callback_methods.append("java.lang.AutoCloseable register{0}({1} callback);"
- .format(callback_ifc, fully_qualified_callback_ifc))
- register_callback_methods_impl.append(register_callback_impl_template.substitute(plugin_package=plugin_package,
- callback_package=callback_package,
- dto_package=dto_package,
- notification=camel_case_name_with_suffix,
- callback=callback_ifc))
- handler_methods.append(handler_impl_template.substitute(base_package=base_package,
- plugin_package=plugin_package,
- callback_package=callback_package,
- dto_package=dto_package,
- notification=notification_dto,
- notification_reply=camel_case_name_with_suffix,
- callback=callback_ifc))
-
-
- callback_file = open(os.path.join(notification_package, "%sEventRegistry.java" % plugin_name), 'w')
- callback_file.write(notification_registry_template.substitute(inputfile=inputfile,
- register_callback_methods="\n ".join(register_callback_methods),
- base_package=base_package,
- plugin_package=plugin_package,
- plugin_name=plugin_name,
- notification_package=notification_package))
- callback_file.flush()
- callback_file.close()
-
- callback_file = open(os.path.join(notification_package, "Global%sEventCallback.java" % plugin_name), 'w')
-
- global_notification_callback_callbacks = ""
- if callbacks:
- global_notification_callback_callbacks = " extends " + ", ".join(callbacks)
-
- callback_file.write(global_notification_callback_template.substitute(inputfile=inputfile,
- callbacks=global_notification_callback_callbacks,
- plugin_package=plugin_package,
- plugin_name=plugin_name,
- notification_package=notification_package))
- callback_file.flush()
- callback_file.close()
-
- callback_file = open(os.path.join(notification_package, "%sEventRegistryImpl.java" % plugin_name), 'w')
- callback_file.write(notification_registry_impl_template.substitute(inputfile=inputfile,
- callback_package=callback_package,
- dto_package=dto_package,
- register_callback_methods="".join(register_callback_methods_impl),
- handler_methods="".join(handler_methods),
- base_package=base_package,
- plugin_package=plugin_package,
- plugin_name=plugin_name,
- notification_package=notification_package))
- callback_file.flush()
- callback_file.close()
-
- callback_file = open(os.path.join(notification_package, "%sEventRegistryProvider.java" % plugin_name), 'w')
- callback_file.write(notification_provider_template.substitute(inputfile=inputfile,
- base_package=base_package,
- plugin_package=plugin_package,
- plugin_name=plugin_name,
- notification_package=notification_package))
- callback_file.flush()
- callback_file.close()