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.country;
19 import java.util.Collections;
20 import java.util.List;
21 import javax.annotation.PostConstruct;
22 import javax.enterprise.context.ApplicationScoped;
23 import javax.faces.view.facelets.FaceletException;
24 import javax.inject.Named;
25 import javax.naming.Context;
26 import javax.naming.InitialContext;
27 import javax.naming.NamingException;
28 import org.mxchange.jcountry.data.Country;
29 import org.mxchange.jcountry.data.CountrySingletonBeanRemote;
34 * @author Roland Haeder<roland@mxchange.org>
38 public class PizzaCountryWebApplicationBean implements PizzaCountryWebApplicationController {
43 private static final long serialVersionUID = 176_985_298_681_742_960L;
48 private CountrySingletonBeanRemote countryBean;
51 * List of all countries
53 private List<Country> countryList;
58 public PizzaCountryWebApplicationBean () {
61 // Get initial context
62 Context context = new InitialContext();
64 // Try to lookup the bean
65 this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/addressbook-ejb/country!org.mxchange.jcountry.data.AddressbookCountrySingletonBeanLocal"); //NOI18N
66 } catch (final NamingException ex) {
68 throw new FaceletException(ex);
73 public List<Country> allCountries () {
74 // Return "cached" version
75 return Collections.unmodifiableList(this.countryList);
79 * Post-initialization of this class
83 // "Cache" country list as this will not change so often.
84 this.countryList = this.countryBean.allCountries();