]> git.mxchange.org Git - jjobs-war.git/commitdiff
renamed converter, no cellphone-only, but all mobile phones
authorRoland Haeder <roland@mxchange.org>
Tue, 11 Apr 2017 13:00:09 +0000 (15:00 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 12 Apr 2017 10:45:53 +0000 (12:45 +0200)
src/java/org/mxchange/jjobs/converter/mobile/JobsMobileConverter.java [deleted file]
src/java/org/mxchange/jjobs/converter/mobile/JobsMobileNumberConverter.java [new file with mode: 0644]

diff --git a/src/java/org/mxchange/jjobs/converter/mobile/JobsMobileConverter.java b/src/java/org/mxchange/jjobs/converter/mobile/JobsMobileConverter.java
deleted file mode 100644 (file)
index c1286f2..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (C) 2016 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.jjobs.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.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.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 = "CellphoneConverter")
-public class JobsMobileConverter implements Converter {
-
-       /**
-        * Logger instance
-        */
-       @Log
-       private LoggerBeanLocal loggerBeanLocal;
-
-       /**
-        * Phone EJB
-        */
-       private PhoneSessionBeanRemote phoneBean;
-
-       /**
-        * Initialization of this converter
-        */
-       public JobsMobileConverter () {
-               // 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/jjobs-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) {
-               // 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(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
-                       // Return null
-                       return null;
-               }
-
-               // Init instance
-               DialableMobileNumber mobileNumber = null;
-
-               try {
-                       // Try to parse the value as long
-                       Long mobileNumberId = Long.valueOf(submittedValue);
-
-                       // Try to get mobile instance from it
-                       mobileNumber = this.phoneBean.findMobileNumberById(mobileNumberId);
-               } 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
-               }
-
-               // Trace message
-               // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: cellphone={0} - EXIT!", cellphone)); //NOI18N
-
-               // Return it
-               return mobileNumber;
-       }
-
-       @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/jjobs/converter/mobile/JobsMobileNumberConverter.java b/src/java/org/mxchange/jjobs/converter/mobile/JobsMobileNumberConverter.java
new file mode 100644 (file)
index 0000000..dc3785b
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2016 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.jjobs.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.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.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 = "MobileNumberConverter")
+public class JobsMobileNumberConverter implements Converter {
+
+       /**
+        * Logger instance
+        */
+       @Log
+       private LoggerBeanLocal loggerBeanLocal;
+
+       /**
+        * Phone EJB
+        */
+       private PhoneSessionBeanRemote phoneBean;
+
+       /**
+        * Initialization of this converter
+        */
+       public JobsMobileNumberConverter () {
+               // 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/jjobs-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) {
+               // 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(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
+
+                       // Return null
+                       return null;
+               }
+
+               // Init instance
+               DialableMobileNumber mobileNumber = null;
+
+               try {
+                       // Try to parse the value as long
+                       Long mobileNumberId = Long.valueOf(submittedValue);
+
+                       // Try to get mobile instance from it
+                       mobileNumber = this.phoneBean.findMobileNumberById(mobileNumberId);
+               } 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
+               }
+
+               // Trace message
+               // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: cellphone={0} - EXIT!", cellphone)); //NOI18N
+
+               // Return it
+               return mobileNumber;
+       }
+
+       @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());
+       }
+
+}