]> git.mxchange.org Git - addressbook-swing.git/blobdiff - src/org/mxchange/addressbook/client/BaseAddressbookClient.java
Continued:
[addressbook-swing.git] / src / org / mxchange / addressbook / client / BaseAddressbookClient.java
index 094d0ecee9a485b2d3369cbbb86dfc1658b0a0fd..b566d764854f8681ddbc63338de9c20c27b812e8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Roland Haeder
+ * Copyright (C) 2016 - 2020 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -18,22 +18,23 @@ package org.mxchange.addressbook.client;
 
 import java.sql.SQLException;
 import java.text.MessageFormat;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
-import org.mxchange.addressbook.manager.contact.AddressbookContactManager;
-import org.mxchange.addressbook.manager.contact.ManageableContactAddressbook;
+import org.mxchange.addressbook.facade.contact.AddressbookContactFacade;
+import org.mxchange.addressbook.facade.contact.ContactFacade;
 import org.mxchange.addressbook.menu.Menu;
 import org.mxchange.jcore.client.BaseClient;
-import org.mxchange.jcore.client.Client;
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;
 import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
 
 /**
  * A general addressbook client
  * <p>
- * @author Roland Haeder TODO: Find better name
+ * @author Roland Häder<roland@mxchange.org> TODO: Find better name
  */
 public abstract class BaseAddressbookClient extends BaseClient implements AddressbookClient {
 
@@ -43,14 +44,15 @@ public abstract class BaseAddressbookClient extends BaseClient implements Addres
        private String currentMenu;
 
        /**
-        * Menu system
+        * Logger instance
         */
-       private final Map<String, Menu> menus;
+       @Log
+       private LoggerBeanLocal loggerBeanLocal;
 
        /**
-        * Logger instance
+        * Menu system
         */
-       private LoggerBeanLocal logger;
+       private final Map<String, Menu> menus;
 
        /**
         * No instances can be created of this class
@@ -64,8 +66,8 @@ public abstract class BaseAddressbookClient extends BaseClient implements Addres
                        // Get context
                        Context context = new InitialContext();
 
-                       // Lookup logger
-                       this.logger = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal");
+                       // Lookup loggerBeanLocal
+                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
                } catch (final NamingException ex) {
                        // Continue to throw
                        throw new RuntimeException(ex);
@@ -77,12 +79,12 @@ public abstract class BaseAddressbookClient extends BaseClient implements Addres
         * <p>
         * @return the currentMenu
         */
-       public final String getCurrentMenu () {
+       public String getCurrentMenu () {
                return this.currentMenu;
        }
 
        @Override
-       public final void setCurrentMenu (final String currentMenu) {
+       public void setCurrentMenu (final String currentMenu) {
                this.currentMenu = currentMenu;
        }
 
@@ -90,6 +92,7 @@ public abstract class BaseAddressbookClient extends BaseClient implements Addres
         * "Getter" for given menu type
         * <p>
         * @param menuType Menu type instance to return
+        * <p>
         * @return Menu or null if not found
         */
        private Menu getMenu (final String menuType) {
@@ -106,18 +109,40 @@ public abstract class BaseAddressbookClient extends BaseClient implements Addres
                return menu;
        }
 
+       /**
+        * Logs exception and exits program
+        * <p>
+        * @param throwable Throwable
+        */
+       protected void abortProgramWithException (final Throwable throwable) {
+               // Log exception
+               this.logException(throwable);
+
+               // Abort here
+               System.exit(1);
+       }
+
        /**
         * Fills menu map with swing menus
         */
        protected abstract void fillMenuMap ();
 
+       /**
+        * Getter for loggerBeanLocal instance
+        * <p>
+        * @return Logger instance
+        */
+       protected LoggerBeanLocal getLoggerBeanLocal () {
+               return this.loggerBeanLocal;
+       }
+
        /**
         * Getter for menus map
         * <p>
         * @return Map of all menus
         */
-       protected final Map<String, Menu> getMenus () {
-               return this.menus;
+       protected Map<String, Menu> getMenus () {
+               return Collections.unmodifiableMap(this.menus);
        }
 
        /**
@@ -127,23 +152,33 @@ public abstract class BaseAddressbookClient extends BaseClient implements Addres
         */
        protected void initContactManager () throws SQLException {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Debug message
-               this.getLogger().logDebug("Initializing contact manager ..."); //NOI18N
+               this.getLoggerBeanLocal().logDebug("Initializing contact manager ..."); //NOI18N
 
-               // Init contact manager with console client
+               // Init contact facade with console client
                // TODO Static initial amount of contacts
-               ManageableContactAddressbook manager = new AddressbookContactManager((Client) this);
+               ContactFacade facade = new AddressbookContactFacade(this);
 
                // Set it here
-               this.setManager(manager);
+               this.setFacade(facade);
 
                // Debug message
-               this.getLogger().logDebug("Contact manager has been initialized."); //NOI18N
+               this.getLoggerBeanLocal().logDebug("Contact manager has been initialized."); //NOI18N
 
                // Trace message
-               this.getLogger().logTrace("EXIT!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N
+       }
+
+       /**
+        * Logs an exception
+        * <p>
+        * @param throwable Throwable
+        */
+       protected void logException (final Throwable throwable) {
+               // Deligate to loggerBeanLocal
+               this.getLoggerBeanLocal().logException(throwable);
        }
 
        /**
@@ -153,7 +188,7 @@ public abstract class BaseAddressbookClient extends BaseClient implements Addres
         */
        protected void showMenu (final String menuType) {
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("menuType={0} - CALLED!", menuType)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("menuType={0} - CALLED!", menuType)); //NOI18N
 
                // Get menu from type
                Menu menu = this.getMenu(menuType);
@@ -169,38 +204,6 @@ public abstract class BaseAddressbookClient extends BaseClient implements Addres
                menu.show(this);
 
                // Trace message
-               this.getLogger().logTrace("EXIT!"); //NOI18N
-       }
-
-       /**
-        * Getter for logger instance
-        *
-        * @return Logger instance
-        */
-       protected LoggerBeanLocal getLogger () {
-               return this.logger;
-       }
-
-       /**
-        * Logs an exception
-        *
-        * @param throwable Throwable
-        */
-       protected void logException (final Throwable throwable) {
-               // Deligate to logger
-               this.getLogger().logException(throwable);
-       }
-
-       /**
-        * Logs exception and exits program
-        *
-        * @param throwable Throwable
-        */
-       protected void abortProgramWithException (final Throwable throwable) {
-               // Log exception
-               this.logException(throwable);
-
-               // Abort here
-               System.exit(1);
+               this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N
        }
 }