import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.mxchange.jcore.BaseFrameworkSystem;
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;
import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
/**
* A general addressbook class
- *
+ * <p>
* @author Roland Haeder
*/
public abstract class BaseAddressbookSystem extends BaseFrameworkSystem {
/**
* Logger instance
*/
+ @Log
private LoggerBeanLocal logger;
/**
try {
// Get initial 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");
} catch (final NamingException ex) {
/**
* Getter for logger instance
- *
+ * <p>
* @return Logger instance
*/
protected LoggerBeanLocal getLogger () {
/**
* Logs given exception
- *
+ * <p>
* @param exception Throwable
*/
protected void logException (final Throwable exception) {
/**
* Log exception and abort program.
- *
+ * <p>
* @param throwable Throwable
*/
protected void abortProgramWithException (final Throwable throwable) {
import java.io.IOException;
import java.sql.SQLException;
import java.text.MessageFormat;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
import org.mxchange.addressbook.client.AddressbookClient;
import org.mxchange.addressbook.client.console.ConsoleClient;
import org.mxchange.addressbook.client.gui.SwingClient;
import org.mxchange.jcore.application.Application;
import org.mxchange.jcore.application.BaseApplication;
import org.mxchange.jcore.client.Client;
+import org.mxchange.jcore.exceptions.MenuInitializationException;
import org.mxchange.jcore.exceptions.UnhandledUserChoiceException;
import org.mxchange.jcore.manager.application.ApplicationManager;
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;
import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
/**
/**
* Logger instance
*/
+ @Log
private LoggerBeanLocal logger;
/**
* Protected constructor
*/
protected AddressbookApplication () {
- // Init properties file
- this.initProperties();
+ // Try this
+ try {
+ // Get context
+ Context context = new InitialContext();
- // Is the bundle initialized?
- if (!isBundledInitialized()) {
- // Temporary initialize default bundle
- // TODO The enum Gender uses this
- this.initBundle();
+ // Get logger
+ this.logger = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal");
+ } catch (final NamingException ex) {
+ // Output it and exit
+ System.err.println(MessageFormat.format("Cannot initialize: {0}", ex));
+
+ // Abort here
+ System.exit(1);
}
+
+ // Call init method
+ this.init();
}
/**
* Main loop of the application
*/
@Override
- public void doMainLoop () {
+ public void doMainLoop () throws MenuInitializationException {
// Get client and cast it
AddressbookClient client = (AddressbookClient) this.getClient();
// Ask for user input and run proper method
client.doUserMenuChoice();
} catch (final UnhandledUserChoiceException ex) {
+ // Log exception
this.getLogger().logException(ex);
}
// Shutdown client
this.getClient().doShutdown();
+ // Regular exit reached
this.getLogger().logInfo("End of program (last line)"); //NOI18N
System.exit(0);
}
+ /**
+ * Initializes this application
+ */
+ private void init () {
+ // Try this
+ try {
+ // Init properties file
+ this.initProperties();
+ } catch (final IOException ex) {
+ // Abort here
+ this.abortProgramWithException(ex);
+ }
+
+ // Is the bundle initialized?
+ if (!isBundledInitialized()) {
+ // Temporary initialize default bundle
+ // TODO The enum Gender uses this
+ this.initBundle();
+ }
+ }
+
/**
* Logs given exception
*
// Parse arguments
this.parseArguments(args);
- // Launch application
- ApplicationManager.getSingeltonManager(this).start();
+ try {
+ // Launch application
+ ApplicationManager.getSingeltonManager(this).start();
+ } catch (final MenuInitializationException ex) {
+ // Something bad happened
+ this.abortProgramWithException(ex);
+ }
// Good bye, but this should not be reached ...
this.getLogger().logWarning("Unusual exit reached."); //NOI18N
*/
package org.mxchange.addressbook.client;
+import org.mxchange.jcore.exceptions.MenuInitializationException;
import org.mxchange.addressbook.menu.item.SelectableMenuItem;
import org.mxchange.jcore.client.Client;
import org.mxchange.jcore.exceptions.UnhandledUserChoiceException;
* Asks the user for a choice and proceeds accordingly
* <p>
* @throws UnhandledUserChoiceException If choice is not supported
+ * @throws org.mxchange.jcore.exceptions.MenuInitializationException If the menu cannot be initialized
*/
- public void doUserMenuChoice () throws UnhandledUserChoiceException;
+ public void doUserMenuChoice () throws UnhandledUserChoiceException, MenuInitializationException;
/**
* Asks the the user to enter a single character which must match validChars
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;
/**
/**
* Logger instance
*/
+ @Log
private LoggerBeanLocal logger;
/**
import org.mxchange.addressbook.client.AddressbookClient;
import org.mxchange.addressbook.client.BaseAddressbookClient;
import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
+import org.mxchange.jcore.exceptions.MenuInitializationException;
import org.mxchange.addressbook.manager.contact.ManageableContactAddressbook;
import org.mxchange.addressbook.menu.Menu;
import org.mxchange.addressbook.menu.MenuTools;
}
@Override
- public void doUserMenuChoice () throws UnhandledUserChoiceException {
+ public void doUserMenuChoice () throws UnhandledUserChoiceException, MenuInitializationException {
// Trace message
this.getLogger().logTrace("CALLED!"); //NOI18N
System.out.println(message);
}
+ @Override
+ public void show (final Contact contact) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
@Override
public void showCurrentMenu () {
this.showMenu(this.getCurrentMenu());
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //NOI18N
}
+ @Override
+ public void show (final Contact contact) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
@Override
public void showCurrentMenu () {
// Debug message
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;
/**
/**
* Logger instance
*/
+ @Log
private LoggerBeanLocal logger;
/**
return isAdded;
}
- @Override
- public void logException (final Throwable exception) {
+ /**
+ * Logs given exception
+ * <p>
+ * @param exception Throwable
+ */
+ protected void logException (final Throwable exception) {
this.getLogger().logException(exception);
}
import org.mxchange.jcore.client.Client;
/**
+ * A general menu class
*
* @author Roland Haeder
*/
-public class BaseMenu extends BaseAddressbookSystem {
+public abstract class BaseMenu extends BaseAddressbookSystem {
/**
* Menu list
import org.mxchange.jcore.client.Client;
/**
- *
+ * An interface for menus
+ * <p>
* @author Roland Haeder TODO find better name
*/
public interface Menu {
*/
package org.mxchange.addressbook.menu;
-import java.text.MessageFormat;
import java.util.Iterator;
import java.util.Map;
import org.mxchange.addressbook.BaseAddressbookSystem;
import org.mxchange.addressbook.menu.item.SelectableMenuItem;
+import org.mxchange.jcore.exceptions.MenuInitializationException;
/**
* Menu utilities
* @param menus A Map with all menus and their entries
* @param menuType Menu type
* @return An array with available access chars
+ * @throws org.mxchange.jcore.exceptions.MenuInitializationException If the menu cannot be initialized
*/
- public static char[] getAccessKeysFromMenuMap (final Map<String, Menu> menus, final String menuType) {
+ public static char[] getAccessKeysFromMenuMap (final Map<String, Menu> menus, final String menuType) throws MenuInitializationException {
// First search for the proper menu class
Menu menu = menus.get(menuType);
// Is it there?
if (!(menu instanceof Menu)) {
// Not found
- // TODO Rewrite to exception
- System.err.println(MessageFormat.format("menu is not implementing Menu: {0}", menu)); //NOI18N
- System.exit(1);
+ throw new MenuInitializationException(menu, menuType);
}
// Get iterator