/src/lib/storage/repository/xml_file_repository.e
Specman e | 108 lines | 70 code | 11 blank | 27 comment | 5 complexity | 9c0bce713e0fc31bb3eabf285c22e3be MD5 | raw file
1-- This file is part of a Liberty Eiffel library. 2-- See the full copyright at the end. 3-- 4class XML_FILE_REPOSITORY [O_ -> STORABLE] 5 -- 6 -- To be used with a file that contains the repository (and only that) 7 -- 8inherit 9 XML_REPOSITORY_IMPL[O_] 10 11create {ANY} 12 connect_to 13 14feature {ANY} -- Updating and committing 15 commit 16 do 17 commit_stream.connect_to(filename) 18 write_to_stream(out_stream) 19 commit_stream.disconnect 20 end 21 22 is_commitable: BOOLEAN 23 do 24 Result := commit_stream /= Void and then is_connected 25 end 26 27 update 28 do 29 update_stream.connect_to(filename) 30 read_from_stream(update_stream) 31 update_stream.disconnect 32 end 33 34 is_updateable: BOOLEAN 35 do 36 Result := update_stream /= Void and then is_connected 37 end 38 39 is_connected: BOOLEAN 40 do 41 Result := filename /= Void 42 end 43 44feature {ANY} -- Creation 45 connect_to (a_filename: like filename) 46 -- Connect to a repository with streams as physical store. 47 local 48 ft: FILE_TOOLS 49 do 50 make 51 if ft.file_exists(a_filename) then 52 filename := a_filename 53 if ft.is_readable(a_filename) then 54 create update_stream.make 55 update 56 end 57 commitable_tester.connect_for_appending_to(a_filename) 58 if commitable_tester.is_connected then 59 create commit_stream.make 60 commitable_tester.disconnect 61 end 62 else 63 commitable_tester.connect_to(a_filename) 64 if commitable_tester.is_connected then 65 filename := a_filename 66 create commit_stream.make 67 commitable_tester.disconnect 68 create update_stream.make 69 end 70 end 71 72 if commit_stream /= Void then 73 create out_stream.make(commit_stream, version) 74 end 75 end 76 77feature {} 78 filename: STRING 79 update_stream: TEXT_FILE_READ 80 commit_stream: TEXT_FILE_WRITE 81 out_stream: XML_REPOSITORY_OUTPUT 82 83 commitable_tester: TEXT_FILE_WRITE 84 once 85 create Result.make 86 end 87 88end -- class XML_FILE_REPOSITORY 89-- 90-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file. 91-- 92-- Permission is hereby granted, free of charge, to any person obtaining a copy 93-- of this software and associated documentation files (the "Software"), to deal 94-- in the Software without restriction, including without limitation the rights 95-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 96-- copies of the Software, and to permit persons to whom the Software is 97-- furnished to do so, subject to the following conditions: 98-- 99-- The above copyright notice and this permission notice shall be included in 100-- all copies or substantial portions of the Software. 101-- 102-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 103-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 104-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 105-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 106-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 107-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 108-- THE SOFTWARE.