* @author Roland Haeder
*/
public class BaseFrameworkSystem implements FrameworkInterface {
+ /**
+ * Instance for own properties
+ */
+ private static final Properties properties = new Properties(System.getProperties());
/**
* Class' logger
*/
private ManageableContact contactManager;
- /**
- * Instance for own properties
- */
- private final Properties properties;
/**
* Name of used database table, handled over to backend
* No instances can be created of this class
*/
protected BaseFrameworkSystem () {
- // Init properties instance with from system
- this.properties = new Properties(System.getProperties());
-
// Init properties file
this.initProperties();
}
return this.application;
}
+ /**
+ * Getter for human-readable string from given key
+ *
+ * @param key Key to return
+ * @return Human-readable message
+ */
+ @Override
+ public final String getMessageStringFromKey (final String key) {
+ // Return message
+ return this.getBundle().getString(key);
+ }
+
+ /**
+ * Aborts program with given exception
+ *
+ * @param throwable Any type of Throwable
+ */
+ protected final void abortProgramWithException (final Throwable throwable) {
+ // Log exception ...
+ this.getLogger().catching(throwable);
+
+ // .. and exit
+ System.exit(1);
+
+ }
+
+ /**
+ * Application instance
+ *
+ * @param application the application to set
+ */
+ protected final void setApplication (final Application application) {
+ this.application = application;
+ }
+
/**
* Client instance
*
return this.client;
}
+ /**
+ * Getter for bundle instance
+ *
+ * @return Resource bundle
+ */
+ protected final ResourceBundle getBundle () {
+ return this.bundle;
+ }
+
+ /**
+ * Client instance
+ *
+ * @param client the client to set
+ */
+ protected final void setClient (final Client client) {
+ this.client = client;
+ }
+
/**
* Contact manager instance
*
return this.contactManager;
}
+ /**
+ * Contact manager instance
+ *
+ * @param contactManager the contactManager to set
+ */
+ protected final void setContactManager (final ManageableContact contactManager) {
+ this.contactManager = contactManager;
+ }
+
+ /**
+ * Log exception
+ *
+ * @param exception Exception to log
+ */
+ @Override
+ public void logException (final Throwable exception) {
+ // Log this exception
+ this.getLogger().catching(exception);
+ }
+
/**
* Prepares all properties, the file is written if it is not found
*/
// Trace message
this.getLogger().trace("CALLED!"); //NOI18N
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("{0} properties are loaded already.", BaseFrameworkSystem.properties.size())); //NOI18N
+
+ // Are some properties loaded?
+ if (!BaseFrameworkSystem.properties.isEmpty()) {
+ // Some are already loaded, abort here
+ return;
+ }
+
try {
// Try to read it
- this.properties.load(new BufferedReader(new InputStreamReader(new FileInputStream(FrameworkInterface.PROPERTIES_CONFIG_FILE))));
+ BaseFrameworkSystem.properties.load(new BufferedReader(new InputStreamReader(new FileInputStream(FrameworkInterface.PROPERTIES_CONFIG_FILE))));
// Debug message
- this.getLogger().debug(MessageFormat.format("{0} properties has been loaded.", this.properties.size())); //NOI18N
+ this.getLogger().debug(MessageFormat.format("{0} properties has been loaded.", BaseFrameworkSystem.properties.size())); //NOI18N
} catch (final FileNotFoundException ex) {
// Debug message
this.getLogger().debug(MessageFormat.format("Properties file {0} not found: {1}", FrameworkInterface.PROPERTIES_CONFIG_FILE, ex)); //NOI18N
// Init default values:
// Default database backend
- this.properties.put("database.backendType", "base64csv"); //NOI18N
+ BaseFrameworkSystem.properties.put("org.mxchange.addressbook.database.backendType", "base64csv"); //NOI18N
// For MySQL backend
- this.properties.put("database.mysql.host", "localhost"); //NOI18N
- this.properties.put("database.mysql.dbname", "test"); //NOI18N
- this.properties.put("database.mysql.login", ""); //NOI18N
- this.properties.put("database.mysql.password", ""); //NOI18N
+ BaseFrameworkSystem.properties.put("org.mxchange.addressbook.database.mysql.host", "localhost"); //NOI18N
+ BaseFrameworkSystem.properties.put("org.mxchange.addressbook.database.mysql.dbname", "test"); //NOI18N
+ BaseFrameworkSystem.properties.put("org.mxchange.addressbook.database.mysql.login", ""); //NOI18N
+ BaseFrameworkSystem.properties.put("org.mxchange.addressbook.database.mysql.password", ""); //NOI18N
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
try {
// Write it
- this.properties.store(new PrintWriter(FrameworkInterface.PROPERTIES_CONFIG_FILE), "This file is automatically generated. You may wish to alter it."); //NOI18N
+ BaseFrameworkSystem.properties.store(new PrintWriter(FrameworkInterface.PROPERTIES_CONFIG_FILE), "This file is automatically generated. You may wish to alter it."); //NOI18N
} catch (final IOException ex) {
this.abortProgramWithException(ex);
}
this.getLogger().trace("EXIT!"); //NOI18N
}
- /**
- * Contact manager instance
- *
- * @param contactManager the contactManager to set
- */
- protected final void setContactManager (final ManageableContact contactManager) {
- this.contactManager = contactManager;
- }
-
- /**
- * Client instance
- *
- * @param client the client to set
- */
- protected final void setClient (final Client client) {
- this.client = client;
- }
-
- /**
- * Application instance
- *
- * @param application the application to set
- */
- protected final void setApplication (final Application application) {
- this.application = application;
- }
-
- /**
- * Getter for human-readable string from given key
- *
- * @param key Key to return
- * @return Human-readable message
- */
- @Override
- public final String getMessageStringFromKey (final String key) {
- // Return message
- return this.getBundle().getString(key);
- }
-
- /**
- * Aborts program with given exception
- *
- * @param throwable Any type of Throwable
- */
- protected final void abortProgramWithException (final Throwable throwable) {
- // Log exception ...
- this.getLogger().catching(throwable);
-
- // .. and exit
- System.exit(1);
-
- }
-
- /**
- * Getter for bundle instance
- *
- * @return Resource bundle
- */
- protected final ResourceBundle getBundle () {
- return this.bundle;
- }
-
/**
* Getter for logger
*
* @return Propety value
*/
protected String getProperty (final String key) {
- return this.properties.getProperty(String.format("org.mxchange.addressbook.%s", key)); //NOI18N
+ return BaseFrameworkSystem.properties.getProperty(String.format("org.mxchange.addressbook.%s", key)); //NOI18N
}
/**