]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/beans/country/JobsCountryWebApplicationBean.java
Refactured a lot:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / country / JobsCountryWebApplicationBean.java
index a39e2251afcedeca9e765f207c5ef2ce411bf37b..93cd4fdc1afcb82b09d23de62cd45921db4ea6f8 100644 (file)
  */
 package org.mxchange.jjobs.beans.country;
 
-import java.util.Collections;
+import java.text.MessageFormat;
 import java.util.List;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Named;
 import javax.naming.Context;
@@ -27,6 +28,7 @@ import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.jcountry.data.Country;
 import org.mxchange.jcountry.data.CountrySingletonBeanRemote;
+import org.mxchange.jcountry.events.AdminAddedCountryEvent;
 
 /**
  * A country bean
@@ -70,9 +72,31 @@ public class JobsCountryWebApplicationBean implements JobsCountryWebApplicationC
        }
 
        @Override
+       public void afterAdminAddedCountry (@Observes final AdminAddedCountryEvent event) {
+               // Is all valid?
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getAddedCountry() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.addedCountry is null"); //NOI18N
+               } else if (event.getAddedCountry().getCountryId() == null) {
+                       // And again ...
+                       throw new NullPointerException("event.addedCountry.countryId is null"); //NOI18N
+               } else if (event.getAddedCountry().getCountryId() < 1) {
+                       // Id is invalid
+                       throw new IllegalArgumentException(MessageFormat.format("event.addedCountry.countryId={0} is not valid.", event.getAddedCountry().getCountryId())); //NOI18N
+               }
+
+               // Add the event
+               this.countryList.add(event.getAddedCountry());
+       }
+
+       @Override
+       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
        public List<Country> allCountries () {
                // Return "cached" version
-               return Collections.unmodifiableList(this.countryList);
+               return this.countryList;
        }
 
        /**