/src/lib/storage/repository/xml_repository.e

http://github.com/tybor/Liberty · Specman e · 131 lines · 84 code · 17 blank · 30 comment · 2 complexity · 8bbf313097d9e7433960020024544472 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_REPOSITORY[O_ -> STORABLE]
  5. obsolete
  6. "Use either XML_STREAM_REPOSITORY or XML_FILE_REPOSITORY (may 2006)"
  7. inherit
  8. XML_REPOSITORY_IMPL[O_]
  9. creation {ANY}
  10. connect_to, from_file, make
  11. feature {ANY} -- Updating and committing
  12. commit_to_file (path: STRING) is
  13. -- Overwrite or create `path' with the contents of `Current'.
  14. obsolete
  15. "Use XML_FILE_REPOSITORY.connect_to and the standard commit"
  16. do
  17. tfw.connect_to(path)
  18. write_to_stream(tfw)
  19. tfw.disconnect
  20. end
  21. update_from_file (path: STRING) is
  22. -- Get all objects from the file designed by `path'. Previous objects are not discarded except if new
  23. -- objects use the same key.
  24. obsolete
  25. "Use XML_FILE_REPOSITORY.connect_to and the standard update"
  26. do
  27. tfr.connect_to(path)
  28. if tfr.is_connected then
  29. update_from_stream(tfr)
  30. tfr.disconnect
  31. end
  32. end
  33. read_from_file (path: STRING) is
  34. -- Get all objects from the file designed by `path'. Previous objects are discarded first.
  35. obsolete
  36. "Use XML_FILE_REPOSITORY.connect_to and the standard update"
  37. do
  38. tfr.connect_to(path)
  39. read_from_stream(tfr)
  40. tfr.disconnect
  41. end
  42. commit is
  43. do
  44. write_to_stream(commit_stream)
  45. end
  46. is_commitable: BOOLEAN is
  47. do
  48. Result := commit_stream /= Void and then commit_stream.is_connected
  49. end
  50. update is
  51. do
  52. read_from_stream(update_stream)
  53. end
  54. is_updateable: BOOLEAN is
  55. do
  56. Result := update_stream /= Void and then update_stream.is_connected
  57. end
  58. is_connected: BOOLEAN is
  59. do
  60. Result := commit_stream /= Void and then commit_stream.is_connected
  61. end
  62. feature {} -- Creation
  63. from_file (path: STRING) is
  64. -- Create a not-connected repository with initial data from the given path. One must use
  65. -- `update_from_file' and `commit_to_file'.
  66. obsolete
  67. "Use XML_FILE_REPOSITORY.connect_to"
  68. do
  69. make
  70. tfr.connect_to(path)
  71. if tfr.is_connected then
  72. update_from_stream(tfr)
  73. tfr.disconnect
  74. end
  75. end
  76. connect_to (in_stream: like update_stream; out_stream: like commit_stream) is
  77. -- Connect to a repository with streams as physical store.
  78. do
  79. make
  80. update_stream := in_stream
  81. commit_stream := out_stream
  82. end
  83. feature {} -- Internals
  84. tfr: TEXT_FILE_READ is
  85. once
  86. create Result.make
  87. end
  88. tfw: TEXT_FILE_WRITE is
  89. once
  90. create Result.make
  91. end
  92. update_stream: INPUT_STREAM
  93. commit_stream: OUTPUT_STREAM
  94. end -- class XML_REPOSITORY
  95. --
  96. -- Copyright (c) 2009 by all the people cited in the AUTHORS file.
  97. --
  98. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  99. -- of this software and associated documentation files (the "Software"), to deal
  100. -- in the Software without restriction, including without limitation the rights
  101. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  102. -- copies of the Software, and to permit persons to whom the Software is
  103. -- furnished to do so, subject to the following conditions:
  104. --
  105. -- The above copyright notice and this permission notice shall be included in
  106. -- all copies or substantial portions of the Software.
  107. --
  108. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  109. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  110. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  111. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  112. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  113. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  114. -- THE SOFTWARE.