]> git.mxchange.org Git - jbonuscard-lib.git/blobdiff - Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java
Added and implemented missing methods
[jbonuscard-lib.git] / Addressbook / src / org / mxchange / addressbook / application / AddressbookApplication.java
index 7f55a382725a8c1b0936dc399621f00bccc6ce82..4be3359bdbe5fb7c6a7cbb6d3d62d55fdaed979b 100644 (file)
  */
 package org.mxchange.addressbook.application;
 
+import java.io.IOException;
+import java.sql.SQLException;
 import java.text.MessageFormat;
-import org.mxchange.addressbook.BaseFrameworkSystem;
-import org.mxchange.addressbook.client.Client;
+import org.mxchange.addressbook.BaseAddressbookSystem;
+import org.mxchange.addressbook.client.AddressbookClient;
 import org.mxchange.addressbook.client.console.ConsoleClient;
 import org.mxchange.addressbook.client.gui.SwingClient;
-import org.mxchange.addressbook.exceptions.UnhandledUserChoiceException;
-import org.mxchange.addressbook.manager.application.ApplicationManager;
+import org.mxchange.jcore.BaseFrameworkSystem;
+import org.mxchange.jcore.application.Application;
+import org.mxchange.jcore.client.Client;
+import org.mxchange.jcore.exceptions.UnhandledUserChoiceException;
+import org.mxchange.jcore.manager.application.ApplicationManager;
 
 /**
  * ============================================
@@ -110,27 +115,21 @@ import org.mxchange.addressbook.manager.application.ApplicationManager;
  * 2.2 (social):
  *   + 3 days
  *   + Additional tables: ???
- * 
+*
  * @author Roland Haeder
  * @version 0.0
- * @since 0.0
  */
-public class AddressbookApplication extends BaseFrameworkSystem implements Application {
+public class AddressbookApplication extends BaseAddressbookSystem implements Application {
 
        /**
         * Application title
         */
-       public static final String APP_TITLE = "Adressbuch";
+       public static final String APP_TITLE = "Adressbuch"; //NOI18N
 
        /**
         * Application version
         */
-       public static final String APP_VERSION = "0.0";
-
-       /**
-        * Self instance
-        */
-       private static Application selfInstance;
+       public static final String APP_VERSION = "0.0"; //NOI18N
 
        /**
         * Console client is enabled by default
@@ -144,19 +143,14 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
 
        /**
         * Protected constructor
+        * @throws java.io.IOException If any IO error occurs
         */
-       protected AddressbookApplication () {
-               // Set own instance
-               selfInstance = this;
-       }
+       protected AddressbookApplication () throws IOException {
+               // Init properties file
+               this.initProperties();
 
-       /**
-        * Getter for printable application name
-        *
-        * @return A printable name
-        */
-       public static String printableTitle () {
-               return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION);
+               // Init bundle
+               this.initBundle();
        }
 
        /**
@@ -164,7 +158,7 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
         */
        @Override
        public void doBootstrap () {
-               this.getLogger().debug("Initializing application ...");
+               this.getLogger().debug("Initializing application ..."); //NOI18N
 
                // Init client variable
                Client client = null;
@@ -172,19 +166,19 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
                // Is console or Swing choosen?
                if (this.isConsole()) {
                        // Debug message
-                       this.getLogger().debug("Initializing console client ...");
+                       this.getLogger().debug("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 ...");
+                       this.getLogger().debug("Initializing GUI (Swing) client ..."); //NOI18N
 
                        // Init console instance
                        client = new SwingClient(this);
                } else {
                        // Not client choosen
-                       this.getLogger().error("No client choosen. Cannot launch.");
+                       this.getLogger().error("No client choosen. Cannot launch."); //NOI18N
                        System.exit(1);
                }
 
@@ -196,6 +190,9 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
 
                // The application is running at this point
                this.getClient().enableIsRunning();
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
        }
 
        /**
@@ -203,24 +200,27 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
         */
        @Override
        public void doMainLoop () {
+               // Get client and cast it
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
                // Debug message
-               this.getLogger().trace("CALLED!");
+               this.getLogger().trace("CALLED!"); //NOI18N
 
-       // @TODO The application should be running now
+               // @TODO The application should be running now
                // Output introduction
                this.showIntro();
 
                // Set current menu to main
-               this.getClient().setCurrentMenu("main");
+               client.setCurrentMenu("main"); //NOI18N
 
                // --- Main loop starts here ---
                while (this.getClient().isRunning()) {
                        // The application is still active, show menu selection
-                       this.getClient().showCurrentMenu();
+                       client.showCurrentMenu();
 
                        try {
                                // Ask for user input and run proper method
-                               this.getClient().doUserMenuChoice();
+                               client.doUserMenuChoice();
                        } catch (final UnhandledUserChoiceException ex) {
                                this.getLogger().catching(ex);
                        }
@@ -232,17 +232,32 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
                                // Ignore it
                        }
                }
-       // --- Main loop ends here ---
+               // --- Main loop ends here ---
 
                // Debug message
-               this.getLogger().debug("Main loop exit - shutting down ...");
+               this.getLogger().debug("Main loop exit - shutting down ..."); //NOI18N
+       }
+
+       /**
+        * Shuts down the application.
+        */
+       @Override
+       public void doShutdown () throws SQLException, IOException {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+               
+               // Shutdown client
+               this.getClient().doShutdown();
+               
+               this.getLogger().info("End of program (last line)"); //NOI18N
+               System.exit(0);
        }
 
        /**
         * Enables console client by setting propper flag
         */
        private void enableConsoleClient () {
-               this.getLogger().debug("Enabling console client (may become optional client) ...");
+               this.getLogger().debug("Enabling console client (may become optional client) ..."); //NOI18N
                this.consoleClient = true;
                this.guiClient = false;
        }
@@ -251,7 +266,7 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
         * Enables GUI client by setting propper flag
         */
        private void enableGuiClient () {
-               this.getLogger().debug("Enabling GUI client (may become new default client) ...");
+               this.getLogger().debug("Enabling GUI client (may become new default client) ..."); //NOI18N
                this.consoleClient = false;
                this.guiClient = true;
        }
@@ -282,17 +297,20 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
         * @param args Arguments from program launch
         */
        private void parseArguments (final String[] args) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("args()={0} - CALLED!", args.length)); //NOI18N
+
                // Debug message
-               this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length));
+               this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length)); //NOI18N
 
                for (final String arg : args) {
                        // Switch on it
                        switch (arg) {
-                               case "-console":
+                               case "-console": //NOI18N
                                        enableConsoleClient();
                                        break;
 
-                               case "-gui":
+                               case "-gui": //NOI18N
                                        enableGuiClient();
                                        break;
                        }
@@ -303,8 +321,14 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
         * Show introduction which depends on client
         */
        private void showIntro () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
                // Let the client show it
                this.getClient().showWelcome();
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
        }
 
        /**
@@ -313,7 +337,14 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
         * @param args Arguments handled to program
         */
        private void start (final String args[]) {
-               this.getLogger().info("Program is started.");
+               this.getLogger().info("Program is started."); //NOI18N
+               try {
+                       // Init properties file
+                       this.initProperties();
+               } catch (final IOException ex) {
+                       // Something bad happened
+                       this.abortProgramWithException(ex);
+               }
 
                // Parse arguments
                this.parseArguments(args);
@@ -322,8 +353,12 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
                ApplicationManager.getManager(this).start();
 
                // Good bye, but this should not be reached ...
-               this.getLogger().warn("Unusual exit reached.");
-               this.doShutdown();
+               this.getLogger().warn("Unusual exit reached."); //NOI18N
+               try {
+                       this.doShutdown();
+               } catch (final SQLException | IOException ex) {
+                       this.abortProgramWithException(ex);
+               }
        }
 
        /**
@@ -332,29 +367,22 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli
         * @param args the command line arguments
         */
        public static void main (String[] args) {
-               // Start application
-               new AddressbookApplication().start(args);
-       }
-
-       /**
-        * Shuts down the application.
-        */
-       @Override
-       public void doShutdown () {
-               // Shutdown client
-               this.getClient().doShutdown();
-
-               this.getLogger().info("End of program (last line)");
-               System.exit(0);
+               try {
+                       // Start application
+                       new AddressbookApplication().start(args);
+               } catch (final IOException ex) {
+                       // Get instance
+                       BaseFrameworkSystem.getInstance().getLogger().catching(ex);
+                       System.exit(1);
+               }
        }
 
        /**
-        * Getter for this application
-        * 
-        * @return Instance from this application
+        * Getter for printable application name
+        *
+        * @return A printable name
         */
-       public static final Application getInstance () {
-               // Return it
-               return selfInstance;
+       public static String printableTitle () {
+               return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION); //NOI18N
        }
 }