]> git.mxchange.org Git - addressbook-lib.git/blobdiff - src/org/mxchange/addressbook/application/AddressbookApplication.java
Prepared for upcoming rewrite:
[addressbook-lib.git] / src / org / mxchange / addressbook / application / AddressbookApplication.java
index dca6fe202e2dc7e9892f2a158a474f8ef4e5e7e5..2859e5ca11c5feb02c19190c9f8b5b78c32c4be7 100644 (file)
@@ -22,12 +22,12 @@ import java.text.MessageFormat;
 import org.mxchange.addressbook.client.AddressbookClient;
 import org.mxchange.addressbook.client.console.ConsoleClient;
 import org.mxchange.addressbook.client.gui.SwingClient;
-import org.mxchange.jcore.BaseFrameworkSystem;
 import org.mxchange.jcore.application.Application;
 import org.mxchange.jcore.application.BaseApplication;
 import org.mxchange.jcore.client.Client;
 import org.mxchange.jcore.exceptions.UnhandledUserChoiceException;
 import org.mxchange.jcore.manager.application.ApplicationManager;
+import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
 
 /**
  * Address book application class. Please see ROADMAP.txt for details.
@@ -57,12 +57,15 @@ public class AddressbookApplication extends BaseApplication implements Applicati
         */
        private boolean guiClient = false;
 
+       /**
+        * Logger instance
+        */
+       private LoggerBeanLocal logger;
+
        /**
         * Protected constructor
-        * <p>
-        * @throws java.io.IOException If any IO error occurs
         */
-       protected AddressbookApplication () throws IOException {
+       protected AddressbookApplication () {
                // Init properties file
                this.initProperties();
 
@@ -79,7 +82,7 @@ public class AddressbookApplication extends BaseApplication implements Applicati
         */
        @Override
        public void doBootstrap () {
-               this.getLogger().debug("Initializing application ..."); //NOI18N
+               this.getLogger().logDebug("Initializing application ..."); //NOI18N
 
                // Init client variable
                Client client = null;
@@ -87,19 +90,19 @@ public class AddressbookApplication extends BaseApplication implements Applicati
                // Is console or Swing choosen?
                if (this.isConsole()) {
                        // Debug message
-                       this.getLogger().debug("Initializing console client ..."); //NOI18N
+                       this.getLogger().logDebug("Initializing console client ..."); //NOI18N
 
                        // Init console client instance
                        client = new ConsoleClient(this);
                } else if (this.isGui()) {
                        // Debug message
-                       this.getLogger().debug("Initializing GUI (Swing) client ..."); //NOI18N
+                       this.getLogger().logDebug("Initializing GUI (Swing) client ..."); //NOI18N
 
                        // Init console instance
                        client = new SwingClient(this);
                } else {
                        // Not client choosen
-                       this.getLogger().error("No client choosen. Cannot launch."); //NOI18N
+                       this.getLogger().logError("No client choosen. Cannot launch."); //NOI18N
 
                        try {
                                this.doShutdown();
@@ -122,7 +125,7 @@ public class AddressbookApplication extends BaseApplication implements Applicati
                this.getClient().enableIsRunning();
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
        /**
@@ -134,7 +137,7 @@ public class AddressbookApplication extends BaseApplication implements Applicati
                AddressbookClient client = (AddressbookClient) this.getClient();
 
                // Debug message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // TODO The application should be running now
                // Output introduction
@@ -152,7 +155,7 @@ public class AddressbookApplication extends BaseApplication implements Applicati
                                // Ask for user input and run proper method
                                client.doUserMenuChoice();
                        } catch (final UnhandledUserChoiceException ex) {
-                               this.getLogger().catching(ex);
+                               this.getLogger().logException(ex);
                        }
 
                        try {
@@ -165,7 +168,7 @@ public class AddressbookApplication extends BaseApplication implements Applicati
                // --- Main loop ends here ---
 
                // Debug message
-               this.getLogger().debug("Main loop exit - shutting down ..."); //NOI18N
+               this.getLogger().logDebug("Main loop exit - shutting down ..."); //NOI18N
        }
 
        /**
@@ -174,20 +177,49 @@ public class AddressbookApplication extends BaseApplication implements Applicati
        @Override
        public void doShutdown () throws SQLException, IOException {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Shutdown client
                this.getClient().doShutdown();
 
-               this.getLogger().info("End of program (last line)"); //NOI18N
+               this.getLogger().logInfo("End of program (last line)"); //NOI18N
                System.exit(0);
        }
 
+       /**
+        * Logs given exception
+        *
+        * @param exception Throwable
+        */
+       protected void logException (final Throwable exception) {
+               this.getLogger().logException(exception);
+       }
+
+       /**
+        * Initializes properties
+        */
+       private void initProperties () throws IOException {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       /**
+        * Log exception and abort program.
+        *
+        * @param throwable Throwable
+        */
+       protected void abortProgramWithException (final Throwable throwable) {
+               // Log exception
+               this.logException(throwable);
+
+               // Abort here
+               System.exit(1);
+       }
+
        /**
         * Enables console client by setting propper flag
         */
        private void enableConsoleClient () {
-               this.getLogger().debug("Enabling console client (may become optional client) ..."); //NOI18N
+               this.getLogger().logDebug("Enabling console client (may become optional client) ..."); //NOI18N
                this.consoleClient = true;
                this.guiClient = false;
        }
@@ -196,7 +228,7 @@ public class AddressbookApplication extends BaseApplication implements Applicati
         * Enables GUI client by setting propper flag
         */
        private void enableGuiClient () {
-               this.getLogger().debug("Enabling GUI client (may become new default client) ..."); //NOI18N
+               this.getLogger().logDebug("Enabling GUI client (may become new default client) ..."); //NOI18N
                this.consoleClient = false;
                this.guiClient = true;
        }
@@ -228,10 +260,10 @@ public class AddressbookApplication extends BaseApplication implements Applicati
         */
        private void parseArguments (final String[] args) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("args()={0} - CALLED!", args.length)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("args()={0} - CALLED!", args.length)); //NOI18N
 
                // Debug message
-               this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length)); //NOI18N
+               this.getLogger().logDebug(MessageFormat.format("Parsing {0} arguments ...", args.length)); //NOI18N
 
                for (final String arg : args) {
                        // Switch on it
@@ -252,13 +284,13 @@ public class AddressbookApplication extends BaseApplication implements Applicati
         */
        private void showIntro () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Let the client show it
                this.getClient().showWelcome();
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
        /**
@@ -267,7 +299,8 @@ public class AddressbookApplication extends BaseApplication implements Applicati
         * @param args Arguments handled to program
         */
        private void start (final String args[]) {
-               this.getLogger().info("Program is started."); //NOI18N
+               this.getLogger().logInfo("Program is started."); //NOI18N
+
                try {
                        // Init properties file
                        this.initProperties();
@@ -283,10 +316,12 @@ public class AddressbookApplication extends BaseApplication implements Applicati
                ApplicationManager.getSingeltonManager(this).start();
 
                // Good bye, but this should not be reached ...
-               this.getLogger().warn("Unusual exit reached."); //NOI18N
+               this.getLogger().logWarning("Unusual exit reached."); //NOI18N
+
                try {
                        this.doShutdown();
                } catch (final SQLException | IOException ex) {
+                       // Something bad happened
                        this.abortProgramWithException(ex);
                }
        }
@@ -297,14 +332,8 @@ public class AddressbookApplication extends BaseApplication implements Applicati
         * @param args the command line arguments
         */
        public static void main (String[] args) {
-               try {
-                       // Start application
-                       new AddressbookApplication().start(args);
-               } catch (final IOException ex) {
-                       // Get instance
-                       BaseFrameworkSystem.getInstance().getLogger().catching(ex);
-                       System.exit(1);
-               }
+               // Start application
+               new AddressbookApplication().start(args);
        }
 
        /**
@@ -315,4 +344,13 @@ public class AddressbookApplication extends BaseApplication implements Applicati
        public static String printableTitle () {
                return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION); //NOI18N
        }
+
+       /**
+        * Getter for logger instance
+        *
+        * @return Logger instance
+        */
+       protected LoggerBeanLocal getLogger () {
+               return this.logger;
+       }
 }