]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebBean.java
5ab300db26f54ac9e0460243abdff751d66d1b5a
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / product / AdminProductWebBean.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.product;
18
19 import java.rmi.RemoteException;
20 import java.util.Deque;
21 import javax.enterprise.context.SessionScoped;
22 import javax.faces.view.facelets.FaceletException;
23 import javax.inject.Named;
24 import javax.naming.InitialContext;
25 import javax.naming.NamingException;
26 import org.mxchange.jcoreee.beans.BaseFrameworkBean;
27 import org.mxchange.jshopcore.exceptions.ProductTitleAlreadyUsedException;
28 import org.mxchange.jshopcore.model.product.Product;
29 import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote;
30
31 /**
32  * Main application class
33  *
34  * @author Roland Haeder
35  */
36 @Named("admin_product")
37 @SessionScoped
38 public class AdminProductWebBean extends BaseFrameworkBean implements AdminProductWebController {
39         /**
40          * Serial id
41          */
42         private static final long serialVersionUID = 5_819_375_183_472_871L;
43
44         /**
45          * Remote bean for products
46          */
47         private final ProductSessionBeanRemote product;
48
49         /**
50          * Default constructor
51          * 
52          * @throws javax.naming.NamingException Something happened here?
53          */
54         public AdminProductWebBean () throws NamingException {
55                 // Get initial context
56                 InitialContext context = new InitialContext();
57
58                 // Try to lookup the bean
59                 this.product = (ProductSessionBeanRemote) context.lookup("ejb/stateless-product"); //NOI18N
60         }
61
62         @Override
63         public void doAdminAddProduct (final Product product) throws FaceletException {
64                 try {
65                         // Call bean
66                         this.product.doAdminAddProduct(product);
67                 } catch (final ProductTitleAlreadyUsedException ex) {
68                         // Continue to throw
69                         throw new FaceletException(ex);
70                 }
71         }
72
73         @Override
74         public Deque<Product> getAllProducts () throws FaceletException {
75                 try {
76                         // Call bean
77                         return this.product.getAllProducts();
78                 } catch (final RemoteException ex) {
79                         // Continue to throw
80                         throw new FaceletException(ex);
81                 }
82         }
83 }