]> git.mxchange.org Git - jfinancials-war.git/blob
5c2c045d593d29c230e6fb077c693118cbfbeb5e
[jfinancials-war.git] /
1 /*
2  * Copyright (C) 2016, 2017 Roland Häder
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.jfinancials.beans.businesscontact;
18
19 import java.util.Collections;
20 import java.util.List;
21 import javax.annotation.PostConstruct;
22 import javax.enterprise.context.SessionScoped;
23 import javax.faces.view.facelets.FaceletException;
24 import javax.inject.Inject;
25 import javax.inject.Named;
26 import javax.naming.Context;
27 import javax.naming.InitialContext;
28 import javax.naming.NamingException;
29 import org.mxchange.jcontactsbusiness.BusinessContact;
30 import org.mxchange.jcontactsbusiness.BusinessContactSessionBeanRemote;
31 import org.mxchange.jfinancials.beans.BaseFinancialsController;
32 import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController;
33
34 /**
35  * A business contact bean (controller)
36  * <p>
37  * @author Roland Häder<roland@mxchange.org>
38  */
39 @Named ("businessContactController")
40 @SessionScoped
41 public class FinancialsBusinessContactWebSessionBean extends BaseFinancialsController implements FinancialsBusinessContactWebSessionController {
42
43         /**
44          * Serial number
45          */
46         private static final long serialVersionUID = 56_189_028_928_371L;
47
48         /**
49          * Remote contact bean
50          */
51         private BusinessContactSessionBeanRemote businessContactBean;
52
53         /**
54          * A list of all registered companies (globally)
55          */
56         private List<BusinessContact> registeredCompanies;
57
58         /**
59          * User instance
60          */
61         @Inject
62         private FinancialsUserLoginWebSessionController userLoginController;
63
64         /**
65          * Constructor
66          */
67         public FinancialsBusinessContactWebSessionBean () {
68                 // Call super constructor
69                 super();
70         }
71
72         @Override
73         public List<BusinessContact> allRegisteredCompanies () {
74                 return Collections.unmodifiableList(this.registeredCompanies);
75         }
76
77         /**
78          * Post-initialization of this class
79          */
80         @PostConstruct
81         public void init () {
82                 // Try it
83                 try {
84                         // Get initial context
85                         Context context = new InitialContext();
86
87                         // Try to lookup
88                         this.businessContactBean = (BusinessContactSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/businessContact!org.mxchange.jcontactsbusiness.BusinessContactSessionBeanRemote"); //NOI18N
89
90                         // Init list
91                         this.registeredCompanies = this.businessContactBean.allBusinessContacts();
92                 } catch (final NamingException e) {
93                         // Throw again
94                         throw new FaceletException(e);
95                 }
96         }
97
98 }