]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/country/CountryWebApplicationBean.java
added comment
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / country / CountryWebApplicationBean.java
1 package org.mxchange.pizzaapplication.beans.country;
2
3 /*
4  * Copyright (C) 2016 Roland Haeder
5  *
6  * This program is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License as published by the Free Software
8  * Foundation, either version 3 of the License, or (at your option) any later
9  * version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program. If not, see <http://www.gnu.org/licenses/>.
18  */
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;
30
31 /**
32  * A country bean
33  * <p>
34  * @author Roland Haeder<roland@mxchange.org>
35  */
36 @Named ("country")
37 @ApplicationScoped
38 public class CountryWebApplicationBean implements CountryWebApplicationController {
39
40         /**
41          * Serial number
42          */
43         private static final long serialVersionUID = 176_985_298_681_742_960L;
44
45         /**
46          * Remote country EJB
47          */
48         private CountrySingletonBeanRemote countryBean;
49
50         /**
51          * List of all countries
52          */
53         private List<Country> countryList;
54
55         /**
56          * Default constructor
57          */
58         public CountryWebApplicationBean () {
59                 // Try this
60                 try {
61                         // Get initial context
62                         Context context = new InitialContext();
63
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) {
67                         // Continue to throw
68                         throw new FaceletException(ex);
69                 }
70         }
71
72         @Override
73         public List<Country> allCountries () {
74                 // Return "cached" version
75                 return Collections.unmodifiableList(this.countryList);
76         }
77
78         /**
79          * Post-initialization of this class
80          */
81         @PostConstruct
82         public void init () {
83                 // "Cache" country list as this will not change so often.
84                 this.countryList = this.countryBean.allCountries();
85         }
86 }