]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java
fixed imports
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / controller / PizzaServiceWebBean.java
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.controller;
18
19 import java.io.IOException;
20 import java.lang.reflect.InvocationTargetException;
21 import java.rmi.RemoteException;
22 import java.sql.SQLException;
23 import java.util.Deque;
24 import java.util.Iterator;
25 import javax.annotation.PostConstruct;
26 import javax.enterprise.context.SessionScoped;
27 import javax.faces.FacesException;
28 import javax.inject.Named;
29 import javax.naming.InitialContext;
30 import javax.naming.NamingException;
31 import org.mxchange.jcoreee.beans.BaseFrameworkBean;
32 import org.mxchange.jshopcore.exceptions.CategoryTitleAlreadyUsedException;
33 import org.mxchange.jshopcore.exceptions.ProductTitleAlreadyUsedException;
34 import org.mxchange.jshopcore.model.category.Category;
35 import org.mxchange.jshopcore.model.product.Product;
36 import org.mxchange.jshopeelib.beans.remote.shop.ShopSessionBeanRemote;
37
38 /**
39  * Main application class
40  *
41  * @author Roland Haeder
42  */
43 @Named("controller")
44 @SessionScoped
45 public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBean {
46         /**
47          * Serial id
48          */
49         private static final long serialVersionUID = 58137539530279L;
50
51         /**
52          * Remote bean
53          */
54         private final ShopSessionBeanRemote remote;
55
56         /**
57          * Initializer block
58          */
59         {
60                 // Get new application instance
61                 this.getLogger().debug("INITIALIZER!"); //NOI18N
62         }
63
64         /**
65          * Default constructor
66          * 
67          * @throws javax.naming.NamingException Something happened here?
68          */
69         public PizzaServiceWebBean () throws NamingException {
70                 this.getLogger().trace("CALLED!"); //NOI18N
71
72                 // Get initial context
73                 InitialContext context = new InitialContext();
74
75                 // Try to lookup the bean
76                 this.remote = (ShopSessionBeanRemote) context.lookup("ejb/stateless-shop");
77         }
78
79         @Override
80         @PostConstruct
81         public void init () throws FacesException {
82                 // Trace message
83                 this.getLogger().trace("CALLED!"); //NOI18N
84
85                 // Super call
86                 super.init();
87         }
88
89         @Override
90         public Iterator<Product> getAvailableProductsIterator () throws RemoteException {
91                 try {
92                         return this.remote.getAvailableProductsIterator();
93                 } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
94                         // Continue to throw
95                         throw new RemoteException("getAvailableProductsIterator() failed", ex);
96                 }
97         }
98
99         @Override
100         public Iterator<Product> getAllProductsIterator () throws RemoteException {
101                 try {
102                         return this.remote.getAllProductsIterator();
103                 } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
104                         // Continue to throw
105                         throw new RemoteException("getAllProductsIterator() failed.", ex);
106                 }
107         }
108
109         @Override
110         public Deque<Product> getAvailableProducts () throws RemoteException {
111                 try {
112                         return this.remote.getAvailableProducts();
113                 } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
114                         // Continue to throw
115                         throw new RemoteException("getAvailableProducts() failed.", ex);
116                 }
117         }
118
119         @Override
120         public Deque<Product> getAllProducts () throws RemoteException {
121                 try {
122                         return this.remote.getAllProducts();
123                 } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
124                         // Continue to throw
125                         throw new RemoteException("getAllProducts() failed", ex);
126                 }
127         }
128
129         @Override
130         public Iterator<Category> getAllCategoriesIterator () throws RemoteException {
131                 try {
132                         return this.remote.getAllCategoriesIterator();
133                 } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
134                         // Continue to throw
135                         throw new RemoteException("getAllCategoriesIterator() failed.", ex);
136                 }
137         }
138
139         @Override
140         public Deque<Category> getAllCategories () throws RemoteException {
141                 try {
142                         return this.remote.getAllCategories();
143                 } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
144                         // Continue to throw
145                         throw new RemoteException("getAllCategories() failed.", ex);
146                 }
147         }
148
149         @Override
150         public void doAdminAddCategory (final Category category) throws RemoteException, CategoryTitleAlreadyUsedException {
151                 try {
152                         this.remote.doAdminAddCategory(category);
153                 } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
154                         // Continue to throw
155                         throw new RemoteException("doAdminAddCategory() failed.", ex);
156                 }
157         }
158
159         @Override
160         public void doAdminAddProduct (final Product product) throws RemoteException, ProductTitleAlreadyUsedException {
161                 try {
162                         this.remote.doAdminAddProduct(product);
163                 } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
164                         // Continue to throw
165                         throw new RemoteException("doAdminAddProduct() failed.", ex);
166                 }
167         }
168 }