indexing description: "Represents an advertisement" author: "Beat Strasser " date: "$Date$" revision: "$Revision$" deferred class P2P_ADVERTISEMENT inherit P2P_DOCUMENT ANY redefine out end P2P_ID_CREATOR export {NONE} all undefine out end feature {NONE} -- Initialization parse_from_string (source: STRING) is -- Parse document from string do create cached_document.parse_from_string (source) is_valid := cached_document.is_valid if is_valid then cached_document.handle_elements (agent element_handler) validate if not is_valid then clear_document end else clear_document end end make_from_element (source: XM_ELEMENT) is -- Create advertisement from xml element do create cached_document.make_from_root_element (source) is_valid := True cached_document.handle_elements (agent element_handler) validate if not is_valid then clear_document end end feature -- Access local_expiration_time: INTEGER -- Local expiration time (not included in document) remote_expiration_time: INTEGER -- Remote expiration time (not included in document) feature -- Element change set_local_expiration_time (time: INTEGER) is -- Set local expiration time do local_expiration_time := time ensure Time_set: local_expiration_time = time end set_remote_expiration_time (time: INTEGER) is -- Set remote expiration time do remote_expiration_time := time ensure Time_set: remote_expiration_time = time end feature -- Output out: STRING is -- String representation do Result := document.out end document: P2P_XML_DOCUMENT is -- Create XML document require Advertisement_valid: is_valid do if cached_document = Void then create cached_document.make_with_jxta_root (root_element_name) end Result := cached_document ensure Result_set: Result /= Void end feature {NONE} -- Implementation root_element_name: STRING is -- Root element name deferred end element_handler (child_element: XM_ELEMENT) is -- Handle a root child element of a parsed advertisement document require Element_existent: child_element /= Void deferred end validate is -- Validate advertisement and set `is_valid' do -- The implementation here currently doesn't add any restrictions end cached_document: P2P_XML_DOCUMENT renew_document, clear_document is -- Clear document cache do cached_document := Void end element_text (an_element: XM_ELEMENT): STRING is -- Concatenation of elements children text require Element_valid: an_element /= Void do Result := an_element.text if Result = Void then create Result.make_empty end ensure Result_set: Result /= Void end end