public class Sysproperties {
public final static String PROPERTY_NAME = "C:/dokumente und einstellungen/All Users/Desptop/Exporter/config.properties";
//Statisches Object speichert eine Instanz der eigenen Klasse
static Object instance;
// Properties Object
static Properties properties;
final String config;
/**
* Instanziiert ein Properties-Objekt und stößt den Ladevorgang an.
* @param config Dateiname der Konfigurationsdatei
*/
public Sysproperties(String config){
properties = new Properties();
this.config = config;
//Properties Datei laden
loadProps();
}
/**
* Gibt GENAU eine Instanz dieser Klasse zurück.
* Sysproperties ist so ein Singleton.
*
* @return Instanz der Klasse
*/
public static Sysproperties getInstance(String config) {
if (instance == null) {
instance = new Sysproperties(config);
}
return (Sysproperties) instance;
}
/**
* Hier werden alle Einstellungen aus der Konfigurationsdatei
* in das Properties-Objekt geladen.
*/
@SuppressWarnings("unused")
private boolean loadProperties() {
boolean data = false;
try {
properties.load(new FileInputStream(config));
data = true;
} catch (final FileNotFoundException e) {
System.out.println("Config File konnte nicht gefunden weren oder existiert nicht.");
data = false;
e.printStackTrace();
} catch (final IOException e) {
System.out.println("Es ist ein Fehler beim Lesen der Config Datei aufgetreten.");
data = false;
e.printStackTrace();
}
return data;
}// end of load Properties
private boolean loadProps() {
boolean data = false;
try
{
properties.load(getClass().getClassLoader().getResourceAsStream("config.properties"));
data = true;
}
catch (IOException e)
{
//logger.error("Cannot locate axis.properties file", e);
data = false;
}
return data;
}// end of load Properties
/**
* Gibt einen bestimmten Konfigurationsparameter zurück.
* @param aPropertyName Name des Parameters
* @return Wert des Parameters
*/
public String getPropertyValue(String aPropertyName)
{
return properties.getProperty(aPropertyName);
}
public void setPropertyValue(String value, String aPropertyName){
properties.setProperty(aPropertyName,value );
try {
properties.store(new FileOutputStream("config.properties"), null);
} catch (IOException e) {
System.out.println("Konnte den Wert in der config.properties nicht ändern!");
}
}
}// end of class