[Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/properties Settings.java,NONE,1.1 package
Status: Pre-Alpha
Brought to you by:
henryml
From: Jesper P. <je...@us...> - 2005-08-04 06:06:34
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/properties In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3481 Added Files: Settings.java package.html Log Message: Initial import --- NEW FILE: package.html --- <body> This packages contains classes that are used for the users properties </body> --- NEW FILE: Settings.java --- //--------------------------------------------------------------------------------- // $Id: Settings.java,v 1.1 2005/08/04 06:06:26 jews Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gui.properties; import net.sourceforge.bprocessor.model.db.Database; import net.sourceforge.bprocessor.model.db.DatabaseFactory; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Properties; import org.apache.log4j.Logger; /** * The settings class */ public class Settings extends Properties { /** The logger */ private static Logger log = Logger.getLogger(Settings.class); /** The singleton instance */ private static Settings instance; /** DATABASE_NAME */ public static final String DATABASE_NAME = "database.name"; /** DATABASE_TYPE */ public static final String DATABASE_TYPE = "database.type"; /** CONNECTION_URL */ public static final String CONNECTION_URL = "connection.url"; /** CONNECTION_USER */ public static final String CONNECTION_USER = "connection.user"; /** CONNECTION_PASSWORD */ public static final String CONNECTION_PASSWORD = "connection.password"; /** CONNECTION_AUTODROP */ public static final String CONNECTION_AUTODROP = "connection.autodrop"; /** * Constructor for Settings */ private Settings() { } /** * Get the instance * @return The instance */ public static synchronized Settings getInstance() { if (instance == null) { instance = new Settings(); } return instance; } /** * Load the settings */ public synchronized void load() { try { super.clear(); super.load(new FileInputStream("bprocessor.properties")); apply(); } catch (Exception e) { log.error("The settings could not be loaded: " + e.getMessage()); log.warn("Using default settings"); defaultSettings(); } } /** * Save the settings */ public synchronized void save() { try { super.store(new FileOutputStream("bprocessor.properties"), "BProcessor"); } catch (Exception e) { log.error("The settings could not be saved", e); } } /** * Apply settings */ public synchronized void apply() { int type = Integer.parseInt(getProperty(DATABASE_TYPE)); String url = getProperty(CONNECTION_URL); String user = getProperty(CONNECTION_USER); String password = getProperty(CONNECTION_PASSWORD); boolean autodrop = Boolean.valueOf(getProperty(CONNECTION_AUTODROP)).booleanValue(); DatabaseFactory.getInstance().setDatabase(type, url, user, password, autodrop); } /** * Default settings */ private void defaultSettings() { clear(); Database db = DatabaseFactory.getInstance().getDatabase(); setProperty(DATABASE_NAME, db.getName()); setProperty(DATABASE_TYPE, Integer.toString(db.getType())); setProperty(CONNECTION_URL, db.getUrl()); setProperty(CONNECTION_USER, db.getUser()); setProperty(CONNECTION_PASSWORD, db.getPassword()); setProperty(CONNECTION_AUTODROP, Boolean.toString(db.getAutodrop())); } } |