]> git.mxchange.org Git - addressbook-war.git/blob - src/java/org/mxchange/addressbook/beans/mobileprovider/AddressbookMobileProviderWebApplicationBean.java
9211957a08c4a33afd9d878fcb790310858b1296
[addressbook-war.git] / src / java / org / mxchange / addressbook / beans / mobileprovider / AddressbookMobileProviderWebApplicationBean.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.addressbook.beans.mobileprovider;
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.jphone.phonenumbers.mobileprovider.MobileProvider;
29 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote;
30
31 /**
32  * A SMS provider bean
33  * <p>
34  * @author Roland Haeder<roland@mxchange.org>
35  */
36 @Named ("cellphone")
37 @ApplicationScoped
38 public class AddressbookMobileProviderWebApplicationBean implements AddressbookMobileProviderWebApplicationController {
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 MobileProviderSingletonBeanRemote cellphoneBean;
49
50         /**
51          * List of all countries
52          */
53         private List<MobileProvider> cellphoneList;
54
55         /**
56          * Default constructor
57          */
58         public AddressbookMobileProviderWebApplicationBean () {
59                 // Try this
60                 try {
61                         // Get initial context
62                         Context context = new InitialContext();
63
64                         // Try to lookup the bean
65                         this.cellphoneBean = (MobileProviderSingletonBeanRemote) context.lookup("java:global/addressbook-ejb/MobileProvider!org.mxchange.jphone.phonenumbers.MobileProvider.MobileProviderSingletonBeanRemote"); //NOI18N
66                 } catch (final NamingException ex) {
67                         // Continue to throw
68                         throw new FaceletException(ex);
69                 }
70         }
71
72         @Override
73         public List<MobileProvider> allMobileProvider () {
74                 // Return "cached" version
75                 return Collections.unmodifiableList(this.cellphoneList);
76         }
77
78         /**
79          * Post-initialization of this class
80          */
81         @PostConstruct
82         public void init () {
83                 this.cellphoneList = this.cellphoneBean.allMobileProvider();
84         }
85 }