PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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