]> git.mxchange.org Git - jfinancials-swing.git/commitdiff
Added method logException() + properties instance should be static as only one instan...
authorRoland Haeder <roland@mxchange.org>
Thu, 30 Jul 2015 08:01:56 +0000 (10:01 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 30 Jul 2015 08:01:56 +0000 (10:01 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java
Addressbook/src/org/mxchange/addressbook/FrameworkInterface.java

index 87f2b6197db3ff29c8b89aaf22dd30caf2267c71..333f68bf638ffa789a556a63e33137462f5a4ae8 100644 (file)
@@ -37,6 +37,10 @@ import org.mxchange.addressbook.manager.contact.ManageableContact;
  * @author Roland Haeder
  */
 public class BaseFrameworkSystem implements FrameworkInterface {
+       /**
+        * Instance for own properties
+        */
+       private static final Properties properties = new Properties(System.getProperties());
 
        /**
         * Class' logger
@@ -63,10 +67,6 @@ public class BaseFrameworkSystem implements FrameworkInterface {
         */
        private ManageableContact contactManager;
 
-       /**
-        * Instance for own properties
-        */
-       private final Properties properties;
 
        /**
         * Name of used database table, handled over to backend
@@ -85,9 +85,6 @@ public class BaseFrameworkSystem implements FrameworkInterface {
         * 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();
        }
@@ -102,6 +99,41 @@ public class BaseFrameworkSystem implements FrameworkInterface {
                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
         *
@@ -112,6 +144,24 @@ public class BaseFrameworkSystem implements FrameworkInterface {
                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
         *
@@ -122,6 +172,26 @@ public class BaseFrameworkSystem implements FrameworkInterface {
                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
         */
@@ -129,12 +199,21 @@ public class BaseFrameworkSystem implements FrameworkInterface {
                // 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
@@ -165,13 +244,13 @@ public class BaseFrameworkSystem implements FrameworkInterface {
 
                // 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
@@ -186,7 +265,7 @@ public class BaseFrameworkSystem implements FrameworkInterface {
 
                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);
                }
@@ -195,68 +274,6 @@ public class BaseFrameworkSystem implements FrameworkInterface {
                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
         *
@@ -273,7 +290,7 @@ public class BaseFrameworkSystem implements FrameworkInterface {
         * @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
        }
 
        /**
index 02144db0366c4722625e31bc72adbb1baf1d166f..0ef8206a49c9d12e311be5ec0dab191e76066662 100644 (file)
@@ -59,4 +59,11 @@ public interface FrameworkInterface {
         * @return Human-readable message
         */
        public String getMessageStringFromKey (final String key);
+
+       /**
+        * Logs given exception
+        *
+        * @param exception Exception to log
+        */
+       public void logException (final Throwable exception);
 }