booking system

  1. /*
  2.  * Store.java
  3.  * The package functions contains the different class executing the different functions of the FlightSystem Reservation.
  4.  */
  5. package reservation.system.functions;
  6.  
  7. import java.io.*;
  8.  
  9. /**
  10.  * This class hold Create structure. This object allows to create a new flight in the data base by calling the method <CODE>create</CODE> in {@link reservation.system.FlightSystem}.
  11.  * @author Texier Mathieu and Frederic Bidon
  12.  */public class Store extends Functions {
  13.    
  14.     /**Name of the file where we want to save the data.*/
  15.     private File datafile;
  16.    
  17.     /**
  18.      * Verify invariants :
  19.      * <PRE>
  20.      * - Argument not null
  21.      * - The number of argument equals 1
  22.      * - File's name doesn't exist
  23.      * - The file can be created
  24.      * </PRE>
  25.      * @throws Exception if the file exists or cannot be created.
  26.      */
  27.     void _check (String[] arg) throws Exception {
  28.         CheckFlightListNotEmpty ();
  29.         ArgumentIsValid (arg, 1, 1);
  30.         File datafile = new File (arg[0]);
  31.         if (!datafile.exists ()) {
  32.             if (!datafile.createNewFile ())
  33.                 throw new Exception ("Cannot create the file: " + datafile.getPath ());
  34.         } else
  35.             throw new Exception ("file " + datafile.getPath () + " already exist");
  36.        
  37.         this.datafile = datafile;
  38.     }
  39.    
  40.     /**
  41.      * Display the usage for the command <CODE>reload</code>.
  42.      * @return the usage.
  43.      */
  44.     static public String usage() {
  45.         String usage = " Usage command Store: store <fileName>\n\r";
  46.         usage += " - The <fileName> is the path to the file to be store \n\r";
  47.         usage +=" The file extention is .out .\n";
  48.         return usage;
  49.     }
  50.    
  51.     /**
  52.      * Store in a file the data contained in the database.
  53.      * @throws Exception if the file is not saved.
  54.      * @return a confimation's message if the data are stored.
  55.      */
  56.     public String execute () throws Exception {
  57.         ObjectOutputStream fout = new ObjectOutputStream (new FileOutputStream (datafile));
  58.         fout.writeObject (fs);
  59.         return "Flight stored";
  60.     }
  61. }
  62.  

contact - link to this site