indexing description: "Represents a pipe advertisement" license: "MIT license (see ../../license.txt)" author: "Beat Strasser " date: "$Date$" revision: "$Revision$" class P2P_PIPE_ADVERTISEMENT inherit P2P_ADVERTISEMENT redefine document, validate end create make, make_from_element, parse_from_string feature {NONE} -- Initialization make (a_id: like id; a_type: like type) is -- Create new pipe advertisement require Id_valid: a_id /= Void Type_valid: a_type /= Void do initialize set_id (a_id) set_type (a_type) is_valid := True ensure Id_set: id.is_equal (a_id) Type_set: type.is_equal (a_type) end feature -- Access id: P2P_PIPE_ID type: STRING name: STRING index_elements: DS_LIST [TUPLE [STRING, STRING]] is -- Indexable elements do if name /= Void then create {DS_ARRAYED_LIST [TUPLE [STRING, STRING]]} Result.make (2) Result.put_last ([element_name, name]) else create {DS_ARRAYED_LIST [TUPLE [STRING, STRING]]} Result.make (1) end Result.put_last ([element_id, id.out]) end unique_id: STRING is -- Unique id do Result := id.out_short end match (an_element_name, an_element_value: STRING): BOOLEAN is -- Is given element's value equal with `an_element_value'? do if element_id.is_equal (an_element_name) then Result := does_element_match (id, an_element_value) elseif element_type.is_equal (an_element_name) then Result := does_element_match (type, an_element_value) elseif element_name.is_equal (an_element_name) then Result := does_element_match (name, an_element_value) end end feature -- Element change set_id (a_id: like id) is -- Set new pipe id require Id_valid: a_id /= Void do id := a_id renew_document ensure Id_set: id.is_equal (a_id) end set_type (a_type: like type) is -- Set new type require Type_valid: a_type /= Void do type := a_type renew_document ensure Type_set: type.is_equal (a_type) end set_name (a_name: like name) is -- Set new name require Name_valid: a_name /= Void do name := a_name renew_document ensure Name_set: name.is_equal (a_name) end feature -- Output document: P2P_XML_DOCUMENT is -- Create XML document local cached: BOOLEAN do cached := cached_document /= Void -- create document Result := Precursor if not cached then -- element Id Result.create_root_child_element (element_id, Result.namespace_empty) Result.create_content (Result.last_element, id.out) -- element Type Result.create_root_child_element (element_type, Result.namespace_empty) Result.create_content (Result.last_element, type) -- element Name if name /= Void then Result.create_root_child_element (element_name, Result.namespace_empty) Result.create_content (Result.last_element, name) end end end feature {NONE} -- Implementation Element_id: STRING is "Id" Element_type: STRING is "Type" Element_name: STRING is "Name" Type_id: STRING is "jxta:JXTAID" Type_type: STRING is "xs:string" Type_name: STRING is "xs:string" root_element_name: STRING is "PipeAdvertisement" element_handler (element: XM_ELEMENT) is -- Handle root child element of parsed advertisement do if element_id.is_equal (element.name) then create id.make_from_urn (element_text (element)) if not id.is_valid then id := Void end elseif element_type.is_equal (element.name) then type := trimmed (element.text) elseif element_name.is_equal (element.name) then name := trimmed (element.text) end end validate is -- Validate advertisement and set `is_valid' do is_valid := is_valid and id /= Void and type /= Void end end