/*
* Store.java
* The package functions contains the different class executing the different functions of the FlightSystem Reservation.
*/
package reservation.system.functions;
import java.io.*;
/**
* 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}.
* @author Texier Mathieu and Frederic Bidon
*/public class Store extends Functions {
/**Name of the file where we want to save the data.*/
/**
* Verify invariants :
* <PRE>
* - Argument not null
* - The number of argument equals 1
* - File's name doesn't exist
* - The file can be created
* </PRE>
* @throws Exception if the file exists or cannot be created.
*/
CheckFlightListNotEmpty ();
ArgumentIsValid (arg, 1, 1);
if (!datafile.exists ()) {
if (!datafile.createNewFile ())
throw new Exception ("Cannot create the file: " + datafile.
getPath ());
} else
throw new Exception ("file " + datafile.
getPath () + " already exist");
this.datafile = datafile;
}
/**
* Display the usage for the command <CODE>reload</code>.
* @return the usage.
*/
static public String usage
() {
String usage
= " Usage command Store: store <fileName>\n\r";
usage += " - The <fileName> is the path to the file to be store \n\r";
usage +=" The file extention is .out .\n";
return usage;
}
/**
* Store in a file the data contained in the database.
* @throws Exception if the file is not saved.
* @return a confimation's message if the data are stored.
*/
fout.writeObject (fs);
return "Flight stored";
}
}