/*
- * Copyright (C) 2016 Roland Häder
+ * 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
/**
* Mobile provider bean
*/
- private MobileProviderSingletonBeanRemote mobileRemoteBean;
+ private static MobileProviderSingletonBeanRemote MOBILE_PROVIDER_BEAN;
/**
- * Initialization of this converter
+ * Default constructor
*/
public PizzaMobileProviderConverter () {
- // Try to get it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- /// 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 ConverterException(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
return null;
}
+ // Is the bean there?
+ // @TODO Requires this synchronization or is it (sync) confusing the container?
+ if (null == PizzaMobileProviderConverter.MOBILE_PROVIDER_BEAN) {
+ // Try to get it
+ try {
+ // Get initial context
+ Context initialContext = new InitialContext();
+
+ /// and mobile provider controller
+ PizzaMobileProviderConverter.MOBILE_PROVIDER_BEAN = (MobileProviderSingletonBeanRemote) initialContext.lookup("java:global/pizzaapplication-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();
+ List<MobileProvider> providerList = PizzaMobileProviderConverter.MOBILE_PROVIDER_BEAN.allMobileProvider();
// Init value
MobileProvider provider = null;
// 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)
// @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;
}
@Override
public String getAsString (final FacesContext context, final UIComponent component, final Object value) {
// Is the object null?
- if ((null == value) || ((String.valueOf(value)).isEmpty())) {
+ if ((null == value) || (String.valueOf(value).isEmpty())) {
// Is null
return ""; //NOI18N
} else if (!(value instanceof MobileProvider)) {
// Not same interface
- throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement MobileProvider.", value)); //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("value[]={0} does not implement MobileProvider.", value.getClass().getSimpleName())); //NOI18N
}
- // Return category id
+ // Return id number
return String.valueOf(((MobileProvider) value).getProviderId());
}