From ad3a217eb62ab36fab7004786b42e44edc063171 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 24 Aug 2015 11:49:47 +0200 Subject: [PATCH] =?utf8?q?Converted=20private=20constructor=20to=20public?= =?utf8?q?=20init()=20method=20with=20context,=20still=20this=20cannot=20b?= =?utf8?q?e=20converted=20to=20a=20bean=20as=20the=20context=20is=20someho?= =?utf8?q?w=20needed.=20:-(=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../application/PizzaApplication.java | 16 ++++++++++++++++ .../application/PizzaServiceApplication.java | 15 ++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java index a1879ee4..09993d40 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java @@ -16,12 +16,17 @@ */ package org.mxchange.pizzaapplication.application; +import java.io.IOException; +import java.sql.SQLException; import java.util.Iterator; +import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.mxchange.jcore.application.Application; +import org.mxchange.jcore.exceptions.BadTokenException; +import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; import org.mxchange.pizzaapplication.category.Category; import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException; import org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException; @@ -108,6 +113,17 @@ public interface PizzaApplication extends Application { */ public float getTotalPositionPriceFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session); + /** + * Initializes this instance with given ServletContext + * + * @param context Servlet context + * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the backend is unsupported + * @throws java.sql.SQLException If an 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 void init (final ServletContext context) throws UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException; + /** * Checks whether the given product is choosen, request overules session. * diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index f97bad78..d8253814 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -95,17 +95,18 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P instance = (PizzaApplication) object; // Debug message - instance.getLogger().debug(MessageFormat.format("Using existing instance {0} ...", object)); + instance.getLogger().debug(MessageFormat.format("Using existing instance {0} ...", object)); //NOI18N } else if (object instanceof Object) { // Not correct instance throw new ServletException("app is not set correctly"); //NOI18N } else { try { // "service" is null, so initialize it - instance = new PizzaServiceApplication(context); + instance = new PizzaServiceApplication(); + instance.init(context); // Debug message - instance.getLogger().debug(MessageFormat.format("Created new instance {0} ...", object)); + instance.getLogger().debug(MessageFormat.format("Created new instance {0} ...", object)); //NOI18N } catch (final UnsupportedDatabaseBackendException | SQLException | IOException | BadTokenException ex) { throw new ServletException(ex); } @@ -131,12 +132,8 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P new PizzaServiceApplication().start(); } - /** - * Constructor with servet configuration - * - * @param context Servlet context - */ - private PizzaServiceApplication (final ServletContext context) throws UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException { + @Override + public void init (final ServletContext context) throws UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException { // Temporary initialize default bundle // @TODO The JSF may have better internatialization support this.initBundle(); -- 2.39.5