1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
import java.io.*;
import java.util.ArrayList;
import java.util.Vector;
public class configuration implements Serializable
{
Vector nom;
Vector regle;
Vector exeption;
public configuration()
{
nom = new Vector();
regle = new Vector();
exeption = new Vector();
nom.add("1");
regle.add("1");
exeption.add("1");
nom.add("2");
regle.add("2");
exeption.add("2");
nom.add("3");
regle.add("3");
exeption.add("3");
nom.add("4");
regle.add("4");
exeption.add("4");
nom.add("5");
regle.add("5");
exeption.add("5");
nom.add("6");
regle.add("6");
exeption.add("6");
}
public void ADD(String name,exeption exep,regle rg)
{
nom.addElement(name);
exeption.addElement(exep);
regle.addElement(rg);
}
public void SET(int index,String name,exeption exep,regle rg)
{
nom.set(index , name );
exeption.set(index,exep);
regle.set(index, rg);
}
public void DEL(int index)
{
nom.remove(index);
exeption.remove(index);
regle.remove(index);
}
public void SAVE()
{
try
{
// ouverture d'un flux de sortie vers le fichier "personne.serial"
FileOutputStream fos = new FileOutputStream("configuration.dat");
// création d'un "flux objet" avec le flux fichier
ObjectOutputStream oos= new ObjectOutputStream(fos);
try {
// sérialisation : écriture de l'objet dans le flux de sortie
oos.writeObject(this);
// on vide le tampon
oos.flush();
} finally
{
//fermeture des flux
try
{
oos.close();
} finally
{
fos.close();
}
}
} catch(IOException ioe)
{
ioe.printStackTrace();
}
}
public configuration LOAD ()
{
configuration config=null;
try {
// ouverture d'un flux d'entrée depuis le fichier "personne.serial"
FileInputStream fis = new FileInputStream("configuration.dat");
// création d'un "flux objet" avec le flux fichier
ObjectInputStream ois= new ObjectInputStream(fis);
try {
// désérialisation : lecture de l'objet depuis le flux d'entrée
config = (configuration) ois.readObject();
} finally {
// on ferme les flux
try {
ois.close();
} finally {
fis.close();
}
}
} catch(IOException ioe) {
ioe.printStackTrace();
} catch(ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
if(config != null) {
System.out.println(config + " a ete deserialise");
}
return config;
}
} |