booking system

  1. /*
  2.  * Reload.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 reservation.system.FlightSystem;
  8. import reservation.system.Flight;
  9. import reservation.system.Pos;
  10. import reservation.system.Person;
  11.  
  12. import java.io.*;
  13. import java.util.Vector;
  14.  
  15. /**
  16.  * This class hold Reload structure. This object allows to load the data previous saved in a file.
  17.  * @author Texier Mathieu and Frederic Bidon
  18.  */
  19.  public class Reload extends Functions {
  20.    
  21.     /**Name of the file to reload*/
  22.     private File datafile;
  23.    
  24.     /**
  25.      * Verify invariants :
  26.      * <PRE>
  27.      * - Argument not null
  28.      * - The number of argument equals 1
  29.      * - File's name exists
  30.      * - The file can be read
  31.      * </PRE>
  32.      * @throws Exception if the file doesn't exist or cannot read.
  33.      */
  34.     void _check (String[] arg) throws Exception {
  35.         ArgumentIsValid (arg, 1, 1);
  36.         File datafile = new File (arg[0]);
  37.         if (!datafile.exists () || !datafile.canRead () ) {
  38.             throw new Exception ("file " + datafile.getPath () + " does not exist or can not be read");
  39.         } else this.datafile = datafile;
  40.     }
  41.    
  42.     /**
  43.      * Display the usage for the command <CODE>reload</code>.
  44.      * @return the usage.
  45.      */
  46.     static public String usage() {
  47.         String usage = " Usage command Reload: reload <fileName>\n\r";
  48.         usage += " - The <fileName> is the path to the file to be reloaded \n\r";
  49.         usage +=" The file extention is .out .\n";
  50.         return usage;
  51.     }
  52.    
  53.     /**
  54.      * Reload the data previous stored in a file.
  55.      * @throws Exception if the file is not reloaded.
  56.      * @return a confimation's message if the data are reloaded.
  57.      */
  58.     public String execute () throws Exception {
  59.         String reString = "FlightSystem reloaded";
  60.         ObjectInputStream fin = new ObjectInputStream (new FileInputStream (arg[0]));
  61.         Object obj = fin.readObject ();
  62.         if (obj instanceof FlightSystem) {
  63.             FlightSystem fsExtracted = (FlightSystem) obj;
  64.            
  65.             String[] listFlight = fsExtracted.getFlightList ();
  66.             int decount = listFlight.length;
  67.             for(int i = 0; i < listFlight.length; i++) {
  68.                 Flight flight = fsExtracted.selectFlight (listFlight[i]);
  69.                 decount -= fs.create (flight)? 1 : 0;
  70.             }
  71.            
  72.             if (decount != 0)
  73.                 throw new Exception ("Flight list partialy reloaded: " + decount + "flight skiped");
  74.            
  75.             Integer[] listBooking = fsExtracted.getBookingList ();
  76.             for (int j = 0; j < fsExtracted.getBookingNumberMax (); j++) {
  77.                 Vector listPerson = fsExtracted.identify (listBooking[j].intValue ());
  78.                 decount += listPerson.size();
  79.                 for (int k = 0; k < listPerson.size (); k++) {
  80.                     Person person = (Person) listPerson.get (k);
  81.                     decount -= fs.reserve (person);
  82.                 }
  83.             }
  84.            
  85.             if (decount != 0)
  86.                 throw new Exception ("Person list partialy reloaded: " + decount + "person skiped");
  87.            
  88.             fin.close ();
  89.         }
  90.         return reString;
  91.     }
  92.    
  93. }
  94.  

contact - link to this site