/**
*
* Description : used for demonstration to the config package.
* see main to understand how to used the AbstactDataBinding.
*
*
Projet : JOSAST
*
* JOSAST : Java Open Source Amateur Satellite Toolbox
*
The aim of the project is to create a set of tools for amateur satellite purpose. All this tools could be used together to create specific software.
* JOSAST project is managed by AVMDTI (http://www.avmdti.org )
*
This software is an open source software. Please read the JOSAST licence
(http://www.avmdti.org )
*
for more information contact josast@avmdti.org
* @author mercier
* @version 1.0
* Source Update
*
Version : date : name : comments
*
V1 : 3 mars 2004 : C. Mercier : create file
*
*/
package org.josast.config.databinding;
import java.io.File;
import java.util.Vector;
/**
*
* Description :
*
Projet : JOSAST
*
*
* JOSAST : Java Open Source Amateur Satellite Toolbox
*
The aim of the project is to create a set of tools for amateur satellite purpose. All this tools could be used together to create specific software.
* JOSAST project is managed by AVMDTI (http://www.avmdti.org )
*
This software is an open source software. Please read the JOSAST licence
(http://www.avmdti.org )
*
for more information contact josast@avmdti.org
* @author mercier
* @version 1.0
* Source Update
*
Version : date : name : comments
*
V1 : 3 mars 2004 : C. Mercier : create file
*
V2 : 01 mai 2019 : C. Mercier : Change log system
*
*/
public class ConfigurationdataBindingDemo extends AbstractDataBinding {
private static final long serialVersionUID = -9045143058463814039L;
private double version = 1.0;
private String name = null;
private Vector V = new Vector();
private String directory = new String("C:\\temp");
private ConfigurationdataBindingDemo() {
}
/**
* This method return an instance of the class.
* If the configuration file exist, the function return an object from the configuration file
* else the function return a default object.
* @return an instance of the class.
*/
public static ConfigurationdataBindingDemo getInstance() {
// create a default object
ConfigurationdataBindingDemo t = new ConfigurationdataBindingDemo();
// test if the file exist
// TODO : A REVOIR
File f = new File(t.getDirectory());
if (!f.exists()) {
f.mkdir();
}
t.setFolder(t.getDirectory());
if (t.isExist()) {
// load the object
t = (ConfigurationdataBindingDemo) t.load();
}
// return the object
return t;
}
/**
* display Vector data and also name of the class and version.
* @see java.lang.Object#toString()
*/
public String toString() {
return this.V.toString() + name + version;
}
/**
* @return field name.
*/
public String getName() {
return name;
}
/**
* @return field vector
*/
public Vector getV() {
return V;
}
/**
* @return field version
*/
public double getVersion() {
return version;
}
/**
* set field name.
* @param string
*/
public void setName(final String string) {
name = string;
}
/**
* set a vector
*
* @param vector
*/
public void setV(final Vector vector) {
V = vector;
}
/**
* set version.
*
* @param d
*/
public void setVersion(final double d) {
version = d;
}
public void setDirectory(final String directory) {
this.directory = directory;
}
public String getDirectory() {
return directory;
}
/**
* D�monstration :
* - cr�ation d'un objet
* - modification des param�tres de l'objet
* - sauvegarde
* - lecture
* @param messages non utilis�
*/
public static void main(String[] arg) {
Vector v = new Vector();
v.add("�lement 1");
v.add("�l�ment 2");
v.add("�l�ment 3");
ConfigurationdataBindingDemo t = getInstance();
System.out.println("First Load" + t);
t.setName("d�monstration du fichier");
t.setVersion(1.3);
t.setV(v);
System.out.println("avant sauvegarde" + t);
t.save();
t = new ConfigurationdataBindingDemo();
System.out.println("a la cr�ation" + t);
t = (ConfigurationdataBindingDemo) t.load();
System.out.println("apr�s sauvegarde" + t);
}
}