X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Faddressbook%2Fmanager%2Fcontact%2FAddressbookContactManager.java;h=9b0a0b33d45f358615c38e3d031ec4fb1ebcc4e5;hb=d320d13f3f26ab01c36a7d6857918b141977454a;hp=c7aed6ab601404f43d036a9c5fd3348b3b6b7fb9;hpb=9751c29b55df512254d2e3f6d605d80f70836298;p=addressbook-lib.git diff --git a/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java b/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java index c7aed6a..9b0a0b3 100644 --- a/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java +++ b/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java @@ -31,10 +31,12 @@ 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.Log; +import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; /** * A manager for contacts. - * + *
* @author Roland Haeder
* @version 0.0
*/
@@ -45,6 +47,12 @@ public class AddressbookContactManager extends BaseManager implements Manageable
*/
private final List
* @param client Client instance to use
* @throws java.sql.SQLException If an SQL error occurs
*/
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,18 +90,13 @@ 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);
}
- /**
- * Adds given Contact instance to list
- *
- * @param contact Contact instance to add
- */
@Override
- public void addContact (final Contact contact) throws ContactAlreadyAddedException {
+ 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,32 +108,28 @@ public class AddressbookContactManager extends BaseManager implements Manageable
((AddressbookContactFrontend) this.getFrontend()).addContact(contact);
// Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
+ this.getLogger().logTrace("EXIT!"); //NOI18N
}
- /**
- * Let the user add a new other address
- */
@Override
public void doAddOtherAddress () {
throw new UnsupportedOperationException("Not supported yet."); //NOI18N
}
- /**
- * Let the user change address data
- *
- * @param contact Instance to change data
- */
@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) {
// Abort here
throw new NullPointerException("contact is null"); //NOI18N
}
+ if (!(this.getClient() instanceof AddressbookClient)) {
+ // Cannot cast
+ throw new IllegalArgumentException(MessageFormat.format("this.getClient()={0} does not implement AddressbookClient", this.getClient())); //NOI18N
+ }
// Get and cast client instance
AddressbookClient client = (AddressbookClient) this.getClient();
@@ -148,18 +147,13 @@ public class AddressbookContactManager extends BaseManager implements Manageable
}
// Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
+ this.getLogger().logTrace("EXIT!"); //NOI18N
}
- /**
- * Let the user change "name data"
- *
- * @param contact Instance to change data
- */
@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) {
@@ -183,27 +177,18 @@ public class AddressbookContactManager extends BaseManager implements Manageable
}
// Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
+ this.getLogger().logTrace("EXIT!"); //NOI18N
}
- /**
- * Let the user change other address
- */
@Override
public void doChangeOtherAddress () {
throw new UnsupportedOperationException("Not supported yet."); //NOI18N
}
- /**
- * Let the user change other data
- *
- * @param contact Instance to change data
- * TODO Didn't handle birthday
- */
@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) {
@@ -227,16 +212,13 @@ public class AddressbookContactManager extends BaseManager implements Manageable
}
// Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
+ this.getLogger().logTrace("EXIT!"); //NOI18N
}
- /**
- * Allows the user to change his/her own data
- */
@Override
- public void doChangeOwnData () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{
+ 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
@@ -254,10 +236,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();
@@ -266,28 +248,22 @@ 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
}
- /**
- * Let the user delete other address
- */
@Override
public void doDeleteOtherAddress () {
throw new UnsupportedOperationException("Not supported yet."); //NOI18N
}
- /**
- * Asks user for own data
- */
@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()) {
@@ -308,7 +284,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable
}
// Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
+ this.getLogger().logTrace("EXIT!"); //NOI18N
}
@Override
@@ -321,33 +297,22 @@ public class AddressbookContactManager extends BaseManager implements Manageable
throw new UnsupportedOperationException("Not supported yet."); //NOI18N
}
- /**
- * Shuts down this contact manager
- *
- * @throws java.sql.SQLException If an SQL error occurs
- * @throws java.io.IOException If an IO error occurs
- */
@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
}
- /**
- * Asks the user for his/her cellphone number
- *
- * @return User's cellphone number
- */
@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();
@@ -355,15 +320,10 @@ public class AddressbookContactManager extends BaseManager implements Manageable
return client.enterString(5, 30, "Bitte geben Sie Ihre Handynummer an: ", true);
}
- /**
- * Asks the user for his/her city's name
- *
- * @return City's name of the user
- */
@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();
@@ -371,15 +331,10 @@ public class AddressbookContactManager extends BaseManager implements Manageable
return client.enterString(3, 50, "Bitte geben Sie Ihre Wohnort ein: ", false);
}
- /**
- * Asks the user for his/her city's name
- *
- * @return City's name of the user
- */
@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();
@@ -387,15 +342,10 @@ public class AddressbookContactManager extends BaseManager implements Manageable
return client.enterString(0, 100, "Kommentar zu Ihrem Eintrag: ", true);
}
- /**
- * Asks the user for his/her company name
- *
- * @return User's company name
- */
@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();
@@ -403,15 +353,10 @@ public class AddressbookContactManager extends BaseManager implements Manageable
return client.enterString(5, 50, "Bitte geben Sie Ihre Firmenbezeichnung ein: ", true);
}
- /**
- * Asks user for his/her own country code
- *
- * @return User's own country code
- */
@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();
@@ -419,15 +364,10 @@ public class AddressbookContactManager extends BaseManager implements Manageable
return client.enterString(2, 2, "Bitte geben Sie den zweistelligen Ländercode von Ihrem Land ein: ", false).toUpperCase();
}
- /**
- * Asks user for his/her own country code
- *
- * @return User's own country code
- */
@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();
@@ -435,15 +375,10 @@ public class AddressbookContactManager extends BaseManager implements Manageable
return client.enterString(10, 50, "Bitte geben Sie Ihre Email-Adresse ein: ", true);
}
- /**
- * Asks the user for family name
- *
- * @return Family name of the user
- */
@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();
@@ -451,15 +386,10 @@ public class AddressbookContactManager extends BaseManager implements Manageable
return client.enterString(2, 50, "Bitte geben Sie Ihren Nachnamen ein: ", false);
}
- /**
- * Asks the user for family name
- *
- * @return Family name of the user
- */
@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();
@@ -467,31 +397,21 @@ public class AddressbookContactManager extends BaseManager implements Manageable
return client.enterString(5, 30, "Bitte geben Sie Ihre Faxnummer an: ", true);
}
- /**
- * Asks the user for surname
- *
- * @return Surname of the user
- */
@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();
-
+
return client.enterString(2, 50, "Bitte geben Sie Ihren Vornamen ein: ", false);
}
- /**
- * Asks the user for gender, until a valid has been entered
- *
- * @return Gender of the user
- */
@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();
@@ -499,15 +419,10 @@ public class AddressbookContactManager extends BaseManager implements Manageable
return client.enterGender("Bitte geben Sie die Anrede ein: (M=Herr, F=Frau, C=Firma): ");
}
- /**
- * Asks the user for phone number
- *
- * @return Phone number of the user
- */
@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();
@@ -515,15 +430,10 @@ public class AddressbookContactManager extends BaseManager implements Manageable
return client.enterString(5, 30, "Bitte geben Sie Ihre Telefonnummer an: ", true);
}
- /**
- * Asks the user for own street (including number)
- *
- * @return Own street an number
- */
@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();
@@ -531,15 +441,10 @@ public class AddressbookContactManager extends BaseManager implements Manageable
return client.enterString(5, 50, "Bitte geben Sie Ihre Strasse und Hausnummer ein: ", false);
}
- /**
- * Asks the user for own ZIP code
- *
- * @return ZIP code
- */
@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();
@@ -573,18 +478,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;
}
@@ -592,7 +497,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;
@@ -603,22 +508,16 @@ 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;
}
- /**
- * Checks whether own contact is already added by checking all entries for
- * isOwnContact flag
- *
- * @return Whether own contact is already added
- */
@Override
public boolean isOwnContactAdded () throws IOException {
// Trace message
- this.getLogger().trace("CALLED!"); //NOI18N
+ this.getLogger().logTrace("CALLED!"); //NOI18N
// Init variable
boolean isAdded = false;
@@ -632,22 +531,16 @@ 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;
}
- /**
- * Adds given contact to address book and flushes all entries to database
- *
- * @param contact Contact being added
- * TODO Add check for book size
- */
@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) {
@@ -655,10 +548,7 @@ 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
+ // Check if contact is found
if (((AddressbookContactFrontend) this.getFrontend()).isContactFound(contact)) {
// Contact already added
// TODO Do something here
@@ -675,23 +565,20 @@ public class AddressbookContactManager extends BaseManager implements Manageable
}
// Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
+ this.getLogger().logTrace("EXIT!"); //NOI18N
}
- @Override
- public final int size () throws IOException {
- // Init size
- int size = -1;
-
- try {
- size = ((AddressbookContactFrontend) this.getFrontend()).getContactsCount();
- } catch (final SQLException ex) {
- // Something happened
- this.abortProgramWithException(ex);
- }
+ /**
+ * Logs given exception and exits program
+ *
+ * @param throwable Throwable
+ */
+ private void abortProgramWithException (Throwable throwable) {
+ // Log exception
+ this.logException(throwable);
- // Return amount
- return size;
+ // Abort here
+ System.exit(1);
}
/**
@@ -702,7 +589,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
* @return Contact instance or null
* @throws java.sql.SQLException If an SQL error occurs
* @throws java.io.IOException If an IO error occurs
@@ -751,15 +647,24 @@ 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;
}
+
+ /**
+ * Logs given exception
+ *
+ * @param exception Throwable
+ */
+ protected void logException (final Throwable exception) {
+ this.getLogger().logException(exception);
+ }
}