]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Mon, 17 Jul 2017 10:21:31 +0000 (12:21 +0200)
committerRoland Häder <roland@mxchange.org>
Mon, 17 Jul 2017 10:25:06 +0000 (12:25 +0200)
- 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 <Project>MobileNumberConverter for
class name.

src/java/org/mxchange/jfinancials/converter/fax/FinancialsFaxNumberConverter.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/converter/landline/FinancialsLandLineNumberConverter.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileConverter.java [deleted file]
src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileNumberConverter.java [new file with mode: 0644]

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 (file)
index 0000000..cf7f56f
--- /dev/null
@@ -0,0 +1,130 @@
+/*\r
+ * Copyright (C) 2017 Roland Häder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Affero General Public License as\r
+ * published by the Free Software Foundation, either version 3 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU Affero General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Affero General Public License\r
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.jfinancials.converter.fax;\r
+\r
+import java.text.MessageFormat;\r
+import javax.faces.component.UIComponent;\r
+import javax.faces.context.FacesContext;\r
+import javax.faces.convert.Converter;\r
+import javax.faces.convert.ConverterException;\r
+import javax.faces.convert.FacesConverter;\r
+import javax.naming.Context;\r
+import javax.naming.InitialContext;\r
+import javax.naming.NamingException;\r
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;\r
+import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;\r
+import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException;\r
+import org.mxchange.jphone.phonenumbers.DialableNumber;\r
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;\r
+import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote;\r
+\r
+/**\r
+ * Converter for fax id <-> valid fax number instance\r
+ * <p>\r
+ * @author Roland Häder<roland@mxchange.org>\r
+ */\r
+@FacesConverter (value = "FaxNumberConverter")\r
+public class FinancialsFaxNumberConverter implements Converter {\r
+\r
+       /**\r
+        * Logger instance\r
+        */\r
+       @Log\r
+       private LoggerBeanLocal loggerBeanLocal;\r
+\r
+       /**\r
+        * Phone EJB\r
+        */\r
+       private PhoneSessionBeanRemote phoneBean;\r
+\r
+       /**\r
+        * Initialization of this converter\r
+        */\r
+       public FinancialsFaxNumberConverter () {\r
+               // Try to get it\r
+               try {\r
+                       // Get initial context\r
+                       Context context = new InitialContext();\r
+\r
+                       // Lookup logger\r
+                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N\r
+\r
+                       // ... and user controller\r
+                       this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N\r
+               } catch (final NamingException ex) {\r
+                       // Continue to throw it\r
+                       throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {\r
+               // Log message\r
+               this.loggerBeanLocal.logTrace(MessageFormat.format("{0}.getAsObject: context={1},component={2},submittedValue={3} - CALLED!", this.getClass().getSimpleName(), context, component, submittedValue)); //NOI18N\r
+\r
+               // Is the value null or empty?\r
+               if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {\r
+                       // Warning message\r
+                       this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N\r
+\r
+                       // Return null\r
+                       return null;\r
+               }\r
+\r
+               // Init instance\r
+               DialableFaxNumber faxNumber = null;\r
+\r
+               try {\r
+                       // Try to parse the value as long\r
+                       Long faxNumberId = Long.valueOf(submittedValue);\r
+\r
+                       // Log message\r
+                       this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject: faxNumberId={1}", this.getClass().getSimpleName(), faxNumberId)); //NOI18N\r
+\r
+                       // Try to get mobile instance from it\r
+                       faxNumber = this.phoneBean.findFaxNumberById(faxNumberId);\r
+               } catch (final NumberFormatException ex) {\r
+                       // Throw again\r
+                       throw new ConverterException(ex);\r
+               } catch (final PhoneEntityNotFoundException ex) {\r
+                       // Debug message\r
+                       this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N\r
+               }\r
+\r
+               // Log message\r
+               this.loggerBeanLocal.logTrace(MessageFormat.format("{0}.getAsObject: faxNumber={1} - EXIT!", this.getClass().getSimpleName(), faxNumber)); //NOI18N\r
+\r
+               // Return it\r
+               return faxNumber;\r
+       }\r
+\r
+       @Override\r
+       public String getAsString (final FacesContext context, final UIComponent component, final Object value) {\r
+               // Is the object null?\r
+               if ((null == value) || ((String.valueOf(value)).isEmpty())) {\r
+                       // Is null\r
+                       return ""; //NOI18N\r
+               } else if (!(value instanceof DialableNumber)) {\r
+                       // Not same interface\r
+                       throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement DialableNumber.", value)); //NOI18N\r
+               }\r
+\r
+               // Return category id\r
+               return String.valueOf(((DialableNumber) value).getPhoneId());\r
+       }\r
+\r
+}\r
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 (file)
index 0000000..8f8f9f6
--- /dev/null
@@ -0,0 +1,121 @@
+/*\r
+ * Copyright (C) 2017 Roland Häder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Affero General Public License as\r
+ * published by the Free Software Foundation, either version 3 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU Affero General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Affero General Public License\r
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.jfinancials.converter.landline;\r
+\r
+import java.text.MessageFormat;\r
+import javax.faces.component.UIComponent;\r
+import javax.faces.context.FacesContext;\r
+import javax.faces.convert.Converter;\r
+import javax.faces.convert.ConverterException;\r
+import javax.faces.convert.FacesConverter;\r
+import javax.naming.Context;\r
+import javax.naming.InitialContext;\r
+import javax.naming.NamingException;\r
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;\r
+import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;\r
+import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException;\r
+import org.mxchange.jphone.phonenumbers.DialableNumber;\r
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;\r
+import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote;\r
+\r
+/**\r
+ * Converter for land-line id <-> valid land-line number instance\r
+ * <p>\r
+ * @author Roland Häder<roland@mxchange.org>\r
+ */\r
+@FacesConverter (value = "LandLineNumberConverter")\r
+public class FinancialsLandLineNumberConverter implements Converter {\r
+\r
+       /**\r
+        * Logger instance\r
+        */\r
+       @Log\r
+       private LoggerBeanLocal loggerBeanLocal;\r
+\r
+       /**\r
+        * Phone EJB\r
+        */\r
+       private PhoneSessionBeanRemote phoneBean;\r
+\r
+       /**\r
+        * Initialization of this converter\r
+        */\r
+       public FinancialsLandLineNumberConverter () {\r
+               // Try to get it\r
+               try {\r
+                       // Get initial context\r
+                       Context context = new InitialContext();\r
+\r
+                       // Lookup logger\r
+                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N\r
+\r
+                       // ... and user controller\r
+                       this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N\r
+               } catch (final NamingException ex) {\r
+                       // Continue to throw it\r
+                       throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {\r
+               // Is the value null or empty?\r
+               if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {\r
+                       // Warning message\r
+                       this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N\r
+\r
+                       // Return null\r
+                       return null;\r
+               }\r
+\r
+               // Init instance\r
+               DialableLandLineNumber landLineNumber = null;\r
+\r
+               try {\r
+                       // Try to parse the value as long\r
+                       Long landLineNumberId = Long.valueOf(submittedValue);\r
+\r
+                       // Try to get mobile instance from it\r
+                       landLineNumber = this.phoneBean.findLandLineNumberById(landLineNumberId);\r
+               } catch (final NumberFormatException ex) {\r
+                       // Throw again\r
+                       throw new ConverterException(ex);\r
+               } catch (final PhoneEntityNotFoundException ex) {\r
+                       // Debug message\r
+                       this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N\r
+               }\r
+\r
+               // Return it\r
+               return landLineNumber;\r
+       }\r
+\r
+       @Override\r
+       public String getAsString (final FacesContext context, final UIComponent component, final Object value) {\r
+               // Is the object null?\r
+               if ((null == value) || ((String.valueOf(value)).isEmpty())) {\r
+                       // Is null\r
+                       return ""; //NOI18N\r
+               } else if (!(value instanceof DialableNumber)) {\r
+                       // Not same interface\r
+                       throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement DialableNumber.", value)); //NOI18N\r
+               }\r
+\r
+               // Return category id\r
+               return String.valueOf(((DialableNumber) value).getPhoneId());\r
+       }\r
+\r
+}\r
diff --git a/src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileConverter.java b/src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileConverter.java
deleted file mode 100644 (file)
index 6e2dd86..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-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
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@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());
-       }
-
-}
diff --git a/src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileNumberConverter.java b/src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileNumberConverter.java
new file mode 100644 (file)
index 0000000..f908ca9
--- /dev/null
@@ -0,0 +1,116 @@
+/*\r
+ * Copyright (C) 2016, 2017 Roland Häder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Affero General Public License as\r
+ * published by the Free Software Foundation, either version 3 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU Affero General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Affero General Public License\r
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.jfinancials.converter.mobile;\r
+\r
+import java.text.MessageFormat;\r
+import javax.faces.component.UIComponent;\r
+import javax.faces.context.FacesContext;\r
+import javax.faces.convert.Converter;\r
+import javax.faces.convert.ConverterException;\r
+import javax.faces.convert.FacesConverter;\r
+import javax.naming.Context;\r
+import javax.naming.InitialContext;\r
+import javax.naming.NamingException;\r
+import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException;\r
+import org.mxchange.jphone.phonenumbers.DialableNumber;\r
+import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;\r
+import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote;\r
+\r
+/**\r
+ * Converter for mobile id <-> valid mobile instance\r
+ * <p>\r
+ * @author Roland Häder<roland@mxchange.org>\r
+ */\r
+@FacesConverter (value = "MobileNumberConverter")\r
+public class FinancialsMobileNumberConverter implements Converter {\r
+\r
+       /**\r
+        * Phone EJB\r
+        */\r
+       private PhoneSessionBeanRemote phoneBean;\r
+\r
+       /**\r
+        * Initialization of this converter\r
+        */\r
+       public FinancialsMobileNumberConverter () {\r
+       }\r
+\r
+       @Override\r
+       public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {\r
+               // Is the value null or empty?\r
+               if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {\r
+                       // Warning message\r
+                       // @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\r
+\r
+                       // Return null\r
+                       return null;\r
+               }\r
+\r
+               synchronized (this) {\r
+                       // Is the EJB instanciated?\r
+                       if (null == this.phoneBean) {\r
+                               // Try to get it\r
+                               try {\r
+                                       // Get initial context\r
+                                       Context initialContext = new InitialContext();\r
+\r
+                                       // ... and user controller\r
+                                       this.phoneBean = (PhoneSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N\r
+                               } catch (final NamingException ex) {\r
+                                       // Continue to throw it\r
+                                       throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // Init instance\r
+               DialableMobileNumber mobile = null;\r
+\r
+               try {\r
+                       // Try to parse the value as long\r
+                       Long mobileId = Long.valueOf(submittedValue);\r
+\r
+                       // Try to get mobile instance from it\r
+                       mobile = this.phoneBean.findMobileNumberById(mobileId);\r
+               } catch (final NumberFormatException ex) {\r
+                       // Throw again\r
+                       throw new ConverterException(ex);\r
+               } catch (final PhoneEntityNotFoundException ex) {\r
+                       // Debug message\r
+                       // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N\r
+               }\r
+\r
+               // Return it\r
+               return mobile;\r
+       }\r
+\r
+       @Override\r
+       public String getAsString (final FacesContext context, final UIComponent component, final Object value) {\r
+               // Is the object null?\r
+               if ((null == value) || ((String.valueOf(value)).isEmpty())) {\r
+                       // Is null\r
+                       return ""; //NOI18N\r
+               } else if (!(value instanceof DialableNumber)) {\r
+                       // Not same interface\r
+                       throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement DialableNumber.", value)); //NOI18N\r
+               }\r
+\r
+               // Return category id\r
+               return String.valueOf(((DialableNumber) value).getPhoneId());\r
+       }\r
+\r
+}\r