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.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;
37 * Main application class
39 * @author Roland Haeder
43 public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBean {
47 private static final long serialVersionUID = 58_137_539_530_279L;
50 * Remote bean for categories
52 private final CategorySessionBeanRemote category;
55 * Remote bean for products
57 private final ProductSessionBeanRemote product;
62 * @throws javax.naming.NamingException Something happened here?
64 public PizzaServiceWebBean () throws NamingException {
65 // Get initial context
66 InitialContext context = new InitialContext();
68 // Try to lookup the bean
69 this.category = (CategorySessionBeanRemote) context.lookup("ejb/stateless-category"); //NOI18N
71 // Try to lookup the bean
72 this.product = (ProductSessionBeanRemote) context.lookup("ejb/stateless-product"); //NOI18N
76 public void init () throws RuntimeException {
77 // Call super init first
82 public Queue<Product> getAvailableProducts () throws FacesException {
84 return this.getProduct().getAvailableProducts();
85 } catch (final RemoteException ex) {
87 throw new FacesException(ex);
92 public Queue<Category> getAllCategories () throws FacesException {
95 Category c = new ProductCategory(0L, "Ist oberste Kategorie", 0L);
98 Deque<Category> deque = this.getCategory().getAllCategories();
105 } catch (final SQLException ex) {
107 throw new FacesException(ex);
112 * Getter for shop remote bean
114 * @return Remote shop bean
116 private CategorySessionBeanRemote getCategory () {
117 return this.category;
121 * Getter for shop remote bean
123 * @return Remote shop bean
125 private ProductSessionBeanRemote getProduct () {