]> git.mxchange.org Git - pizzaservice-war.git/blobdiff - src/java/org/mxchange/pizzaapplication/converter/mobileprovider/PizzaMobileProviderConverter.java
Please cherry-pick:
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / converter / mobileprovider / PizzaMobileProviderConverter.java
index 0830b9ab75c7508f6241490062f1d8b3bbde251d..602e4641487b56b3b84916bc4ca31814297696c1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Roland Haeder
+ * Copyright (C) 2016, 2017 Roland Häder
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -22,29 +22,22 @@ import java.util.Objects;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
 import javax.faces.convert.FacesConverter;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
-import org.mxchange.jcoreeelogger.beans.local.logger.Log;
-import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote;
 
 /**
  * Converter for SMS provider instance
  * <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Häder<roland@mxchange.org>
  */
 @FacesConverter (value = "MobileProviderConverter")
 public class PizzaMobileProviderConverter implements Converter {
 
-       /**
-        * Logger instance
-        */
-       @Log
-       private LoggerBeanLocal loggerBeanLocal;
-
        /**
         * Mobile provider bean
         */
@@ -54,36 +47,36 @@ public class PizzaMobileProviderConverter implements Converter {
         * Initialization of this converter
         */
        public PizzaMobileProviderConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Lookup logger
-                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
-
-                       /// and SMS provider controller
-                       this.mobileRemoteBean = (MobileProviderSingletonBeanRemote) context.lookup("java:global/PizzaService-ejb/mobileprovider!org.mxchange.jphone.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote"); //NOI18N
-               } catch (final NamingException ex) {
-                       // Continue to throw it
-                       throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
-               }
        }
 
        @Override
        public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
-               // Trace message
-               // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2} - CALLED!", context, component, submittedValue)); //NOI18N
-
                // Is the value null or empty?
                if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
                        // Warning message
-                       this.loggerBeanLocal.logWarning("getAsObject: submittedValue is null or empty - EXIT!"); //NOI18N
+                       // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
 
                        // Return null
                        return null;
                }
 
+               synchronized (this) {
+                       // Is the EJB instanciated?
+                       if (null == this.mobileRemoteBean) {
+                               // Try to get it
+                               try {
+                                       // Get initial context
+                                       Context initialContext = new InitialContext();
+
+                                       /// and mobile provider controller
+                                       this.mobileRemoteBean = (MobileProviderSingletonBeanRemote) initialContext.lookup("java:global/pizzaservice-ejb/mobileprovider!org.mxchange.jphone.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote"); //NOI18N
+                               } catch (final NamingException ex) {
+                                       // Continue to throw it
+                                       throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+                               }
+                       }
+               }
+
                // Get full list
                List<MobileProvider> providerList = this.mobileRemoteBean.allMobileProvider();
 
@@ -98,9 +91,6 @@ public class PizzaMobileProviderConverter implements Converter {
                        // Category id should not be below 1
                        assert (providerId > 0) : "providerId is smaller than one: " + providerId; //NOI18N
 
-                       // Debug message
-                       // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: providerId={0}", providerId)); //NOI18N
-
                        // Try to find it
                        for (final MobileProvider prov : providerList) {
                                // Is the id the same? (null-safe)
@@ -112,12 +102,9 @@ public class PizzaMobileProviderConverter implements Converter {
                        }
                } catch (final NumberFormatException ex) {
                        // Log exception (maybe to much?)
-                       this.loggerBeanLocal.logException(ex);
+                       // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logException(ex);
                }
 
-               // Trace message
-               // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: provider={0} - EXIT!", provider)); //NOI18N
-
                // Return it
                return provider;
        }