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.
*/
private final List<String> translatedColumnNames;
+ /**
+ * Logger instance
+ */
+ private LoggerBeanLocal logger;
+
/**
* Constructor which accepts maxContacts for maximum (initial) contacts and
* a client instance.
*/
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) {
this.fillColumnNamesFromBundle();
// Debug message
- //* NOISY-DEBUG: */ this.getLogger().debug("client=" + client);
+ //* NOISY-DEBUG: */ this.getLogger().logDebug("client=" + client);
}
/**
@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) {
((AddressbookContactFrontend) this.getFrontend()).addContact(contact);
// Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
+ this.getLogger().logTrace("EXIT!"); //NOI18N
}
/**
@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) {
}
// Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
+ this.getLogger().logTrace("EXIT!"); //NOI18N
}
/**
@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) {
}
// Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
+ this.getLogger().logTrace("EXIT!"); //NOI18N
}
/**
@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) {
}
// Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
+ this.getLogger().logTrace("EXIT!"); //NOI18N
}
/**
@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
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();
// 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
}
/**
@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()) {
}
// Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
+ this.getLogger().logTrace("EXIT!"); //NOI18N
}
@Override
@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
}
/**
@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();
@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();
@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();
@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();
@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();
@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();
@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();
@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();
@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();
@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();
@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();
@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();
@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();
@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;
}
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;
}
// 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;
@Override
public boolean isOwnContactAdded () throws IOException {
// Trace message
- this.getLogger().trace("CALLED!"); //NOI18N
+ this.getLogger().logTrace("CALLED!"); //NOI18N
// Init variable
boolean isAdded = false;
}
// 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>
@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) {
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
}
// 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);
}
/**
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();
// 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
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);
}
// 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;
}
/**
*/
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;