From fe1906389d46cb799ff00e19181e82c2eb24f31b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 17 Jul 2017 12:21:31 +0200 Subject: [PATCH] Please cherry-pick: - added missing converter for land-line and fax numbers - renamed converter after naming-convetion, see below Convention: A converter converts mobile number instances from their corresponding id numbers and vise versa, so it should be called MobileNumberConverter for FacesConverter annotation and MobileNumberConverter for class name. --- .../fax/FinancialsFaxNumberConverter.java | 130 ++++++++++ .../FinancialsLandLineNumberConverter.java | 121 +++++++++ ...a => FinancialsMobileNumberConverter.java} | 232 +++++++++--------- 3 files changed, 367 insertions(+), 116 deletions(-) create mode 100644 src/java/org/mxchange/jfinancials/converter/fax/FinancialsFaxNumberConverter.java create mode 100644 src/java/org/mxchange/jfinancials/converter/landline/FinancialsLandLineNumberConverter.java rename src/java/org/mxchange/jfinancials/converter/mobile/{FinancialsMobileConverter.java => FinancialsMobileNumberConverter.java} (93%) diff --git a/src/java/org/mxchange/jfinancials/converter/fax/FinancialsFaxNumberConverter.java b/src/java/org/mxchange/jfinancials/converter/fax/FinancialsFaxNumberConverter.java new file mode 100644 index 00000000..cf7f56f6 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/converter/fax/FinancialsFaxNumberConverter.java @@ -0,0 +1,130 @@ +/* + * Copyright (C) 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 + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.converter.fax; + +import java.text.MessageFormat; +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.exceptions.PhoneEntityNotFoundException; +import org.mxchange.jphone.phonenumbers.DialableNumber; +import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote; + +/** + * Converter for fax id <-> valid fax number instance + *

+ * @author Roland Häder + */ +@FacesConverter (value = "FaxNumberConverter") +public class FinancialsFaxNumberConverter implements Converter { + + /** + * Logger instance + */ + @Log + private LoggerBeanLocal loggerBeanLocal; + + /** + * Phone EJB + */ + private PhoneSessionBeanRemote phoneBean; + + /** + * Initialization of this converter + */ + public FinancialsFaxNumberConverter () { + // 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 user controller + this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //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) { + // Log message + this.loggerBeanLocal.logTrace(MessageFormat.format("{0}.getAsObject: context={1},component={2},submittedValue={3} - CALLED!", this.getClass().getSimpleName(), context, component, submittedValue)); //NOI18N + + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Warning message + this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N + + // Return null + return null; + } + + // Init instance + DialableFaxNumber faxNumber = null; + + try { + // Try to parse the value as long + Long faxNumberId = Long.valueOf(submittedValue); + + // Log message + this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject: faxNumberId={1}", this.getClass().getSimpleName(), faxNumberId)); //NOI18N + + // Try to get mobile instance from it + faxNumber = this.phoneBean.findFaxNumberById(faxNumberId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final PhoneEntityNotFoundException ex) { + // Debug message + this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N + } + + // Log message + this.loggerBeanLocal.logTrace(MessageFormat.format("{0}.getAsObject: faxNumber={1} - EXIT!", this.getClass().getSimpleName(), faxNumber)); //NOI18N + + // Return it + return faxNumber; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final Object value) { + // Is the object null? + if ((null == value) || ((String.valueOf(value)).isEmpty())) { + // Is null + return ""; //NOI18N + } else if (!(value instanceof DialableNumber)) { + // Not same interface + throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement DialableNumber.", value)); //NOI18N + } + + // Return category id + return String.valueOf(((DialableNumber) value).getPhoneId()); + } + +} diff --git a/src/java/org/mxchange/jfinancials/converter/landline/FinancialsLandLineNumberConverter.java b/src/java/org/mxchange/jfinancials/converter/landline/FinancialsLandLineNumberConverter.java new file mode 100644 index 00000000..8f8f9f65 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/converter/landline/FinancialsLandLineNumberConverter.java @@ -0,0 +1,121 @@ +/* + * Copyright (C) 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 + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.converter.landline; + +import java.text.MessageFormat; +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.exceptions.PhoneEntityNotFoundException; +import org.mxchange.jphone.phonenumbers.DialableNumber; +import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote; + +/** + * Converter for land-line id <-> valid land-line number instance + *

+ * @author Roland Häder + */ +@FacesConverter (value = "LandLineNumberConverter") +public class FinancialsLandLineNumberConverter implements Converter { + + /** + * Logger instance + */ + @Log + private LoggerBeanLocal loggerBeanLocal; + + /** + * Phone EJB + */ + private PhoneSessionBeanRemote phoneBean; + + /** + * Initialization of this converter + */ + public FinancialsLandLineNumberConverter () { + // 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 user controller + this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //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) { + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Warning message + this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N + + // Return null + return null; + } + + // Init instance + DialableLandLineNumber landLineNumber = null; + + try { + // Try to parse the value as long + Long landLineNumberId = Long.valueOf(submittedValue); + + // Try to get mobile instance from it + landLineNumber = this.phoneBean.findLandLineNumberById(landLineNumberId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final PhoneEntityNotFoundException ex) { + // Debug message + this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N + } + + // Return it + return landLineNumber; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final Object value) { + // Is the object null? + if ((null == value) || ((String.valueOf(value)).isEmpty())) { + // Is null + return ""; //NOI18N + } else if (!(value instanceof DialableNumber)) { + // Not same interface + throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement DialableNumber.", value)); //NOI18N + } + + // Return category id + return String.valueOf(((DialableNumber) value).getPhoneId()); + } + +} diff --git a/src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileConverter.java b/src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileNumberConverter.java similarity index 93% rename from src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileConverter.java rename to src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileNumberConverter.java index 6e2dd865..f908ca92 100644 --- a/src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileNumberConverter.java @@ -1,116 +1,116 @@ -/* - * 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 - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jfinancials.converter.mobile; - -import java.text.MessageFormat; -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.jphone.exceptions.PhoneEntityNotFoundException; -import org.mxchange.jphone.phonenumbers.DialableNumber; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote; - -/** - * Converter for mobile id <-> valid mobile instance - *

- * @author Roland Häder - */ -@FacesConverter (value = "MobileConverter") -public class FinancialsMobileConverter implements Converter { - - /** - * Phone EJB - */ - private PhoneSessionBeanRemote phoneBean; - - /** - * Initialization of this converter - */ - public FinancialsMobileConverter () { - } - - @Override - public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Is the value null or empty? - if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { - // Warning message - // @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.phoneBean) { - // Try to get it - try { - // Get initial context - Context initialContext = new InitialContext(); - - // ... and user controller - this.phoneBean = (PhoneSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N - } catch (final NamingException ex) { - // Continue to throw it - throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N - } - } - } - - // Init instance - DialableMobileNumber mobile = null; - - try { - // Try to parse the value as long - Long mobileId = Long.valueOf(submittedValue); - - // Try to get mobile instance from it - mobile = this.phoneBean.findMobileNumberById(mobileId); - } catch (final NumberFormatException ex) { - // Throw again - throw new ConverterException(ex); - } catch (final PhoneEntityNotFoundException ex) { - // Debug message - // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N - } - - // Return it - return mobile; - } - - @Override - public String getAsString (final FacesContext context, final UIComponent component, final Object value) { - // Is the object null? - if ((null == value) || ((String.valueOf(value)).isEmpty())) { - // Is null - return ""; //NOI18N - } else if (!(value instanceof DialableNumber)) { - // Not same interface - throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement DialableNumber.", value)); //NOI18N - } - - // Return category id - return String.valueOf(((DialableNumber) value).getPhoneId()); - } - -} +/* + * 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 + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.converter.mobile; + +import java.text.MessageFormat; +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.jphone.exceptions.PhoneEntityNotFoundException; +import org.mxchange.jphone.phonenumbers.DialableNumber; +import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote; + +/** + * Converter for mobile id <-> valid mobile instance + *

+ * @author Roland Häder + */ +@FacesConverter (value = "MobileNumberConverter") +public class FinancialsMobileNumberConverter implements Converter { + + /** + * Phone EJB + */ + private PhoneSessionBeanRemote phoneBean; + + /** + * Initialization of this converter + */ + public FinancialsMobileNumberConverter () { + } + + @Override + public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Warning message + // @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.phoneBean) { + // Try to get it + try { + // Get initial context + Context initialContext = new InitialContext(); + + // ... and user controller + this.phoneBean = (PhoneSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N + } catch (final NamingException ex) { + // Continue to throw it + throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N + } + } + } + + // Init instance + DialableMobileNumber mobile = null; + + try { + // Try to parse the value as long + Long mobileId = Long.valueOf(submittedValue); + + // Try to get mobile instance from it + mobile = this.phoneBean.findMobileNumberById(mobileId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final PhoneEntityNotFoundException ex) { + // Debug message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N + } + + // Return it + return mobile; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final Object value) { + // Is the object null? + if ((null == value) || ((String.valueOf(value)).isEmpty())) { + // Is null + return ""; //NOI18N + } else if (!(value instanceof DialableNumber)) { + // Not same interface + throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement DialableNumber.", value)); //NOI18N + } + + // Return category id + return String.valueOf(((DialableNumber) value).getPhoneId()); + } + +} -- 2.39.5