indexing description: "General Origo service configuration" license: "MIT license (see ../../license.txt)" author: "Beat Strasser " date: "$Date$" revision: "$Revision$" deferred class O_SERVICE_CONFIGURATION inherit P2P_XML_CACHE redefine document, validate, initialize end feature {NONE} -- Initialization make (a_value_list: DS_LIST [STRING]) is -- Create new Origo service control message require List_valid: a_value_list /= Void and a_value_list.count = valid_keys.count local key_cursor: DS_LIST_CURSOR [STRING] do initialize from a_value_list.start key_cursor := valid_keys.new_cursor key_cursor.start until a_value_list.after or key_cursor.after loop set_item (key_cursor.item, a_value_list.item_for_iteration) a_value_list.forth key_cursor.forth end is_valid := True validate end feature -- Access valid_keys: DS_LIST [STRING] is -- Valid keys deferred ensure Result_set: Result /= Void and Result.count > 0 end match (an_element_name, an_element_value: STRING): BOOLEAN is -- Is given element's value equal with `an_element_value'? do if valid_key (an_element_name) then Result := does_element_match (configuration.item (an_element_name), an_element_value) end end item (a_key: STRING): STRING is -- Current value for given `a_key' require Key_valid: a_key /= Void and valid_key (a_key) do Result := configuration.item (a_key) end valid_key (a_key: STRING): BOOLEAN is -- Is `a_key' a valid key? require Key_valid: a_key /= Void do Result := configuration.has (a_key) end feature -- Element change set_item (a_key, a_value: STRING) is -- Set `a_value' for `a_key' require Key_valid: a_key /= Void and valid_key (a_key) Value_valid: a_value /= Void do configuration.force (a_value, a_key) renew_document ensure Item_set: item (a_key).is_equal (a_value) end feature -- Output document: P2P_XML_DOCUMENT is -- Create XML document local cached: BOOLEAN cursor: DS_HASH_TABLE_CURSOR [STRING, STRING] do cached := cached_document /= Void -- create document Result := Precursor if not cached then -- create all elements from cursor := configuration.new_cursor cursor.start until cursor.after loop Result.create_root_child_element (cursor.key, Result.namespace_empty) Result.create_content (Result.last_element, cursor.item) cursor.forth end end end feature {NONE} -- Implementation configuration: DS_HASH_TABLE [STRING, STRING] attribute_handler (root_attribute: XM_ATTRIBUTE) is -- No attributes do end element_handler (element: XM_ELEMENT) is -- Handle root child element of parsed configuration do if valid_key (element.name) then configuration.force (trimmed (element.text), element.name) end end validate is -- Validate message and set `is_valid' local cursor: DS_HASH_TABLE_CURSOR [STRING, STRING] do from cursor := configuration.new_cursor cursor.start until not is_valid or cursor.after loop is_valid := configuration.item (cursor.key) /= Void cursor.forth end end initialize is -- Initialize data structure local equality_tester: KL_EQUALITY_TESTER [STRING] key_cursor: DS_LIST_CURSOR [STRING] do Precursor create configuration.make (valid_keys.count) create equality_tester configuration.set_equality_tester (equality_tester) configuration.set_key_equality_tester (equality_tester) -- initialize configurations hash table from key_cursor := valid_keys.new_cursor key_cursor.start until key_cursor.after loop configuration.put (Void, key_cursor.item) key_cursor.forth end end end