2 * Copyright (C) 2016, 2017 Roland Häder
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.jjobs.beans.country;
19 import java.text.MessageFormat;
20 import java.util.List;
21 import javax.annotation.PostConstruct;
23 import javax.enterprise.context.ApplicationScoped;
24 import javax.enterprise.event.Observes;
25 import javax.inject.Named;
26 import org.mxchange.jcountry.data.Country;
27 import org.mxchange.jcountry.data.CountrySingletonBeanRemote;
28 import org.mxchange.jcountry.events.ObservableAdminAddedCountryEvent;
29 import org.mxchange.jjobs.beans.BaseJobsController;
34 * @author Roland Häder<roland@mxchange.org>
36 @Named ("countryController")
38 public class JobsCountryWebApplicationBean extends BaseJobsController implements JobsCountryWebApplicationController {
43 private static final long serialVersionUID = 176_985_298_681_742_960L;
48 @EJB (lookup = "java:global/jjobs-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote")
49 private CountrySingletonBeanRemote countryBean;
52 * List of all countries
54 private List<Country> countryList;
59 public JobsCountryWebApplicationBean () {
60 // Call super constructor
65 * Observing method when the event is fired that an administrator added a
68 * @param event Event instance
70 public void afterAdminAddedCountryEvent (@Observes final ObservableAdminAddedCountryEvent event) {
74 throw new NullPointerException("event is null"); //NOI18N
75 } else if (event.getAddedCountry() == null) {
77 throw new NullPointerException("event.addedCountry is null"); //NOI18N
78 } else if (event.getAddedCountry().getCountryId() == null) {
80 throw new NullPointerException("event.addedCountry.countryId is null"); //NOI18N
81 } else if (event.getAddedCountry().getCountryId() < 1) {
83 throw new IllegalArgumentException(MessageFormat.format("event.addedCountry.countryId={0} is not valid.", event.getAddedCountry().getCountryId())); //NOI18N
87 this.countryList.add(event.getAddedCountry());
91 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
92 public List<Country> allCountries () {
93 // Return "cached" version
94 return this.countryList;
98 * Post-construction method
101 public void init () {
102 // "Cache" country list as this will not change so often.
103 this.countryList = this.countryBean.allCountries();