/src/lib/storage/repository/xml_file_repository.e

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