]> git.mxchange.org Git - addressbook-lib.git/blobdiff - src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java
Prepared for upcoming rewrite:
[addressbook-lib.git] / src / org / mxchange / addressbook / manager / contact / AddressbookContactManager.java
index 805c3a41b6faee54c86b7f5fce54c19f561dd210..beafc29e5a20f918ac0fd9edbb9b2969cebc2458 100644 (file)
@@ -31,6 +31,7 @@ import org.mxchange.jcore.exceptions.UnhandledUserChoiceException;
 import org.mxchange.jcore.manager.BaseManager;
 import org.mxchange.jcore.model.contact.Contact;
 import org.mxchange.jcore.model.contact.gender.Gender;
+import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
 
 /**
  * A manager for contacts.
@@ -50,6 +51,11 @@ public class AddressbookContactManager extends BaseManager implements Manageable
         */
        private final List<String> translatedColumnNames;
 
+       /**
+        * Logger instance
+        */
+       private LoggerBeanLocal logger;
+
        /**
         * Constructor which accepts maxContacts for maximum (initial) contacts and
         * a client instance.
@@ -59,7 +65,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
         */
        public AddressbookContactManager (final Client client) throws SQLException {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("client={1} - CALLED!", client)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("client={1} - CALLED!", client)); //NOI18N
 
                // Make sure all parameters are set correctly
                if (null == client) {
@@ -82,7 +88,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                this.fillColumnNamesFromBundle();
 
                // Debug message
-               //* NOISY-DEBUG: */ this.getLogger().debug("client=" + client);
+               //* NOISY-DEBUG: */ this.getLogger().logDebug("client=" + client);
        }
 
        /**
@@ -93,7 +99,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public void addContact (final Contact contact) throws ContactAlreadyAddedException {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
 
                // Contact instance must not be null
                if (null == contact) {
@@ -105,7 +111,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                ((AddressbookContactFrontend) this.getFrontend()).addContact(contact);
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
        /**
@@ -124,7 +130,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public void doChangeAddressData (final Contact contact) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
 
                // Contact must not be null
                if (null == contact) {
@@ -152,7 +158,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                }
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
        /**
@@ -163,7 +169,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public void doChangeNameData (final Contact contact) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
 
                // Contact must not be null
                if (null == contact) {
@@ -187,7 +193,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                }
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
        /**
@@ -206,7 +212,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public void doChangeOtherData (final Contact contact) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
 
                // Contact must not be null
                if (null == contact) {
@@ -230,7 +236,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                }
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
        /**
@@ -239,7 +245,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public void doChangeOwnData () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                /*
                 * First check if the user has registered own contact, before that
@@ -257,10 +263,10 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                Contact contact = this.getOwnContact();
 
                // It must be found
-               assert (contact instanceof Contact);
+               assert (contact instanceof Contact) : ": contact is not implementing Contact: " + contact;
 
                // Display contact
-               contact.show(this.getClient());
+               this.getClient().show(contact);
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -269,11 +275,11 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                        // Ask user what to change
                        client.userChooseChangeContactData(contact);
                } catch (final UnhandledUserChoiceException ex) {
-                       this.getLogger().catching(ex);
+                       this.getLogger().logException(ex);
                }
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
        /**
@@ -290,7 +296,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public void doEnterOwnData () throws ContactAlreadyAddedException, IOException {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Is own contact already added?
                if (this.isOwnContactAdded()) {
@@ -311,7 +317,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                }
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
        @Override
@@ -333,13 +339,13 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public void doShutdown () throws SQLException, IOException {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Shut down the database layer
                ((AddressbookContactFrontend) this.getFrontend()).doShutdown();
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
        /**
@@ -350,7 +356,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public String enterOwnCellNumber () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -366,7 +372,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public String enterOwnCity () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -382,7 +388,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public String enterOwnComment () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -398,7 +404,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public String enterOwnCompanyName () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -414,7 +420,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public String enterOwnCountryCode () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -430,7 +436,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public String enterOwnEmailAddress () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -446,7 +452,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public String enterOwnFamilyName () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -462,7 +468,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public String enterOwnFaxNumber () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -478,7 +484,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public String enterOwnFirstName () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -494,7 +500,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public Gender enterOwnGender () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -510,7 +516,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public String enterOwnPhoneNumber () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -526,7 +532,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public String enterOwnStreet () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -542,7 +548,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public int enterOwnZipCode () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -576,18 +582,18 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public Object getValueFromRowColumn (final int rowIndex, final int columnIndex) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("rowIndex={0},columnIndex={1} CALLED!", rowIndex, columnIndex)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("rowIndex={0},columnIndex={1} CALLED!", rowIndex, columnIndex)); //NOI18N
 
                // Then get specific row from database which is a Contact instance
                Storable storable = this.getFrontend().getStorableAtRow(rowIndex);
 
                // Debug message
-               this.getLogger().debug(MessageFormat.format("storable={0}", storable)); //NOI18N
+               this.getLogger().logDebug(MessageFormat.format("storable={0}", storable)); //NOI18N
 
                // It may return null
                if (null == storable) {
                        // Nothing found
-                       this.getLogger().warn("contact is null - returning null ..."); //NOI18N
+                       this.getLogger().logWarning("contact is null - returning null ..."); //NOI18N
                        return null;
                }
 
@@ -595,7 +601,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                String columnName = this.getColumnName(columnIndex);
 
                // Debug message
-               this.getLogger().debug(MessageFormat.format("columnName={0}", columnName)); //NOI18N
+               this.getLogger().logDebug(MessageFormat.format("columnName={0}", columnName)); //NOI18N
 
                // Now get that column
                Object value = null;
@@ -606,7 +612,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                }
 
                // Trace message
-               this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
 
                // Return it
                return value;
@@ -621,7 +627,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public boolean isOwnContactAdded () throws IOException {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Init variable
                boolean isAdded = false;
@@ -635,12 +641,17 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                }
 
                // Trace message
-               this.getLogger().trace(MessageFormat.format("isAdded={0} : EXIT!", isAdded)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("isAdded={0} : EXIT!", isAdded)); //NOI18N
 
                // Return result
                return isAdded;
        }
 
+       @Override
+       public void logException (final Throwable exception) {
+               this.getLogger().logException(exception);
+       }
+
        /**
         * Adds given contact to address book and flushes all entries to database
         * <p>
@@ -649,7 +660,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
        @Override
        public void registerContact (final Contact contact) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
 
                // Sanity check
                if (null == contact) {
@@ -657,12 +668,6 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                        throw new NullPointerException("contact is null"); //NOI18N
                }
                try {
-
-                       // Debug message
-                       /*
-                        * NOISY-DEBUG:
-                        */ this.getLogger().debug(MessageFormat.format("Adding '{0}' '{1}' at pos '{2}' ...", contact.getFirstName(), contact.getFamilyName(), this.size())); //NOI18N
-
                        // Check if contact is found
                        if (((AddressbookContactFrontend) this.getFrontend()).isContactFound(contact)) {
                                // Contact already added
@@ -680,7 +685,20 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                }
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
+       }
+
+       /**
+        * Logs given exception and exits program
+        *
+        * @param throwable Throwable
+        */
+       private void abortProgramWithException (Throwable throwable) {
+               // Log exception
+               this.logException(throwable);
+
+               // Abort here
+               System.exit(1);
        }
 
        /**
@@ -691,7 +709,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                assert (this.translatedColumnNames instanceof List) : "this.translatedColumnNames is not initialized"; //NOI18N
 
                // Debug message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // First get an iterator from key set to iterate over
                Iterator<String> iterator = this.getBundle().keySet().iterator();
@@ -704,7 +722,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                        // Does the key start with AddressbookContactManager.columnName ?
                        if (key.startsWith("ContactManager.columnName")) { //NOI18N
                                // This is the wanted entry.
-                               this.getLogger().debug(MessageFormat.format("key={0}", key)); //NOI18N
+                               this.getLogger().logDebug(MessageFormat.format("key={0}", key)); //NOI18N
 
                                // Convert string to array based on delimiter '.'
                                String[] tokens = this.getArrayFromString(key, "."); //NOI18N
@@ -716,7 +734,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                                String columnName = tokens[tokens.length - 2];
 
                                // Debug message
-                               this.getLogger().debug(MessageFormat.format("columnName={0} - adding ...", columnName)); //NOI18N
+                               this.getLogger().logDebug(MessageFormat.format("columnName={0} - adding ...", columnName)); //NOI18N
 
                                // So add it
                                this.columnNames.add(columnName);
@@ -725,7 +743,16 @@ public class AddressbookContactManager extends BaseManager implements Manageable
                }
 
                // Debug message
-               this.getLogger().trace(MessageFormat.format("getColumnCount()={0}: EXIT!", this.getColumnCount())); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("getColumnCount()={0}: EXIT!", this.getColumnCount())); //NOI18N
+       }
+
+       /**
+        * Getter for logger instance
+        *
+        * @return Logger instance
+        */
+       private LoggerBeanLocal getLogger () {
+               return this.logger;
        }
 
        /**
@@ -740,13 +767,13 @@ public class AddressbookContactManager extends BaseManager implements Manageable
         */
        private Contact getOwnContact () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Deligate this call to database frontend
                Contact contact = ((AddressbookContactFrontend) this.getFrontend()).getOwnContact();
 
                // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N
 
                // Return instance or null
                return contact;