]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java
updated jcore-ee-logger.jar, jshop-ee-lib.jar + added some stuff + renamed variable...
[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.rmi.RemoteException;
20 import java.sql.SQLException;
21 import java.util.Deque;
22 import java.util.Queue;
23 import javax.annotation.PostConstruct;
24 import javax.enterprise.context.SessionScoped;
25 import javax.faces.FacesException;
26 import javax.inject.Named;
27 import javax.naming.InitialContext;
28 import javax.naming.NamingException;
29 import org.mxchange.jcoreee.beans.BaseFrameworkBean;
30 import org.mxchange.jshopcore.model.category.Category;
31 import org.mxchange.jshopcore.model.category.CategorySessionBeanRemote;
32 import org.mxchange.jshopcore.model.category.ProductCategory;
33 import org.mxchange.jshopcore.model.product.Product;
34 import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote;
35
36 /**
37  * Main application class
38  *
39  * @author Roland Haeder
40  */
41 @Named("controller")
42 @SessionScoped
43 public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBean {
44         /**
45          * Serial id
46          */
47         private static final long serialVersionUID = 58_137_539_530_279L;
48
49         /**
50          * Remote bean for categories
51          */
52         private final CategorySessionBeanRemote category;
53
54         /**
55          * Remote bean for products
56          */
57         private final ProductSessionBeanRemote product;
58
59         /**
60          * Default constructor
61          * 
62          * @throws javax.naming.NamingException Something happened here?
63          */
64         public PizzaServiceWebBean () throws NamingException {
65                 // Get initial context
66                 InitialContext context = new InitialContext();
67
68                 // Try to lookup the bean
69                 this.category = (CategorySessionBeanRemote) context.lookup("ejb/stateless-category"); //NOI18N
70
71                 // Try to lookup the bean
72                 this.product = (ProductSessionBeanRemote) context.lookup("ejb/stateless-product"); //NOI18N
73         }
74
75         @PostConstruct
76         public void init () throws RuntimeException {
77                 // Call super init first
78                 super.genericInit();
79         }
80
81         @Override
82         public Queue<Product> getAvailableProducts () throws FacesException {
83                 try {
84                         return this.getProduct().getAvailableProducts();
85                 } catch (final RemoteException ex) {
86                         // Continue to throw
87                         throw new FacesException(ex);
88                 }
89         }
90
91         @Override
92         public Queue<Category> getAllCategories () throws FacesException {
93                 try {
94                         // Fake zero category
95                         Category c = new ProductCategory(0L, "Ist oberste Kategorie", 0L);
96
97                         // Get List back
98                         Deque<Category> deque = this.getCategory().getAllCategories();
99
100                         // Add fake category
101                         deque.addFirst(c);
102
103                         // Return it
104                         return deque;
105                 } catch (final SQLException ex) {
106                         // Continue to throw
107                         throw new FacesException(ex);
108                 }
109         }
110
111         /**
112          * Getter for shop remote bean
113          *
114          * @return Remote shop bean
115          */
116         private CategorySessionBeanRemote getCategory () {
117                 return this.category;
118         }
119
120         /**
121          * Getter for shop remote bean
122          *
123          * @return Remote shop bean
124          */
125         private ProductSessionBeanRemote getProduct () {
126                 return this.product;
127         }
128 }