(**** * * Module File defines the objects and operations related to file processing * in the calendar system. * * Based on module in Lecture Notes Week 9 & 10. * *) module File; from Tests import PracticeTest, ProctorTest, TakenTest; from Database import Database; from StudentFunctionality import UserID; export all; object FileSpace is File* description: (* A FileSpace is an abstract model of a file space in the operating environment in which the CalendarTool is run. The FileSpace is simply a collection of zero or more Files, with no other properties modeled here. *); end; object File is components: name:FileName and permissions:FilePermissions and file_type:FileType and size:FileSize and data:FileData; description: (* A File is an abstraction of a file stored in the file space. It has a name, permissions, type, and data. These are the components sufficient to specify the behavior of Calendar Tool file operations. *); end File; object FileName is string description: (* The name of a file. The string representation here is an abstraction of file names used in specific operating environments. Implementations may obey any syntactic or semantic constraints imposed by a particular environment. *); end; object FilePermissions is is_readable:IsReadable and is_writable:IsWritable description: (* FilePermissions indicate whether a file is readable and/or writable. *); end; object IsReadable is boolean description: (* Flag indicating whether a file is readable, which is required to be true by the FileOpen operation. *); end; object IsWritable is boolean description: (* Flag indicating whether a file is writable, which is required to be true by the FileSave operation. *); end; object FileType is test_type:TestType or taken_test_type:TakenTestType or db_type:DatabaseType description: (* The type of file data is either UntakenTestType data (which is the type for tests that haven't been taken yet), TakenTestType (which is the type for tests that have been taken), or DatabaseType (which is the type that the question database is saved as). *); end FileType; object TestType is UntakenTestType or TakenTestType; object UntakenTestType description: (* The UntakenTestType is the type for tests that haven't been taken yet. *); end UntakenTestType; object TakenTestType description: (* The TakenTestType is the type for tests that have been taken. *); end TakenTestType; object DatabaseType description: (* The DatabaseType is the type that the question database is saved as. *); end DatabaseType; object FileSize is integer description: (* The size in megabytes of a file. *); end FileSize; object FileData is Database or PracticeTest or ProctorTest or TakenTest description: (* FileData is the database of questions, or the one of the test types. *); end FileData; object UserWorkSpace is components: UserID and Database and PracticeTest ProctorTest and TakenTest; description: (* The UserWorkSpace contains all the objects that the user is currently working on. This includes the question database and any tests that are currently being created. *); end UserWorkSpace; operation FileNew is inputs: uws:UserWorkSpace; outputs: uws':UserWorkSpace; description: (* Add a new empty test to the workspace and make it current. *); end FileNew; operation FileOpen is inputs: fs:FileSpace, fn:FileName, uws:UserWorkSpace; outputs: uws':UserWorkSpace; description: (* Open an test file of the given name and put the data from that file in the workspace. *); end FileOpen; operation FileSave is inputs: fs:FileSpace, uws:UserWorkSpace; outputs: fs':FileSpace, uws':UserWorkSpace; description: (* If the tests or question database in the given workspace requires saving, save it in the given file space. *); end FileSave; operation FileSaveAs is inputs: fs:FileSpace, fn:FileName, uws:UserWorkSpace; outputs: fs':FileSpace, uws':UserWorkSpace; description: (* If the tests or question database in the given workspace requires saving, save it in the given file space. *); end FileSave; end File;