From: Roland Haeder Date: Wed, 30 Sep 2015 07:25:03 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8f39e6c8e605ac61f32e40e65418821bf2949e5a;p=jfinancials-swing.git Continued: - fixed some errors (not all) - updated jars Signed-off-by:Roland Häder --- diff --git a/lib/jcore-logger-lib.jar b/lib/jcore-logger-lib.jar index e03e3ca..463d15b 100644 Binary files a/lib/jcore-logger-lib.jar and b/lib/jcore-logger-lib.jar differ diff --git a/lib/jcore-swing.jar b/lib/jcore-swing.jar index 224efdf..bcf9b93 100644 Binary files a/lib/jcore-swing.jar and b/lib/jcore-swing.jar differ diff --git a/lib/jcore.jar b/lib/jcore.jar index af5610d..848bebf 100644 Binary files a/lib/jcore.jar and b/lib/jcore.jar differ diff --git a/src/org/mxchange/addressbook/BaseAddressbookSystem.java b/src/org/mxchange/addressbook/BaseAddressbookSystem.java index 90674c7..6f4ec4a 100644 --- a/src/org/mxchange/addressbook/BaseAddressbookSystem.java +++ b/src/org/mxchange/addressbook/BaseAddressbookSystem.java @@ -20,11 +20,12 @@ import javax.naming.Context; 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 - * + *

* @author Roland Haeder */ public abstract class BaseAddressbookSystem extends BaseFrameworkSystem { @@ -32,6 +33,7 @@ public abstract class BaseAddressbookSystem extends BaseFrameworkSystem { /** * Logger instance */ + @Log private LoggerBeanLocal logger; /** @@ -41,7 +43,7 @@ public abstract class BaseAddressbookSystem extends BaseFrameworkSystem { 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) { @@ -52,7 +54,7 @@ public abstract class BaseAddressbookSystem extends BaseFrameworkSystem { /** * Getter for logger instance - * + *

* @return Logger instance */ protected LoggerBeanLocal getLogger () { @@ -61,7 +63,7 @@ public abstract class BaseAddressbookSystem extends BaseFrameworkSystem { /** * Logs given exception - * + *

* @param exception Throwable */ protected void logException (final Throwable exception) { @@ -70,7 +72,7 @@ public abstract class BaseAddressbookSystem extends BaseFrameworkSystem { /** * Log exception and abort program. - * + *

* @param throwable Throwable */ protected void abortProgramWithException (final Throwable throwable) { diff --git a/src/org/mxchange/addressbook/application/AddressbookApplication.java b/src/org/mxchange/addressbook/application/AddressbookApplication.java index 2859e5c..4f07e31 100644 --- a/src/org/mxchange/addressbook/application/AddressbookApplication.java +++ b/src/org/mxchange/addressbook/application/AddressbookApplication.java @@ -19,14 +19,19 @@ package org.mxchange.addressbook.application; 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; /** @@ -60,21 +65,30 @@ public class AddressbookApplication extends BaseApplication implements Applicati /** * 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(); } /** @@ -132,7 +146,7 @@ public class AddressbookApplication extends BaseApplication implements Applicati * Main loop of the application */ @Override - public void doMainLoop () { + public void doMainLoop () throws MenuInitializationException { // Get client and cast it AddressbookClient client = (AddressbookClient) this.getClient(); @@ -155,6 +169,7 @@ public class AddressbookApplication extends BaseApplication implements Applicati // Ask for user input and run proper method client.doUserMenuChoice(); } catch (final UnhandledUserChoiceException ex) { + // Log exception this.getLogger().logException(ex); } @@ -182,10 +197,32 @@ public class AddressbookApplication extends BaseApplication implements Applicati // 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 * @@ -312,8 +349,13 @@ public class AddressbookApplication extends BaseApplication implements Applicati // 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 diff --git a/src/org/mxchange/addressbook/client/AddressbookClient.java b/src/org/mxchange/addressbook/client/AddressbookClient.java index e884edb..c53c27d 100644 --- a/src/org/mxchange/addressbook/client/AddressbookClient.java +++ b/src/org/mxchange/addressbook/client/AddressbookClient.java @@ -16,6 +16,7 @@ */ 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; @@ -78,8 +79,9 @@ public interface AddressbookClient extends Client { * Asks the user for a choice and proceeds accordingly *

* @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 diff --git a/src/org/mxchange/addressbook/client/BaseAddressbookClient.java b/src/org/mxchange/addressbook/client/BaseAddressbookClient.java index 094d0ec..00a55bd 100644 --- a/src/org/mxchange/addressbook/client/BaseAddressbookClient.java +++ b/src/org/mxchange/addressbook/client/BaseAddressbookClient.java @@ -28,6 +28,7 @@ import org.mxchange.addressbook.manager.contact.ManageableContactAddressbook; 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; /** @@ -50,6 +51,7 @@ public abstract class BaseAddressbookClient extends BaseClient implements Addres /** * Logger instance */ + @Log private LoggerBeanLocal logger; /** diff --git a/src/org/mxchange/addressbook/client/console/ConsoleClient.java b/src/org/mxchange/addressbook/client/console/ConsoleClient.java index 5deface..b01739e 100644 --- a/src/org/mxchange/addressbook/client/console/ConsoleClient.java +++ b/src/org/mxchange/addressbook/client/console/ConsoleClient.java @@ -26,6 +26,7 @@ import org.mxchange.addressbook.application.AddressbookApplication; 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; @@ -311,7 +312,7 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC } @Override - public void doUserMenuChoice () throws UnhandledUserChoiceException { + public void doUserMenuChoice () throws UnhandledUserChoiceException, MenuInitializationException { // Trace message this.getLogger().logTrace("CALLED!"); //NOI18N @@ -530,6 +531,11 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC 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()); diff --git a/src/org/mxchange/addressbook/client/gui/SwingClient.java b/src/org/mxchange/addressbook/client/gui/SwingClient.java index d2316ce..8d91d07 100644 --- a/src/org/mxchange/addressbook/client/gui/SwingClient.java +++ b/src/org/mxchange/addressbook/client/gui/SwingClient.java @@ -197,6 +197,11 @@ public class SwingClient extends BaseAddressbookClient implements AddressbookCli 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 diff --git a/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java b/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java index beafc29..d5833c4 100644 --- a/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java +++ b/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java @@ -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.Log; import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; /** @@ -54,6 +55,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable /** * Logger instance */ + @Log private LoggerBeanLocal logger; /** @@ -647,8 +649,12 @@ public class AddressbookContactManager extends BaseManager implements Manageable return isAdded; } - @Override - public void logException (final Throwable exception) { + /** + * Logs given exception + *

+ * @param exception Throwable + */ + protected void logException (final Throwable exception) { this.getLogger().logException(exception); } diff --git a/src/org/mxchange/addressbook/menu/BaseMenu.java b/src/org/mxchange/addressbook/menu/BaseMenu.java index ad8c2e5..019c8e0 100644 --- a/src/org/mxchange/addressbook/menu/BaseMenu.java +++ b/src/org/mxchange/addressbook/menu/BaseMenu.java @@ -25,10 +25,11 @@ import org.mxchange.addressbook.menu.item.SelectableMenuItem; 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 diff --git a/src/org/mxchange/addressbook/menu/Menu.java b/src/org/mxchange/addressbook/menu/Menu.java index e027a47..909d2ef 100644 --- a/src/org/mxchange/addressbook/menu/Menu.java +++ b/src/org/mxchange/addressbook/menu/Menu.java @@ -21,7 +21,8 @@ import org.mxchange.addressbook.menu.item.SelectableMenuItem; import org.mxchange.jcore.client.Client; /** - * + * An interface for menus + *

* @author Roland Haeder TODO find better name */ public interface Menu { diff --git a/src/org/mxchange/addressbook/menu/MenuTools.java b/src/org/mxchange/addressbook/menu/MenuTools.java index 54d7c96..9f42475 100644 --- a/src/org/mxchange/addressbook/menu/MenuTools.java +++ b/src/org/mxchange/addressbook/menu/MenuTools.java @@ -16,11 +16,11 @@ */ 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 @@ -36,17 +36,16 @@ public class MenuTools extends BaseAddressbookSystem { * @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 menus, final String menuType) { + public static char[] getAccessKeysFromMenuMap (final Map 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