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