indexing description: "Represents a tcp transport configuration document" license: "MIT license (see ../../../license.txt)" author: "Beat Strasser " date: "$Date$" revision: "$Revision$" class P2P_TCP_CONFIGURATION inherit P2P_XML_CACHE redefine document, initialize end create make, make_auto, make_from_element, parse_from_string feature {NONE} -- Initialization make (an_address: like interface_address; a_port: like port) is -- Create new tcp transport configuration with given `a_port' require Address_valid: an_address /= Void do initialize set_interface_address (an_address) set_port (a_port) is_valid := True ensure Port_set: port = a_port Address_set: interface_address.is_equal (an_address) Valid: is_valid end make_auto is -- Create new tcp transport configuration with automatic configuration do initialize is_valid := True ensure Valid: is_valid end feature -- Access port: INTEGER multicast_enabled: BOOLEAN interface_address: STRING match (an_element_name, an_element_value: STRING): BOOLEAN is -- Is given element's value equal with `an_element_value'? do if element_port.is_equal (an_element_name) then Result := does_element_match (port, an_element_value) elseif element_interface_address.is_equal (an_element_name) then Result := does_element_match (interface_address, an_element_value) end end has_port: BOOLEAN is -- Is port set? do Result := port > 0 ensure Result_set: Result = (port > 0) end has_interface_address: BOOLEAN is -- Is interface address set? do Result := interface_address /= Void ensure Result_set: Result = (interface_address /= Void) end feature -- Element change set_port (a_port: like port) is -- Set new class id require Port_valid: a_port > 0 do port := a_port renew_document ensure Port_set: port = a_port end set_interface_address (an_address: like interface_address) is -- Set new interface address require Address_valid: an_address /= Void do interface_address := an_address renew_document ensure Address_set: interface_address = an_address end set_multicast_enabled (enabled: BOOLEAN) is -- Enable/disable multicast do multicast_enabled := enabled renew_document ensure Multicast_set: multicast_enabled = enabled 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 Result.document.root_element.add_unqualified_attribute ("type", "jxta:" + root_element_name) if not multicast_enabled then -- element MulticastOff Result.create_root_child_element (element_multicast_enabled, Result.namespace_empty) end if has_port then -- element Port Result.create_root_child_element (element_port, Result.namespace_empty) Result.create_content (Result.last_element, port.out) end if interface_address /= Void then -- element InterfaceAddress Result.create_root_child_element (element_interface_address, Result.namespace_empty) Result.create_content (Result.last_element, interface_address) end end end feature {NONE} -- Implementation Element_port: STRING is "Port" Element_interface_address: STRING is "InterfaceAddress" Element_multicast_enabled: STRING is "MulticastOff" Type_port: STRING is "xs:integer" Type_interface_address: STRING is "xs:string" root_element_name: STRING is "TCPTransportConfiguration" attribute_handler (root_attribute: XM_ATTRIBUTE) -- Handle a root element attribute of a parsed document do end element_handler (element: XM_ELEMENT) is -- Handle root child element of parsed advertisement local port_raw: STRING do if element_port.is_equal (element.name) then port_raw := element_text (element) if port_raw.is_integer then port := port_raw.to_integer end elseif element_interface_address.is_equal (element.name) then interface_address := trimmed (element.text) elseif element_multicast_enabled.is_equal (element.name) then multicast_enabled := False end end initialize is -- Initialize data structure do Precursor port := 0 interface_address := Void multicast_enabled := True end end