]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Refacturing:
authorRoland Haeder <roland@mxchange.org>
Wed, 2 Sep 2015 17:36:32 +0000 (19:36 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 2 Sep 2015 17:37:01 +0000 (19:37 +0200)
- continue to throw all exceptions from PizzaServiceApplication to let the outer class handle them
- this allows more flexibility than before, e.g. a Swing application doesn't need to handle ServletException then, but can handle the exceptions by itself.
Signed-off-by:Roland Häder <roland@mxchange.org>

src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java
src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java
src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceBean.java

index d281e97cf0ad79ff1900f4e6585ee389c21da0ac..bb2963fb45b298f5b6bc7545b56816eb7120766e 100644 (file)
 package org.mxchange.pizzaapplication.application;
 
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
 import java.sql.SQLException;
 import java.util.Deque;
 import java.util.Iterator;
 import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpSession;
 import org.mxchange.jcore.application.Application;
 import org.mxchange.jcore.exceptions.BadTokenException;
+import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
 import org.mxchange.jshop.category.Category;
 import org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException;
@@ -39,43 +39,47 @@ import org.mxchange.jshop.product.Product;
  * @author Roland Haeder
  */
 public interface PizzaApplication extends Application {
-       /**
-        * HTTP parameter "amount"
-        * @deprecated Don't use this in upcoming JSF
-        */
-       @Deprecated
-       public static final String HTTP_PARAM_AMOUNT = "amount"; //NOI18N
-
-       /**
-        * Mask for all parameters
-        * @deprecated Please refacture!
-        */
-       @Deprecated
-       static final String HTTP_PARAM_MASK = "%s[%s]"; //NOI18N
-
        /**
         * Some "getter" for a linked list of only available products
         * 
         * @return Only available products
-        * @throws javax.servlet.ServletException If anything went wrong
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly
+        * @throws java.lang.reflect.InvocationTargetException If something else happens?
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
         */
-       public Deque<Product> getAvailableProducts () throws ServletException;
+       public Deque<Product> getAvailableProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
 
        /**
         * Some "getter" for a linked list of all products
         *
         * @return All products
-        * @throws javax.servlet.ServletException If anything went wrong
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly
+        * @throws java.lang.reflect.InvocationTargetException If something else happens?
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
         */
-       public Deque<Product> getAllProducts () throws ServletException;
+       public Deque<Product> getAllProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
 
        /**
         * Some "getter" for a linked list of all categories
         *
         * @return All categories
-        * @throws javax.servlet.ServletException If anything went wrong
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly
+        * @throws java.lang.reflect.InvocationTargetException If something else happens?
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
         */
-       public Deque<Category> getAllCategories () throws ServletException;
+       public Deque<Category> getAllCategories () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
 
        /**
         * Initializes this instance with given ServletContext
@@ -92,25 +96,43 @@ public interface PizzaApplication extends Application {
         * Some "getter" for a an array of only available products
         * 
         * @return Only available products
-        * @throws javax.servlet.ServletException If anything went wrong
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly
+        * @throws java.lang.reflect.InvocationTargetException If something else happens?
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
         */
-       public Iterator<Product> getAvailableProductsIterator () throws ServletException;
+       public Iterator<Product> getAvailableProductsIterator () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
 
        /**
         * Some "getter" for a an array of all products
         *
         * @return All products
-        * @throws javax.servlet.ServletException If anything went wrong
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly
+        * @throws java.lang.reflect.InvocationTargetException If something else happens?
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
         */
-       public Iterator<Product> getAllProductsIterator () throws ServletException;
+       public Iterator<Product> getAllProductsIterator () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
 
        /**
         * Some "getter" for a an array of all categories
         *
         * @return All categories
-        * @throws javax.servlet.ServletException If anything went wrong
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly
+        * @throws java.lang.reflect.InvocationTargetException If something else happens?
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
         */
-       public Iterator<Category> getAllCategoriesIterator () throws ServletException;
+       public Iterator<Category> getAllCategoriesIterator () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
 
        /**
         * Checks if given Product instance is available and returns a printable
@@ -126,51 +148,90 @@ public interface PizzaApplication extends Application {
         * 
         * @param product Product instance to check
         * @return Human-readable version of product availability
-        * @throws javax.servlet.ServletException If something unexpected happened
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly
+        * @throws java.lang.reflect.InvocationTargetException If something else happens?
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
         */
-       public String getPrintableProduktCategory (final Product product) throws ServletException;
+       public String getPrintableProductCategory (final Product product) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
 
        /**
         * Adds given category data from request to database
         *
         * @param request Request instance
-        * @throws javax.servlet.ServletException If something unexpected happened
-        * @throws org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException If the given title is already used
+        * @throws org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException The category's title is already used
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly
+        * @throws java.lang.reflect.InvocationTargetException If something else happens?
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
         */
-       public void doAdminAddCategory (final ServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException;
+       public void doAdminAddCategory (final ServletRequest request) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException;
 
        /**
         * Adds given product data from request to database
         *
         * @param request Request instance
-        * @throws javax.servlet.ServletException If something unexpected happened
-        * @throws org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException If the given product title is already used
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly
+        * @throws java.lang.reflect.InvocationTargetException If something else happens?
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
+        * @throws org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException If the product's title is already used
         */
-       public void doAdminAddProduct (final ServletRequest request) throws ServletException, ProductTitleAlreadyUsedException;
+       public void doAdminAddProduct (final ServletRequest request) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException;
 
        /**
         * Handles admin product form requests
         *
         * @param request Request instance
         * @param response Response instance
-        * @throws ServletException If something unexpected happened
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly
+        * @throws java.lang.reflect.InvocationTargetException If something else happens?
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
+        * @throws org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException If the product's title is already used
         */
-       public void doAdminHandleProductForms (final ServletRequest request, final ServletResponse response) throws ServletException;
+       public void doAdminHandleProductForms (final ServletRequest request, final ServletResponse response) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException;
 
        /**
         * Handles admin category form requests
         * 
         * @param request Request instance
         * @param response Response instance
-        * @throws ServletException If something unexpected happened
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly
+        * @throws java.lang.reflect.InvocationTargetException If something else happens?
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
+        * @throws org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException The category's title is already used
         */
-       public void doAdminHandleCategoryForms (final ServletRequest request, final ServletResponse response) throws ServletException;
+       public void doAdminHandleCategoryForms (final ServletRequest request, final ServletResponse response) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException;
 
        /**
         * Some "getter" for a Product instance from given item
+        *
         * @param item Item instance
         * @return A Product instance
-        * @throws ServletException If something unexpected happened
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly
+        * @throws java.lang.reflect.InvocationTargetException If something else happens?
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
         */
-       public Product getProduct (final AddableBasketItem item) throws ServletException;
+       public Product getProduct (final AddableBasketItem item) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
 }
index cc1e3632f6904d89f294184df2dc06938006b409..5052fa56a3a28d1e8fc3bd4618bbc498f325a91c 100644 (file)
 package org.mxchange.pizzaapplication.application;
 
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import java.lang.reflect.InvocationTargetException;
 import java.sql.SQLException;
 import java.text.MessageFormat;
 import java.util.Deque;
 import java.util.Iterator;
 import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
 import org.mxchange.jcore.exceptions.BadTokenException;
 import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
@@ -69,36 +66,21 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
        }
 
        @Override
-       public Deque<Category> getAllCategories () throws ServletException {
-               try {
-                       // Deligate to frontend
-                       return this.categoryFrontend.getAllCategories();
-               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
-                       // Continue to throw
-                       throw new ServletException(ex);
-               }
+       public Deque<Category> getAllCategories () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+               // Deligate to frontend
+               return this.categoryFrontend.getAllCategories();
        }
 
        @Override
-       public Deque<Product> getAllProducts () throws ServletException {
-               try {
-                       // Deligate to frontend
-                       return this.productFrontend.getAllProducts();
-               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
-                       // Continue to throw
-                       throw new ServletException(ex);
-               }
+       public Deque<Product> getAllProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+               // Deligate to frontend
+               return this.productFrontend.getAllProducts();
        }
 
        @Override
-       public Deque<Product> getAvailableProducts () throws ServletException {
-               try {
-                       // Deligate to frontend
-                       return this.productFrontend.getAllAvailableProducts();
-               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
-                       // Continue to throw
-                       throw new ServletException(ex);
-               }
+       public Deque<Product> getAvailableProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+               // Deligate to frontend
+               return this.productFrontend.getAllAvailableProducts();
        }
 
        @Override
@@ -167,24 +149,20 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
 
        @Override
        @SuppressWarnings ("unchecked")
-       public Iterator<Product> getAvailableProductsIterator () throws ServletException {
+       public Iterator<Product> getAvailableProductsIterator () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                // categoryFrontend must be set
                if (null == this.productFrontend) {
                        // Abort here
                        throw new NullPointerException("productFrontend is null"); //NOI18N
                }
 
-               try {
-                       // Ask frontend for a list of products
-                       return (Iterator<Product>) this.productFrontend.getAvailableProductsIterator();
-               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
-                       throw new ServletException(ex);
-               }
+               // Ask frontend for a list of products
+               return (Iterator<Product>) this.productFrontend.getAvailableProductsIterator();
        }
 
        @Override
        @SuppressWarnings ("unchecked")
-       public Iterator<Product> getAllProductsIterator () throws ServletException {
+       public Iterator<Product> getAllProductsIterator () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                // Trace message
                this.getLogger().trace("CALLED!"); //NOI18N
 
@@ -194,17 +172,13 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                        throw new NullPointerException("productFrontend is null"); //NOI18N
                }
 
-               try {
-                       // Ask frontend for a list of products
-                       return (Iterator<Product>) this.productFrontend.getAllProductsIterator();
-               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
-                       throw new ServletException(ex);
-               }
+               // Ask frontend for a list of products
+               return (Iterator<Product>) this.productFrontend.getAllProductsIterator();
        }
 
        @Override
        @SuppressWarnings ("unchecked")
-       public Iterator<Category> getAllCategoriesIterator () throws ServletException {
+       public Iterator<Category> getAllCategoriesIterator () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                // Trace message
                this.getLogger().trace("CALLED!"); //NOI18N
 
@@ -214,12 +188,8 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                        throw new NullPointerException("categoryFrontend is null"); //NOI18N
                }
 
-               try {
-                       // Ask frontend for a list of categories
-                       return (Iterator<Category>) this.categoryFrontend.getAllCategoriesIterator();
-               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
-                       throw new ServletException(ex);
-               }
+               // Ask frontend for a list of categories
+               return (Iterator<Category>) this.categoryFrontend.getAllCategoriesIterator();
        }
 
        /**
@@ -273,7 +243,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
        }
 
        @Override
-       public void doAdminAddCategory (final ServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException {
+       public void doAdminAddCategory (final ServletRequest request) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException {
                // Trace message
                this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N
 
@@ -310,30 +280,21 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                        }
                }
 
-               try {
-                       // Try to check if title is used already
-                       if (this.isCategoryTitleUsed(title)) {
-                               // Title already used
-                               throw new CategoryTitleAlreadyUsedException(request);
-                       }
-               } catch (final IOException | SQLException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
-                       throw new ServletException(ex);
+               // Try to check if title is used already
+               if (this.isCategoryTitleUsed(title)) {
+                       // Title already used
+                       throw new CategoryTitleAlreadyUsedException(request);
                }
 
-               try {
-                       // The category is not found, so add it to database
-                       this.categoryFrontend.addCategory(title, id);
-               } catch (final SQLException | IOException ex) {
-                       // Continue to throw it
-                       throw new ServletException(ex);
-               }
+               // The category is not found, so add it to database
+               this.categoryFrontend.addCategory(title, id);
 
                // Trace message
                this.getLogger().trace("EXIT!"); //NOI18N
        }
 
        @Override
-       public void doAdminAddProduct (final ServletRequest request) throws ServletException, ProductTitleAlreadyUsedException {
+       public void doAdminAddProduct (final ServletRequest request) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException {
                // Trace message
                this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N
 
@@ -398,31 +359,21 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                // Parse boolean
                Boolean a = Boolean.parseBoolean(available);
 
-               // Test on product title
-               try {
-                       // Try to check if title is used already
-                       if (this.isProductTitleUsed(title)) {
-                               // Title already used
-                               throw new ProductTitleAlreadyUsedException(request);
-                       }
-               } catch (final IOException | SQLException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
-                       throw new ServletException(ex);
+               // Try to check if title is used already
+               if (this.isProductTitleUsed(title)) {
+                       // Title already used
+                       throw new ProductTitleAlreadyUsedException(request);
                }
 
-               try {
-                       // The product is not found, so add it to database
-                       this.productFrontend.addProduct(title, p, id, a);
-               } catch (final SQLException | IOException ex) {
-                       // Continue to throw it
-                       throw new ServletException(ex);
-               }
+               // The product is not found, so add it to database
+               this.productFrontend.addProduct(title, p, id, a);
 
                // Trace message
                this.getLogger().trace("EXIT!"); //NOI18N
        }
 
        @Override
-       public String getPrintableProduktCategory (final Product product) throws ServletException {
+       public String getPrintableProductCategory (final Product product) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                // Trace message
                this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N
 
@@ -435,24 +386,14 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                // Declare category
                Category category;
 
-               try {
-                       // Get Category instance from product over the frontend
-                       category = this.categoryFrontend.getCategory(product);
-               } catch (final IOException | SQLException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
-                       throw new ServletException(ex);
-               }
+               // Get Category instance from product over the frontend
+               category = this.categoryFrontend.getCategory(product);
 
                // Debug message
                this.getLogger().debug(MessageFormat.format("categoryId={0}", category)); //NOI18N
 
-               String title = null;
-               try {
-                       // Now get title from it and return it
-                       title = category.getDecodedTitle();
-               } catch (final UnsupportedEncodingException ex) {
-                       // Continue to throw as cause
-                       throw new ServletException(ex);
-               }
+               // Get decoded title
+               String title = category.getDecodedTitle();
 
                // Trace message
                this.getLogger().trace(MessageFormat.format("title={0} - EXIT!", title)); //NOI18N
@@ -504,7 +445,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
        }
 
        @Override
-       public void doAdminHandleProductForms (final ServletRequest request, final ServletResponse response) throws ServletException {
+       public void doAdminHandleProductForms (final ServletRequest request, final ServletResponse response) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException {
                // Trace message
                this.getLogger().trace(MessageFormat.format("request={0},response={1} - CALLED!", request, response)); //NOI18N
 
@@ -517,38 +458,32 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                        throw new NullPointerException("response is null"); //NOI18N
                }
 
-               // Try this operations
-               try {
-                       // Is it post?
-                       if ("POST".equals(((HttpServletRequest) request).getMethod())) { //NOI18N
-                               // Is "add/edit/delete" set?
-                               if (request.getParameter("add") != null) { //NOI18N
-                                       // Is it already added?
-                                       if (this.isProductTitleUsed(request)) {
-                                               // Debug message
-                                               this.getLogger().debug("Already used, redirecting ..."); //NOI18N
-
-                                               // Already added, so redirect here, else a ServletException will be thrown
-                                               ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/product.jsp?already=1", ((HttpServletRequest) request).getContextPath())); //NOI18N
-                                       } else {
-                                               // Add new product
-                                               this.doAdminAddProduct(request);
-
-                                               // Redirect to proper URL
-                                               ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/product.jsp?added=1", ((HttpServletRequest) request).getContextPath())); //NOI18N
-                                       }
-                               } else if (request.getParameter("edit") != null) { //NOI18N
-                                       // TODO
-                               } else if (request.getParameter("delete") != null) { //NOI18N
-                                       // TODO
-                               }
+               // Is it post?
+               if ("POST".equals(((HttpServletRequest) request).getMethod())) { //NOI18N
+                       // Is "add/edit/delete" set?
+                       if (request.getParameter("add") != null) { //NOI18N
+                               // Is it already added?
+                               if (this.isProductTitleUsed(request)) {
+                                       // Debug message
+                                       this.getLogger().debug("Already used, redirecting ..."); //NOI18N
 
-                               // Request not handled
-                               throw new ServletException("request not handled."); //NOI18N
+                                       // Already added, so redirect here, else a ServletException will be thrown
+                                       ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/product.jsp?already=1", ((HttpServletRequest) request).getContextPath())); //NOI18N
+                               } else {
+                                       // Add new product
+                                       this.doAdminAddProduct(request);
+
+                                       // Redirect to proper URL
+                                       ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/product.jsp?added=1", ((HttpServletRequest) request).getContextPath())); //NOI18N
+                               }
+                       } else if (request.getParameter("edit") != null) { //NOI18N
+                               // TODO
+                       } else if (request.getParameter("delete") != null) { //NOI18N
+                               // TODO
                        }
-               } catch (final IOException | SQLException | BadTokenException | CorruptedDatabaseFileException | ProductTitleAlreadyUsedException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | IllegalArgumentException ex) {
-                       // Throw it as cause
-                       throw new ServletException(ex);
+
+                       // Request not handled
+                       throw new IllegalArgumentException("request not handled."); //NOI18N
                }
 
                // Trace message
@@ -556,7 +491,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
        }
 
        @Override
-       public void doAdminHandleCategoryForms (final ServletRequest request, final ServletResponse response) throws ServletException {
+       public void doAdminHandleCategoryForms (final ServletRequest request, final ServletResponse response) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException {
                // Trace message
                this.getLogger().trace(MessageFormat.format("request={0},response={1} - CALLED!", request, response)); //NOI18N
 
@@ -569,38 +504,32 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                        throw new NullPointerException("response is null"); //NOI18N
                }
 
-               // Try this operations
-               try {
-                       // Is it post?
-                       if ("POST".equals(((HttpServletRequest) request).getMethod())) { //NOI18N
-                               // Is "add/edit/delete" set?
-                               if (request.getParameter("add") != null) { //NOI18N
-                                       // Is the category title already used?
-                                       if (this.isCategoryTitleUsed(request)) {
-                                               // Debug message
-                                               this.getLogger().debug("Already used, redirecting ..."); //NOI18N
-
-                                               // Already added, so redirect here, else a ServletException will be thrown
-                                               ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/category.jsp?already=1", ((HttpServletRequest) request).getContextPath())); //NOI18N
-                                       } else {
-                                               // Add new category
-                                               this.doAdminAddCategory(request);
-
-                                               // Redirect to proper URL
-                                               ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/category.jsp?added=1", ((HttpServletRequest) request).getContextPath())); //NOI18N
-                                       }
-                               } else if (request.getParameter("edit") != null) { //NOI18N
-                                       // TODO
-                               } else if (request.getParameter("delete") != null) { //NOI18N
-                                       // TODO
-                               }
+               // Is it post?
+               if ("POST".equals(((HttpServletRequest) request).getMethod())) { //NOI18N
+                       // Is "add/edit/delete" set?
+                       if (request.getParameter("add") != null) { //NOI18N
+                               // Is the category title already used?
+                               if (this.isCategoryTitleUsed(request)) {
+                                       // Debug message
+                                       this.getLogger().debug("Already used, redirecting ..."); //NOI18N
 
-                               // Request not handled
-                               throw new ServletException("request not handled."); //NOI18N
+                                       // Already added, so redirect here, else a ServletException will be thrown
+                                       ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/category.jsp?already=1", ((HttpServletRequest) request).getContextPath())); //NOI18N
+                               } else {
+                                       // Add new category
+                                       this.doAdminAddCategory(request);
+
+                                       // Redirect to proper URL
+                                       ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/category.jsp?added=1", ((HttpServletRequest) request).getContextPath())); //NOI18N
+                               }
+                       } else if (request.getParameter("edit") != null) { //NOI18N
+                               // TODO
+                       } else if (request.getParameter("delete") != null) { //NOI18N
+                               // TODO
                        }
-               } catch (final IOException | SQLException | BadTokenException | CorruptedDatabaseFileException | CategoryTitleAlreadyUsedException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | IllegalArgumentException ex) {
-                       // Throw it as cause
-                       throw new ServletException(ex);
+
+                       // Request not handled
+                       throw new IllegalArgumentException("request not handled."); //NOI18N
                }
 
                // Trace message
@@ -650,7 +579,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
        }
 
        @Override
-       public Product getProduct (final AddableBasketItem item) throws ServletException {
+       public Product getProduct (final AddableBasketItem item) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                // Trace message
                this.getLogger().trace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N
 
@@ -664,15 +593,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                }
 
                // Init product instance
-               Product product = null;
-
-               try {
-                       // Call frontend
-                       product = this.productFrontend.getProduct(item);
-               } catch (final SQLException | IOException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
-                       // Continue to throw
-                       throw new ServletException(ex);
-               }
+               Product product = this.productFrontend.getProduct(item);
 
                // Trace message
                this.getLogger().trace(MessageFormat.format("product={0} - EXIT!", product)); //NOI18N //NOI18N
index 85347b39a1a21f768154a8857c07b2263b63698e..026c6ae931b7246492dbf2cfea629ff7acb91da1 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.pizzaapplication.beans.controller;
 
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
 import java.sql.SQLException;
 import java.text.MessageFormat;
 import java.util.Deque;
@@ -27,8 +28,8 @@ import javax.faces.FacesException;
 import javax.inject.Named;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
-import javax.servlet.http.HttpSession;
 import org.mxchange.jcore.exceptions.BadTokenException;
+import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
 import org.mxchange.jshop.beans.BaseFrameworkBean;
 import org.mxchange.jshop.category.Category;
@@ -101,62 +102,122 @@ public class PizzaServiceBean extends BaseFrameworkBean implements PizzaBean {
 
        @Override
        public Iterator<Product> getAvailableProductsIterator () throws ServletException {
-               return this.app.getAvailableProductsIterator();
+               try {
+                       return this.app.getAvailableProductsIterator();
+               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+                       // Continue to throw
+                       throw new ServletException(ex);
+               }
        }
 
        @Override
        public Iterator<Product> getAllProductsIterator () throws ServletException {
-               return this.app.getAllProductsIterator();
+               try {
+                       return this.app.getAllProductsIterator();
+               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+                       // Continue to throw
+                       throw new ServletException(ex);
+               }
        }
 
        @Override
        public Deque<Product> getAvailableProducts () throws ServletException {
-               return this.app.getAvailableProducts();
+               try {
+                       return this.app.getAvailableProducts();
+               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+                       // Continue to throw
+                       throw new ServletException(ex);
+               }
        }
 
        @Override
        public Deque<Product> getAllProducts () throws ServletException {
-               return this.app.getAllProducts();
+               try {
+                       return this.app.getAllProducts();
+               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+                       // Continue to throw
+                       throw new ServletException(ex);
+               }
        }
 
        @Override
        public Iterator<Category> getAllCategoriesIterator () throws ServletException {
-               return this.app.getAllCategoriesIterator();
+               try {
+                       return this.app.getAllCategoriesIterator();
+               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+                       // Continue to throw
+                       throw new ServletException(ex);
+               }
        }
 
        @Override
        public Deque<Category> getAllCategories () throws ServletException {
-               return this.app.getAllCategories();
+               try {
+                       return this.app.getAllCategories();
+               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+                       // Continue to throw
+                       throw new ServletException(ex);
+               }
        }
 
        @Override
        public void doAdminAddCategory (final ServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException {
-               this.app.doAdminAddCategory(request);
+               try {
+                       this.app.doAdminAddCategory(request);
+               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+                       // Continue to throw
+                       throw new ServletException(ex);
+               }
        }
 
        @Override
        public void doAdminAddProduct (final ServletRequest request) throws ServletException, ProductTitleAlreadyUsedException {
-               this.app.doAdminAddProduct(request);
+               try {
+                       this.app.doAdminAddProduct(request);
+               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+                       // Continue to throw
+                       throw new ServletException(ex);
+               }
        }
 
        @Override
        public String getPrintableProduktCategory (final Product product) throws ServletException {
-               return this.app.getPrintableProduktCategory(product);
+               try {
+                       return this.app.getPrintableProductCategory(product);
+               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+                       // Continue to throw
+                       throw new ServletException(ex);
+               }
        }
 
        @Override
        public void doAdminHandleProductForms () throws ServletException {
-               this.app.doAdminHandleProductForms(this.getRequest(), this.getResponse());
+               try {
+                       this.app.doAdminHandleProductForms(this.getRequest(), this.getResponse());
+               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | ProductTitleAlreadyUsedException ex) {
+                       // Continue to throw
+                       throw new ServletException(ex);
+               }
        }
 
        @Override
        public void doAdminHandleCategoryForms () throws ServletException {
-               this.app.doAdminHandleCategoryForms(this.getRequest(), this.getResponse());
+               try {
+                       this.app.doAdminHandleCategoryForms(this.getRequest(), this.getResponse());
+               } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | CategoryTitleAlreadyUsedException ex) {
+                       // Continue to throw
+                       throw new ServletException(ex);
+               }
        }
 
        @Override
        public Product getProduct (final AddableBasketItem item) throws ServletException {
-               // Deligate to application
-               return this.app.getProduct(item);
+               try {
+                       // Deligate to application
+                       return this.app.getProduct(item);
+               } catch (IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+                       // Continue to throw
+                       throw new ServletException(ex);
+               }
        }
 }