2 * Copyright (C) 2015 Roland Haeder
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.
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.
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/>.
17 package org.mxchange.pizzaapplication.beans.controller;
19 import java.io.IOException;
20 import java.rmi.RemoteException;
21 import java.util.Deque;
22 import javax.annotation.PostConstruct;
23 import javax.enterprise.context.SessionScoped;
24 import javax.faces.FacesException;
25 import javax.inject.Named;
26 import javax.naming.InitialContext;
27 import javax.naming.NamingException;
28 import org.mxchange.jcoreee.beans.BaseFrameworkBean;
29 import org.mxchange.jshopcore.exceptions.CategoryTitleAlreadyUsedException;
30 import org.mxchange.jshopcore.exceptions.ProductTitleAlreadyUsedException;
31 import org.mxchange.jshopcore.model.category.Category;
32 import org.mxchange.jshopcore.model.product.Product;
33 import org.mxchange.jshopeelib.beans.remote.shop.ShopSessionBeanRemote;
36 * Main application class
38 * @author Roland Haeder
42 public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBean {
46 private static final long serialVersionUID = 58_137_539_530_279L;
51 private final ShopSessionBeanRemote shop;
56 * @throws javax.naming.NamingException Something happened here?
58 public PizzaServiceWebBean () throws NamingException {
59 // Get initial context
60 InitialContext context = new InitialContext();
62 // Try to lookup the bean
63 this.shop = (ShopSessionBeanRemote) context.lookup("ejb/stateless-shop"); //NOI18N
67 public void init () throws RuntimeException {
68 // Call super init first
73 public Deque<Product> getAvailableProducts () throws FacesException {
75 return this.getShop().getAvailableProducts();
76 } catch (final RemoteException ex) {
78 throw new FacesException(ex);
83 public Deque<Product> getAllProducts () throws FacesException {
85 return this.getShop().getAllProducts();
86 } catch (final RemoteException ex) {
88 throw new FacesException(ex);
93 public Deque<Category> getAllCategories () throws FacesException {
95 return this.getShop().getAllCategories();
96 } catch (final RemoteException ex) {
98 throw new FacesException(ex);
103 public void doAdminAddCategory (final Category category) throws FacesException {
105 this.getShop().doAdminAddCategory(category);
106 } catch (final IOException | CategoryTitleAlreadyUsedException ex) {
108 throw new FacesException(ex);
113 public void doAdminAddProduct (final Product product) throws FacesException {
115 this.getShop().doAdminAddProduct(product);
116 } catch (final IOException | ProductTitleAlreadyUsedException ex) {
118 throw new FacesException(ex);
123 * Getter for shop remote bean
125 * @return Remote shop bean
127 private ShopSessionBeanRemote getShop () {