2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (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 Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.pizzaapplication.beans.product;
19 import java.util.Collections;
20 import java.util.List;
21 import javax.annotation.PostConstruct;
22 import javax.enterprise.context.ApplicationScoped;
23 import javax.enterprise.event.Observes;
24 import javax.faces.FacesException;
25 import javax.inject.Named;
26 import javax.naming.Context;
27 import javax.naming.InitialContext;
28 import javax.naming.NamingException;
29 import org.mxchange.jshopcore.events.product.AddedProductEvent;
30 import org.mxchange.jshopcore.model.product.Product;
31 import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote;
34 * General product controller
36 * @author Roland Haeder<roland@mxchange.org>
38 @Named ("productController")
40 public class PizzaProductWebApplicationBean implements PizzaProductWebApplicationController {
45 private static final long serialVersionUID = 58_137_539_530_279L;
48 * "Cache" for all available products
50 private List<Product> availableProducts;
53 public void addProduct (final Product product) {
54 // Is the product available?
55 if (product.getProductAvailability()) {
57 this.availableProducts.add(product);
62 public void afterShopProductAdded (@Observes final AddedProductEvent event) {
64 this.addProduct(event.getAddedProduct());
68 public List<Product> getAvailableProducts () throws FacesException {
70 return Collections.unmodifiableList(this.availableProducts);
74 * Initialization of this bean
79 // Get initial context
80 Context context = new InitialContext();
82 // Try to lookup the bean
83 ProductSessionBeanRemote productBean = (ProductSessionBeanRemote) context.lookup("java:global/jshop-ejb/product!org.mxchange.jshopcore.model.product.ProductSessionBeanRemote"); //NOI18N
85 // Get available products list
86 this.availableProducts = productBean.getAvailableProducts();
87 } catch (final NamingException e) {
89 throw new FacesException(e);