]> git.mxchange.org Git - pizzaservice-core.git/blob
6a7a6f23ce5eb1bbfcca06a1c0e839769dae7b76
[pizzaservice-core.git] /
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.pizzaapplication.beans.pizzaservice;
18
19 import java.io.IOException;
20 import java.lang.reflect.InvocationTargetException;
21 import java.sql.SQLException;
22 import java.text.MessageFormat;
23 import java.util.Deque;
24 import javax.annotation.PostConstruct;
25 import javax.ejb.Stateless;
26 import javax.faces.FacesException;
27 import javax.inject.Named;
28 import javax.servlet.ServletException;
29 import org.mxchange.jcore.exceptions.BadTokenException;
30 import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
31 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
32 import org.mxchange.jshop.beans.BaseFrameworkBean;
33 import org.mxchange.jshop.beans.shop.ShopSessionBeanRemote;
34 import org.mxchange.jshop.category.Category;
35 import org.mxchange.jshop.product.Product;
36 import org.mxchange.pizzaapplication.application.PizzaApplication;
37 import org.mxchange.pizzaapplication.application.PizzaServiceApplication;
38
39 /**
40  * The session bean
41  *
42  * @author Roland Haeder
43  */
44 @Named ("shop")
45 @Stateless
46 public class PizzaServiceSessionBean extends BaseFrameworkBean implements ShopSessionBeanRemote {
47
48         /**
49          * Serial number
50          */
51         private static final long serialVersionUID = 578314942948L;
52
53         /**
54          * Application instance
55          */
56         private final PizzaApplication app;
57
58         /**
59          * Initializer block
60          */
61         {
62                 // Get new application instance
63                 this.getLogger().debug("INITIALIZER!"); //NOI18N
64                 this.app = new PizzaServiceApplication();
65         }
66
67         /**
68          * Default constructor
69          */
70         public PizzaServiceSessionBean () {
71                 this.getLogger().trace("CALLED!"); //NOI18N
72         }
73
74         @PostConstruct
75         public void init () throws FacesException {
76                 // Trace message
77                 this.getLogger().trace(MessageFormat.format("application={0} - CALLED!", this.getApplication())); //NOI18N
78
79                 // Must not be null
80                 if (this.getApplication() == null) {
81                         // Abort here
82                         throw new NullPointerException("application is null"); //NOI18N
83                 }
84
85                 try {
86                         // Call init method
87                         this.app.init(this.getApplication());
88                 } catch (final UnsupportedDatabaseBackendException | SQLException | IOException | BadTokenException ex) {
89                         // Continue to throw
90                         throw new FacesException(ex);
91                 }
92         }
93
94         @Override
95         public Deque<Product> getAvailableProducts () throws ServletException {
96                 try {
97                         return this.app.getAvailableProducts();
98                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
99                         // Continue to throw
100                         throw new ServletException(ex);
101                 }
102         }
103
104         @Override
105         public Deque<Product> getAllProducts () throws ServletException {
106                 try {
107                         return this.app.getAllProducts();
108                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
109                         // Continue to throw
110                         throw new ServletException(ex);
111                 }
112         }
113
114         @Override
115         public Deque<Category> getAllCategories () throws ServletException {
116                 try {
117                         return this.app.getAllCategories();
118                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
119                         // Continue to throw
120                         throw new ServletException(ex);
121                 }
122         }
123 }