note description: "[ Factory to create message objects. GENERATED DO NOT MODIFY! ]" author: "Origo Team " date: "$Date$" revision: "$Revision$" class A_MESSAGE_FACTORY inherit A_CONFIG_CONSTANTS A_EXAMPLE_CONSTANTS A_MAIL_CONSTANTS A_SYSTEM_CONSTANTS A_CONSTANTS A_GENERAL_CONSTANTS A_SYSTEM_CONSTANTS create make feature {NONE} -- Initialization make -- Initialize. do create handler_registry.make (5) register_builtin_handlers end feature -- Status is_error: BOOLEAN -- Was there an error? feature -- Update register_handler (a_namespace, a_type: STRING; a_handler: like handler_type) -- Register a handler. require a_namespace_ok: a_namespace /= Void and then not a_namespace.is_empty a_type_ok: a_type /= Void and then not a_type.is_empty a_handler_ok: a_handler /= Void local l_hnd: HASH_TABLE [like handler_type, STRING] do l_hnd := handler_registry.item (a_namespace) if l_hnd = Void then create l_hnd.make (5) handler_registry.force (l_hnd, a_namespace) end l_hnd.force (a_handler, a_type) end feature -- Basic operation new_message_from_ems_message (a_msg: MESSAGE): A_MESSAGE -- Create a new aranea message from an ems MAP_MESSAGE. require valid_ems_message: is_valid_ems_message (a_msg) local l_hnd: HASH_TABLE [like handler_type, STRING] do if not is_error then -- check if we have a handler to get a specific message l_hnd := handler_registry.item (a_msg.get_string_property (namespace_element)) if l_hnd /= Void then if l_hnd.has_key (a_msg.get_string_property (type_element)) then Result := l_hnd.found_item.item ([a_msg]) end end if Result = Void then -- just generate a generic message create {A_GENERIC_MESSAGE} Result.make_from_ems_message (a_msg) end end ensure Error_or_not_void: not is_error implies Result /= Void end feature -- Validity is_valid_ems_message (a_msg: MESSAGE): BOOLEAN -- Is a_msg a valid ems message? do Result := a_msg /= Void and then a_msg.get_string_property (namespace_element) /= Void and a_msg.get_string_property (type_element) /= Void end feature -- Creator handlers new_general_status (a_msg: MESSAGE): A_GENERAL_STATUS_MESSAGE -- Create new general status message out of a_msg. require a_msg_not_void: a_msg /= Void do create Result.make_from_ems_message (a_msg) ensure Error_or_not_void: not is_error implies Result /= Void end new_general_string (a_msg: MESSAGE): A_GENERAL_STRING_MESSAGE -- Create new general string message out of a_msg. require a_msg_not_void: a_msg /= Void do create Result.make_from_ems_message (a_msg) ensure Error_or_not_void: not is_error implies Result /= Void end new_config_command (a_msg: MESSAGE): A_CONFIG_COMMAND_MESSAGE -- Create new typed message out of a_msg. require a_msg_not_void: a_msg /= Void do create Result.make_from_ems_message (a_msg) ensure Error_or_not_void: not is_error implies Result /= Void end new_config_command_list (a_msg: MESSAGE): A_CONFIG_COMMAND_LIST_MESSAGE -- Create new typed message out of a_msg. require a_msg_not_void: a_msg /= Void do create Result.make_from_ems_message (a_msg) ensure Error_or_not_void: not is_error implies Result /= Void end new_config_file_write (a_msg: MESSAGE): A_CONFIG_FILE_WRITE_MESSAGE -- Create new typed message out of a_msg. require a_msg_not_void: a_msg /= Void do create Result.make_from_ems_message (a_msg) ensure Error_or_not_void: not is_error implies Result /= Void end new_config_file_write_list (a_msg: MESSAGE): A_CONFIG_FILE_WRITE_LIST_MESSAGE -- Create new typed message out of a_msg. require a_msg_not_void: a_msg /= Void do create Result.make_from_ems_message (a_msg) ensure Error_or_not_void: not is_error implies Result /= Void end new_example_simple (a_msg: MESSAGE): A_EXAMPLE_SIMPLE_MESSAGE -- Create new typed message out of a_msg. require a_msg_not_void: a_msg /= Void do create Result.make_from_ems_message (a_msg) ensure Error_or_not_void: not is_error implies Result /= Void end new_example_simple_extended (a_msg: MESSAGE): A_EXAMPLE_SIMPLE_EXTENDED_MESSAGE -- Create new typed message out of a_msg. require a_msg_not_void: a_msg /= Void do create Result.make_from_ems_message (a_msg) ensure Error_or_not_void: not is_error implies Result /= Void end new_example_special (a_msg: MESSAGE): A_EXAMPLE_SPECIAL_MESSAGE -- Create new typed message out of a_msg. require a_msg_not_void: a_msg /= Void do create Result.make_from_ems_message (a_msg) ensure Error_or_not_void: not is_error implies Result /= Void end new_example_complex (a_msg: MESSAGE): A_EXAMPLE_COMPLEX_MESSAGE -- Create new typed message out of a_msg. require a_msg_not_void: a_msg /= Void do create Result.make_from_ems_message (a_msg) ensure Error_or_not_void: not is_error implies Result /= Void end new_mail_send (a_msg: MESSAGE): A_MAIL_SEND_MESSAGE -- Create new typed message out of a_msg. require a_msg_not_void: a_msg /= Void do create Result.make_from_ems_message (a_msg) ensure Error_or_not_void: not is_error implies Result /= Void end new_system_status_request (a_msg: MESSAGE): A_SYSTEM_STATUS_REQUEST_MESSAGE -- Create new typed message out of a_msg. require a_msg_not_void: a_msg /= Void do create Result.make_from_ems_message (a_msg) ensure Error_or_not_void: not is_error implies Result /= Void end feature {NONE} -- Implementation handler_registry: HASH_TABLE [HASH_TABLE [like handler_type, STRING], STRING] -- Handlers to create specific messages. register_builtin_handlers -- Register the builtin handlers. do register_handler (general_namespace, general_status_type, agent new_general_status) register_handler (general_namespace, general_string_type, agent new_general_string) register_handler (config_namespace, config_command_type, agent new_config_command) register_handler (config_namespace, config_command_list_type, agent new_config_command_list) register_handler (config_namespace, config_file_write_type, agent new_config_file_write) register_handler (config_namespace, config_file_write_list_type, agent new_config_file_write_list) register_handler (example_namespace, example_simple_type, agent new_example_simple) register_handler (example_namespace, example_simple_extended_type, agent new_example_simple_extended) register_handler (example_namespace, example_special_type, agent new_example_special) register_handler (example_namespace, example_complex_type, agent new_example_complex) register_handler (mail_namespace, mail_send_type, agent new_mail_send) register_handler (system_namespace, system_status_request_type, agent new_system_status_request) end feature {NONE} -- Type anchors handler_type: FUNCTION [ANY, TUPLE [MESSAGE], A_MESSAGE] -- Type of the message creators, indexed by namespace and type. invariant handler_registry_not_void: handler_registry /= Void end