From fed8835173cbf96fceec08639f4a20d890fec23c Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 12 Aug 2015 17:47:05 +0200 Subject: [PATCH] =?utf8?q?Fixes=20for=20missing=20throws=20statements=20(b?= =?utf8?q?ecause=20jcore=20has=20changed).=20Signed-off-by:Roland=20H?= =?utf8?q?=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../addressbook/BaseAddressbookSystem.java | 2 -- .../application/AddressbookApplication.java | 20 ++++++++++++++---- .../client/BaseAddressbookClient.java | 6 +++++- .../client/console/ConsoleClient.java | 15 +++++++++---- .../addressbook/client/gui/SwingClient.java | 12 ++++++----- .../AddressbookContactDatabaseFrontend.java | 10 ++++++--- .../contact/AddressbookContactFrontend.java | 5 ++++- .../contact/AddressbookContactManager.java | 21 +++++++++++++++---- 8 files changed, 67 insertions(+), 24 deletions(-) diff --git a/Addressbook/src/org/mxchange/addressbook/BaseAddressbookSystem.java b/Addressbook/src/org/mxchange/addressbook/BaseAddressbookSystem.java index a835d3f..aa8c235 100644 --- a/Addressbook/src/org/mxchange/addressbook/BaseAddressbookSystem.java +++ b/Addressbook/src/org/mxchange/addressbook/BaseAddressbookSystem.java @@ -28,7 +28,5 @@ public class BaseAddressbookSystem extends BaseFrameworkSystem { * No instances can be created of this class */ protected BaseAddressbookSystem () { - // Init properties file - this.initProperties(); } } diff --git a/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java b/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java index c14c64f..ea26bc1 100644 --- a/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java +++ b/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java @@ -16,11 +16,13 @@ */ package org.mxchange.addressbook.application; +import java.io.IOException; import java.text.MessageFormat; import org.mxchange.addressbook.BaseAddressbookSystem; import org.mxchange.addressbook.client.AddressbookClient; import org.mxchange.addressbook.client.console.ConsoleClient; import org.mxchange.addressbook.client.gui.SwingClient; +import org.mxchange.jcore.BaseFrameworkSystem; import org.mxchange.jcore.application.Application; import org.mxchange.jcore.client.Client; import org.mxchange.jcore.exceptions.UnhandledUserChoiceException; @@ -140,9 +142,13 @@ public class AddressbookApplication extends BaseAddressbookSystem implements App /** * Protected constructor + * @throws java.io.IOException If any IO error occurs */ - protected AddressbookApplication () { - // Always init i18n bundle in this application + protected AddressbookApplication () throws IOException { + // Init properties file + this.initProperties(); + + // Init bundle this.initBundle(); } @@ -349,8 +355,14 @@ public class AddressbookApplication extends BaseAddressbookSystem implements App * @param args the command line arguments */ public static void main (String[] args) { - // Start application - new AddressbookApplication().start(args); + try { + // Start application + new AddressbookApplication().start(args); + } catch (final IOException ex) { + // Get instance + BaseFrameworkSystem.getInstance().getLogger().catching(ex); + System.exit(1); + } } /** diff --git a/Addressbook/src/org/mxchange/addressbook/client/BaseAddressbookClient.java b/Addressbook/src/org/mxchange/addressbook/client/BaseAddressbookClient.java index faafb9d..2f2e2aa 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/BaseAddressbookClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/BaseAddressbookClient.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.client; +import java.sql.SQLException; import java.text.MessageFormat; import java.util.HashMap; import java.util.Map; @@ -23,6 +24,7 @@ import org.mxchange.addressbook.manager.contact.AddressbookContactManager; import org.mxchange.addressbook.menu.Menu; import org.mxchange.jcore.client.BaseClient; import org.mxchange.jcore.client.Client; +import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; import org.mxchange.jcore.manager.database.ManageableDatabase; /** @@ -104,8 +106,10 @@ public abstract class BaseAddressbookClient extends BaseClient { /** * Initializes contact manager + * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the database backend is not supported + * @throws java.sql.SQLException If any SQL error occurs */ - protected void initContactManager () { + protected void initContactManager () throws UnsupportedDatabaseBackendException, SQLException { // Trace message this.getLogger().trace("CALLED!"); //NOI18N diff --git a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java index 8a7bece..176418b 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java @@ -16,14 +16,13 @@ */ package org.mxchange.addressbook.client.console; +import java.sql.SQLException; import java.text.MessageFormat; import java.util.Arrays; import java.util.Scanner; import org.mxchange.addressbook.application.AddressbookApplication; import org.mxchange.addressbook.client.AddressbookClient; import org.mxchange.addressbook.client.BaseAddressbookClient; -import org.mxchange.jcore.contact.Contact; -import org.mxchange.jcore.contact.Gender; import org.mxchange.addressbook.contact.user.UserContact; import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException; import org.mxchange.addressbook.manager.contact.ManageableAddressbookContact; @@ -33,7 +32,10 @@ import org.mxchange.addressbook.menu.console.ConsoleMenu; import org.mxchange.addressbook.menu.item.SelectableMenuItem; import org.mxchange.addressbook.menu.item.console.ConsoleMenuItem; import org.mxchange.jcore.application.Application; +import org.mxchange.jcore.contact.Contact; +import org.mxchange.jcore.contact.Gender; import org.mxchange.jcore.exceptions.UnhandledUserChoiceException; +import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; /** * A client for the console @@ -548,7 +550,7 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC } /** - * Inizializes this client + * Initializes this client */ @Override public void init () { @@ -556,7 +558,12 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC this.getLogger().trace("CALLED!"); //NOI18N // Init contact manager here - this.initContactManager(); + try { + this.initContactManager(); + } catch (final UnsupportedDatabaseBackendException | SQLException ex) { + // End here + this.abortProgramWithException(ex); + } // Fill menu map this.fillMenuMap(); diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java index be62260..8a27f24 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java @@ -16,16 +16,18 @@ */ package org.mxchange.addressbook.client.gui; -import org.mxchange.jcore.client.gui.ClientFrame; +import java.sql.SQLException; import org.mxchange.addressbook.client.AddressbookClient; import org.mxchange.addressbook.client.BaseAddressbookClient; import org.mxchange.addressbook.menu.Menu; import org.mxchange.addressbook.menu.item.SelectableMenuItem; import org.mxchange.jcore.application.Application; +import org.mxchange.jcore.client.gui.ClientFrame; import org.mxchange.jcore.contact.Contact; import org.mxchange.jcore.contact.Gender; import org.mxchange.jcore.exceptions.FrameAlreadyInitializedException; import org.mxchange.jcore.exceptions.UnhandledUserChoiceException; +import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; /** * @@ -177,13 +179,13 @@ public class SwingClient extends BaseAddressbookClient implements AddressbookCli // Debug message this.getLogger().trace("CALLED!"); //NOI18N - // Init contact manager here - this.initContactManager(); - try { + // Init contact manager here + this.initContactManager(); + // Init frame this.frame.init(); - } catch (final FrameAlreadyInitializedException ex) { + } catch (final FrameAlreadyInitializedException | UnsupportedDatabaseBackendException | SQLException ex) { // Abort program this.abortProgramWithException(ex); } diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactDatabaseFrontend.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactDatabaseFrontend.java index 9b574f3..25e2bf8 100644 --- a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactDatabaseFrontend.java +++ b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactDatabaseFrontend.java @@ -47,8 +47,10 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp * Constructor which accepts a contact manager * * @param manager Manager instance + * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the database backend is not supported + * @throws java.sql.SQLException If any SQL error occurs */ - public AddressbookContactDatabaseFrontend (final AddressbookContactManager manager) { + public AddressbookContactDatabaseFrontend (final AddressbookContactManager manager) throws UnsupportedDatabaseBackendException, SQLException { // Call own constructor this(); @@ -66,7 +68,7 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp } /** - * Basic constrcutor + * Default but protected constructor * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the database backend is not supported * @throws java.sql.SQLException Any SQL exception from e.g. MySQL connector */ @@ -226,9 +228,11 @@ public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend imp * Checks whether own contact is found in database * * @return Whether own contact is found + * @throws java.io.IOException If any IO error occurs + * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found */ @Override - public boolean isOwnContactFound () throws SQLException { + public boolean isOwnContactFound () throws SQLException, IOException, BadTokenException { // Get search criteria instance SearchableCritera critera = new SearchCriteria(); diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactFrontend.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactFrontend.java index 5c2cc8a..9e7e83f 100644 --- a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactFrontend.java +++ b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactFrontend.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.database.frontend.contact; +import java.io.IOException; import java.sql.SQLException; import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException; import org.mxchange.jcore.contact.Contact; @@ -66,8 +67,10 @@ public interface AddressbookContactFrontend extends DatabaseFrontend { * * @return Whether own contact is found * @throws java.sql.SQLException If any SQL error occurs + * @throws java.io.IOException If an IO error occurs + * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found */ - public boolean isOwnContactFound () throws SQLException; + public boolean isOwnContactFound () throws SQLException, IOException, BadTokenException; /** * Reads a single row and parses it to a contact instance diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java index b85e9d3..980c64b 100644 --- a/Addressbook/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java +++ b/Addressbook/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java @@ -16,6 +16,8 @@ */ package org.mxchange.addressbook.manager.contact; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.sql.SQLException; import java.text.MessageFormat; import java.util.ArrayList; @@ -31,6 +33,7 @@ import org.mxchange.jcore.contact.Contact; import org.mxchange.jcore.contact.Gender; import org.mxchange.jcore.exceptions.BadTokenException; import org.mxchange.jcore.exceptions.UnhandledUserChoiceException; +import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; import org.mxchange.jcore.manager.BaseManager; /** @@ -61,8 +64,10 @@ public class AddressbookContactManager extends BaseManager implements Manageable * a client instance. * * @param client Client instance to use + * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the database backend is not supported + * @throws java.sql.SQLException If an SQL error occurs */ - public AddressbookContactManager (final Client client) { + public AddressbookContactManager (final Client client) throws UnsupportedDatabaseBackendException, SQLException { // Trace message this.getLogger().trace(MessageFormat.format("client={1} - CALLED!", client)); //NOI18N @@ -327,9 +332,12 @@ public class AddressbookContactManager extends BaseManager implements Manageable /** * 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 () { + public void doShutdown () throws SQLException, IOException { // Trace message this.getLogger().trace("CALLED!"); //NOI18N @@ -615,7 +623,12 @@ public class AddressbookContactManager extends BaseManager implements Manageable this.getLogger().debug(MessageFormat.format("columnName={0}", columnName)); // Now get that column - Object value = contact.getValueFromColumn(columnName); + Object value = null; + try { + value = contact.getValueFromColumn(columnName); + } catch (final IllegalArgumentException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + this.abortProgramWithException(ex); + } // Trace message this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); @@ -641,7 +654,7 @@ public class AddressbookContactManager extends BaseManager implements Manageable try { // Deligate this call to frontend isAdded = this.getContactDatabase().isOwnContactFound(); - } catch (final SQLException ex) { + } catch (final SQLException | IOException | BadTokenException ex) { // Something bad happened this.abortProgramWithException(ex); } -- 2.39.5