]> git.mxchange.org Git - addressbook-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Tue, 29 Aug 2017 20:32:55 +0000 (22:32 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 29 Aug 2017 20:41:20 +0000 (22:41 +0200)
- rewrote initializeList() a bit to become PostConstruct as the injection is
  already done early
- remote more JNDI lookups from PostConstruct-annotated method to @EJB
  annotation

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebSessionBean.java
src/java/org/mxchange/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebRequestBean.java
src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java
src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebApplicationBean.java
src/java/org/mxchange/addressbook/beans/mobileprovider/AddressbookMobileProviderWebRequestBean.java
src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebApplicationBean.java
src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java
src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java
src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebApplicationBean.java
src/java/org/mxchange/addressbook/beans/user/confirmlink/AddressbookConfirmationLinkWebRequestBean.java
src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebSessionBean.java

index de80c145da716611cd7d17b71aff4bab6af75c19..7ed08ab21f4d230518ddc6671d6dba98d679d9c7 100644 (file)
@@ -19,6 +19,7 @@ package org.mxchange.addressbook.beans.business.basicdata;
 import java.text.MessageFormat;
 import java.util.LinkedList;
 import java.util.List;
+import javax.annotation.PostConstruct;
 import javax.ejb.EJB;
 import javax.enterprise.context.SessionScoped;
 import javax.enterprise.event.Observes;
@@ -153,9 +154,6 @@ public class AddressbookBusinessDataWebSessionBean extends BaseAddressbookContro
                        throw new IllegalArgumentException("event.basicData.companyName is empty");
                }
 
-               // Initialize list
-               this.initializeList();
-
                // Add it to list
                this.businessContacts.add(event.getBasicData());
        }
@@ -167,9 +165,6 @@ public class AddressbookBusinessDataWebSessionBean extends BaseAddressbookContro
         */
        @SuppressWarnings ("ReturnOfCollectionOrArrayField")
        public List<BusinessBasicData> allCompanyBasicData () {
-               // Initialize list
-               this.initializeList();
-
                // Return it
                return this.businessContacts;
        }
@@ -339,12 +334,10 @@ public class AddressbookBusinessDataWebSessionBean extends BaseAddressbookContro
        /**
         * Initializer method
         */
-       private void initializeList () {
-               // Is the list empty?
-               if (this.businessContacts.isEmpty()) {
-                       // Init user's contact list
-                       this.businessContacts.addAll(this.adminBusinessDataBean.allCompanyBasicData());
-               }
+       @PostConstruct
+       public void initializeList () {
+               // Init user's contact list
+               this.businessContacts.addAll(this.adminBusinessDataBean.allCompanyBasicData());
        }
 
 }
index 750b5b3408fdc3a1bcce82c4087c93ae8deea1e4..06c0b2ea8c7f1742fa48f61c4c9c93c80f07b42e 100644 (file)
@@ -19,12 +19,9 @@ package org.mxchange.addressbook.beans.business.employee;
 import java.util.LinkedList;
 import java.util.List;
 import javax.annotation.PostConstruct;
+import javax.ejb.EJB;
 import javax.enterprise.context.SessionScoped;
-import javax.faces.view.facelets.FaceletException;
 import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
 import org.mxchange.jcontactsbusiness.employee.CompanyEmployeeSessionBeanRemote;
 import org.mxchange.jcontactsbusiness.employee.Employee;
@@ -46,6 +43,7 @@ public class AddressbookCompanyEmployeeWebRequestBean extends BaseAddressbookCon
        /**
         * EJB for general company employee purposes
         */
+       @EJB (lookup = "java:global/addressbook-ejb/companyEmployee!org.mxchange.jcontactsbusiness.employee.CompanyEmployeeSessionBeanRemote")
        private CompanyEmployeeSessionBeanRemote companyEmployeeBean;
 
        /**
@@ -79,18 +77,6 @@ public class AddressbookCompanyEmployeeWebRequestBean extends BaseAddressbookCon
         */
        @PostConstruct
        public void init () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.companyEmployeeBean = (CompanyEmployeeSessionBeanRemote) context.lookup("java:global/addressbook-ejb/companyEmployee!org.mxchange.jcontactsbusiness.employee.CompanyEmployeeSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
-
                // Get all entries from remote bean
                List<Employee> employees = this.companyEmployeeBean.allCompanyEmployees();
 
index 754cbbf0ffbd05c95e31275587a6ce338e6bebac..2b4d7c072ed3129fc264dcd32b80eaecd8515998 100644 (file)
@@ -24,14 +24,12 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Objects;
 import javax.annotation.PostConstruct;
+import javax.ejb.EJB;
 import javax.enterprise.context.SessionScoped;
 import javax.enterprise.event.Observes;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
 import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
 import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController;
 import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController;
@@ -95,6 +93,7 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController
        /**
         * EJB for general contact purposes
         */
+       @EJB (lookup = "java:global/addressbook-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote")
        private ContactSessionBeanRemote contactBean;
 
        /**
@@ -1009,18 +1008,6 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController
         */
        @PostConstruct
        public void init () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/addressbook-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
-
                // Get full email address list for reducing EJB calls
                this.emailAddressList.addAll(this.contactBean.getEmailAddressList());
 
index 7b3e31093b1ec4d5af63ccae74797432714cf59d..9a11b0ea0b75e16bbd04fa9648204cf6e1734891 100644 (file)
@@ -19,13 +19,10 @@ package org.mxchange.addressbook.beans.country;
 import java.text.MessageFormat;
 import java.util.List;
 import javax.annotation.PostConstruct;
+import javax.ejb.EJB;
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.event.Observes;
-import javax.faces.view.facelets.FaceletException;
 import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
 import org.mxchange.jcountry.data.Country;
 import org.mxchange.jcountry.data.CountrySingletonBeanRemote;
@@ -48,6 +45,7 @@ public class AddressbookCountryWebApplicationBean extends BaseAddressbookControl
        /**
         * Remote country EJB
         */
+       @EJB (lookup = "java:global/addressbook-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote")
        private CountrySingletonBeanRemote countryBean;
 
        /**
@@ -101,18 +99,6 @@ public class AddressbookCountryWebApplicationBean extends BaseAddressbookControl
         */
        @PostConstruct
        public void init () {
-               // Try this
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup the bean
-                       this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/addressbook-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote"); //NOI18N
-               } catch (final NamingException ex) {
-                       // Continue to throw
-                       throw new FaceletException(ex);
-               }
-
                // "Cache" country list as this will not change so often.
                this.countryList = this.countryBean.allCountries();
        }
index 8d946477d64ebf814e70ada24578aa8a18fe170f..e48222773a6681e0c5540453c8024bc2f22961f3 100644 (file)
@@ -19,9 +19,9 @@ package org.mxchange.addressbook.beans.mobileprovider;
 import java.text.MessageFormat;
 import java.util.List;
 import javax.annotation.PostConstruct;
+import javax.ejb.EJB;
 import javax.enterprise.context.SessionScoped;
 import javax.enterprise.event.Observes;
-import javax.faces.view.facelets.FaceletException;
 import javax.inject.Named;
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -53,6 +53,7 @@ public class AddressbookMobileProviderWebRequestBean extends BaseAddressbookCont
        /**
         * Remote EJB for mobile providers (regular)
         */
+       @EJB (lookup = "java:global/addressbook-ejb/mobileprovider!org.mxchange.jphone.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote")
        private MobileProviderSingletonBeanRemote mobileRemoteBean;
 
        /**
@@ -100,18 +101,6 @@ public class AddressbookMobileProviderWebRequestBean extends BaseAddressbookCont
         */
        @PostConstruct
        public void init () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup the beans
-                       this.mobileRemoteBean = (MobileProviderSingletonBeanRemote) context.lookup("java:global/addressbook-ejb/mobileprovider!org.mxchange.jphone.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw it again
-                       throw new FaceletException(e);
-               }
-
                // Init list of mobile providers
                this.mobileProviders = this.mobileRemoteBean.allMobileProvider();
        }
index b005fcfa6f3add282d08aaa76bb6d3cc5e3ab0a6..44295c545c9851c0a9185672689e1716afa68f2c 100644 (file)
@@ -21,13 +21,10 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Objects;
 import javax.annotation.PostConstruct;
+import javax.ejb.EJB;
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.event.Observes;
-import javax.faces.view.facelets.FaceletException;
 import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
@@ -79,6 +76,7 @@ public class AddressbookPhoneWebApplicationBean extends BaseAddressbookControlle
        /**
         * General EJB for phone numbers
         */
+       @EJB (lookup = "java:global/addressbook-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote")
        private PhoneSessionBeanRemote phoneBean;
 
        /**
@@ -500,18 +498,6 @@ public class AddressbookPhoneWebApplicationBean extends BaseAddressbookControlle
         */
        @PostConstruct
        public void init () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup the beans
-                       this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/addressbook-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw it again
-                       throw new FaceletException(e);
-               }
-
                // All phone numbers
                this.allMobileNumbers().addAll(this.phoneBean.allMobileNumbers());
                this.allFaxNumbers().addAll(this.phoneBean.allFaxNumbers());
index 14b428e7364149dd88d424d2cb5759f588c66af9..6eb841707921a4be794d26d89612cf015a993c96 100644 (file)
@@ -19,7 +19,7 @@ package org.mxchange.addressbook.beans.user;
 import java.text.MessageFormat;
 import java.util.Locale;
 import java.util.Objects;
-import javax.annotation.PostConstruct;
+import javax.ejb.EJB;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Event;
 import javax.enterprise.event.Observes;
@@ -29,9 +29,6 @@ import javax.faces.context.FacesContext;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
 import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
 import org.mxchange.addressbook.beans.contact.AddressbookAdminContactWebRequestController;
 import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController;
@@ -98,6 +95,7 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
        /**
         * Administrative user EJB
         */
+       @EJB (lookup = "java:global/addressbook-ejb/adminUser!org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote")
        private AdminUserSessionBeanRemote adminUserBean;
 
        /**
@@ -139,6 +137,7 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
        /**
         * General user EJB
         */
+       @EJB (lookup = "java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote")
        private UserSessionBeanRemote userBean;
 
        /**
@@ -215,7 +214,7 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
         * @return Redirect outcome
         */
        public String addUser () {
-               System.out.println("addUser: this.contact="+this.getContact());
+               System.out.println("addUser: this.contact=" + this.getContact());
                // As the form cannot validate the data (required="true"), check it here
                if (this.getUserName() == null) {
                        // Throw NPE
@@ -633,25 +632,6 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                this.userPasswordRepeat = userPasswordRepeat;
        }
 
-       /**
-        * Post-construction method
-        */
-       @PostConstruct
-       public void init () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
-                       this.adminUserBean = (AdminUserSessionBeanRemote) context.lookup("java:global/addressbook-ejb/adminUser!org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
-       }
-
        /**
         * Locks selected user's account. This method makes sure that a lock reason
         * is provided that th user later can read on login attempts.
index 23a577c319688c1db6ea41a81ecdc2de5e95ef41..008ee9c4986f7c95dd61ddf3ef5e198764350d7e 100644 (file)
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Objects;
 import javax.annotation.PostConstruct;
+import javax.ejb.EJB;
 import javax.enterprise.context.SessionScoped;
 import javax.enterprise.event.Event;
 import javax.enterprise.event.Observes;
@@ -30,9 +31,6 @@ import javax.faces.context.FacesContext;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
 import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
 import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController;
 import org.mxchange.addressbook.beans.features.AddressbookFeaturesWebApplicationController;
@@ -111,6 +109,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
        /**
         * Remote user bean
         */
+       @EJB (lookup = "java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote")
        private UserSessionBeanRemote userBean;
 
        /**
@@ -832,18 +831,6 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
         */
        @PostConstruct
        public void init () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
-
                // Initialize user list
                this.userList = this.userBean.allUsers();
 
index 79bc7eea50675e0988af24a53c2f94a8e4b9134f..28b6d53a21a15894ecf5c8502f314c4f43b5fe69 100644 (file)
@@ -24,13 +24,10 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.PostConstruct;
+import javax.ejb.EJB;
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.event.Observes;
-import javax.faces.view.facelets.FaceletException;
 import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
 import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
@@ -74,6 +71,7 @@ public class AddressbookUserActivityWebApplicationBean extends BaseAddressbookCo
        /**
         * EJB for user activity log
         */
+       @EJB (lookup = "java:global/addressbook-ejb/userActivity!org.mxchange.jusercore.model.user.activity.UserActivityLogSessionBeanRemote")
        private UserActivityLogSessionBeanRemote userActivityBean;
 
        /**
@@ -543,18 +541,6 @@ public class AddressbookUserActivityWebApplicationBean extends BaseAddressbookCo
         */
        @PostConstruct
        public void init () {
-               // Try to get EJB instance
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.userActivityBean = (UserActivityLogSessionBeanRemote) context.lookup("java:global/addressbook-ejb/userActivity!org.mxchange.jusercore.model.user.activity.UserActivityLogSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
-
                // Get whole list
                List<LogableUserActivity> list = this.userActivityBean.fetchAllUserActivityLog();
 
index 85c793f4a7340f0757a06550fbf4e921074f3cd3..d3b28b64d8e8c518475823270673ee71d8ecaf5e 100644 (file)
@@ -20,16 +20,13 @@ import java.text.MessageFormat;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Objects;
-import javax.annotation.PostConstruct;
+import javax.ejb.EJB;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Event;
 import javax.enterprise.inject.Any;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
 import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
 import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController;
 import org.mxchange.jcoreee.events.helper.clear.HelperCleanupEvent;
@@ -74,6 +71,7 @@ public class AddressbookConfirmationLinkWebRequestBean extends BaseAddressbookCo
        /**
         * Remote user bean
         */
+       @EJB (lookup = "java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote")
        private UserSessionBeanRemote userBean;
 
        /**
@@ -114,24 +112,6 @@ public class AddressbookConfirmationLinkWebRequestBean extends BaseAddressbookCo
                this.confirmationKey = confirmationKey;
        }
 
-       /**
-        * Post-construction method
-        */
-       @PostConstruct
-       public void init () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
-       }
-
        @Override
        public void maybeConfirmUserAccount () {
                // Trace message
index 883c750533c734abb8a9327f66008b925d83073d..26a37900601e1823579fbe182c66f3102391031c 100644 (file)
@@ -20,13 +20,11 @@ import java.text.MessageFormat;
 import java.util.List;
 import java.util.Objects;
 import javax.annotation.PostConstruct;
+import javax.ejb.EJB;
 import javax.enterprise.context.SessionScoped;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
 import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
 import org.mxchange.addressbook.beans.features.AddressbookFeaturesWebApplicationController;
 import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController;
@@ -70,6 +68,7 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl
        /**
         * Remote email change bean
         */
+       @EJB (lookup = "java:global/addressbook-ejb/userEmailChange!org.mxchange.jusercore.model.user.email_address.UserEmailChangeSessionBeanRemote")
        private UserEmailChangeSessionBeanRemote emailChangeBean;
 
        /**
@@ -197,18 +196,6 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl
         */
        @PostConstruct
        public void init () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.emailChangeBean = (UserEmailChangeSessionBeanRemote) context.lookup("java:global/addressbook-ejb/userEmailChange!org.mxchange.jusercore.model.email_address.EmailChangeSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
-
                // Init list
                this.emailAddresses = this.emailChangeBean.allQueuedAddresses();
        }