Skip to content
ConfigurationdataBindingDemo.java 4.67 KiB
Newer Older
xtof's avatar
xtof committed
/**
xtof's avatar
xtof committed
 *
xtof's avatar
xtof committed
 * <b>Description : used for demonstration to the config package.
 * 	see main to understand how to used the AbstactDataBinding. </b>
xtof's avatar
xtof committed
 * <br>
xtof's avatar
xtof committed
 * <p>Projet : JOSAST <BR>
 * <br>
xtof's avatar
xtof committed
 * <b>JOSAST</b> : Java Open Source Amateur Satellite  Toolbox
xtof's avatar
xtof committed
 * <br>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.
 * <b>JOSAST</b> project is managed by AVMDTI (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
 * <br> This software is an open source software. Please read the <b><i>JOSAST licence</b></i><BR>(<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
 * <p>for more information contact <a href="mailto:josast@avmdti.org">josast@avmdti.org</a></p>
 * @author  <a href="mailto:mercier.josast@avmdti.org">mercier</a>
 * @version 1.0
 * <p><b><i> Source Update </b></i></p>
xtof's avatar
xtof committed
 * <br> Version : date 		: name 		: comments
xtof's avatar
xtof committed
 * <br> V1      : 3 mars 2004	: C. Mercier 	: create file
 * <p>
 */
package org.josast.config.databinding;

import java.io.File;
import java.util.Vector;

/**
xtof's avatar
xtof committed
 *
 * <b>Description : </b>
 * <p>Projet : JOSAST <br>
 *
xtof's avatar
xtof committed
 * <br>
xtof's avatar
xtof committed
 * <b>JOSAST</b> : Java Open Source Amateur Satellite  Toolbox
xtof's avatar
xtof committed
 * <br>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.
 * <b>JOSAST</b> project is managed by AVMDTI (<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
 * <br> This software is an open source software. Please read the <b><i>JOSAST licence</b></i><BR>(<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
 * <p>for more information contact <a href="mailto:josast@avmdti.org">josast@avmdti.org</a></p>
 * @author  <a href="mailto:mercier.josast@avmdti.org">mercier</a>
 * @version 1.0
 * <p><b><i> Source Update </b></i></p>
xtof's avatar
xtof committed
 * <br> Version : date 		: name 		: comments
xtof's avatar
xtof committed
 * <br> V1      : 3 mars 2004	: C. Mercier 	: create file
 * <br> V2 		: 01 mai 2019   :	C. Mercier 	: Change log system
 * <p>

 */

public class ConfigurationdataBindingDemo extends AbstractDataBinding {

	private static final long serialVersionUID = -9045143058463814039L;
	private double version = 1.0;
	private String name = null;
	private Vector<String> V = new Vector<String>();
	private String directory = new String("C:\\temp");
xtof's avatar
xtof committed

	private ConfigurationdataBindingDemo() {
xtof's avatar
xtof committed
	}
xtof's avatar
xtof committed

xtof's avatar
xtof committed
/**
xtof's avatar
xtof committed
 * This method return an instance of the class.
xtof's avatar
xtof committed
 * 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.
 */
xtof's avatar
xtof committed
public static ConfigurationdataBindingDemo getInstance() {
xtof's avatar
xtof committed
		// create a default object
		ConfigurationdataBindingDemo t = new ConfigurationdataBindingDemo();
		// test if the file exist
		// TODO : A REVOIR
		File f = new File(t.getDirectory());
xtof's avatar
xtof committed

		if (!f.exists()) {
xtof's avatar
xtof committed
			f.mkdir();
		}
		t.setFolder(t.getDirectory());
xtof's avatar
xtof committed
		if (t.isExist()) {
xtof's avatar
xtof committed
				// load the object
				 t = (ConfigurationdataBindingDemo) t.load();
			}
xtof's avatar
xtof committed
		// return the object
xtof's avatar
xtof committed
		return t;
		}
xtof's avatar
xtof committed

	/**
xtof's avatar
xtof committed
	 * display Vector data and also name of the class and version. <br>
	 * @see java.lang.Object#toString()
	 */
xtof's avatar
xtof committed
	public String toString() {
		return this.V.toString() + name + version;
xtof's avatar
xtof committed
	}

	/**
	 * @return field name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * @return field vector
	 */
	public Vector<String> getV() {
		return V;
	}

	/**
	 * @return field version
	 */
	public double getVersion() {
		return version;
	}

	/**
	 * set field name.
xtof's avatar
xtof committed
	 * @param string
xtof's avatar
xtof committed
	 */
xtof's avatar
xtof committed
	public void setName(final String string) {
xtof's avatar
xtof committed
		name = string;
	}

	/**
	 * set a vector
xtof's avatar
xtof committed
	 *
xtof's avatar
xtof committed
	 * @param vector
	 */
xtof's avatar
xtof committed
	public void setV(final Vector<String> vector) {
xtof's avatar
xtof committed
		V = vector;
	}

	/**
	 * set version.
xtof's avatar
xtof committed
	 *
xtof's avatar
xtof committed
	 * @param d
	 */
xtof's avatar
xtof committed
	public void setVersion(final double d) {
xtof's avatar
xtof committed
		version = d;
	}


xtof's avatar
xtof committed

	public void setDirectory(final String directory) {
xtof's avatar
xtof committed
		this.directory = directory;
	}


	public String getDirectory() {
		return directory;
	}
xtof's avatar
xtof committed

xtof's avatar
xtof committed
	/**
	 * D�monstration :
	 * 	- cr�ation d'un objet
	 * 	- modification des param�tres de l'objet
	 *  - sauvegarde
	 *  - lecture
xtof's avatar
xtof committed
	 * @param messages non utilis�
xtof's avatar
xtof committed
	 */
xtof's avatar
xtof committed
	public static void main(String[] arg) {
xtof's avatar
xtof committed
			Vector<String> v = new Vector<String>();
			v.add("�lement 1");
			v.add("�l�ment 2");
			v.add("�l�ment 3");
			ConfigurationdataBindingDemo t = getInstance();
xtof's avatar
xtof committed
			System.out.println("First Load" + t);
xtof's avatar
xtof committed
			t.setName("d�monstration du fichier");
			t.setVersion(1.3);
			t.setV(v);
xtof's avatar
xtof committed
			System.out.println("avant sauvegarde" + t);
xtof's avatar
xtof committed
			t.save();
xtof's avatar
xtof committed
			t = new ConfigurationdataBindingDemo();
			System.out.println("a la cr�ation"  + t);
			t = (ConfigurationdataBindingDemo) t.load();
			System.out.println("apr�s sauvegarde" + t);