/*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2017 - 2020 Free Software Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
*/
package org.mxchange.jjobs.converter.landline;
-import java.text.MessageFormat;
+import javax.enterprise.inject.spi.CDI;
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;
+import org.mxchange.jjobs.beans.phone.list.JobsPhoneListWebViewBean;
+import org.mxchange.jjobs.beans.phone.list.JobsPhoneListWebViewController;
+import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException;
+import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
/**
* Converter for land-line id <-> valid land-line number instance
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-@FacesConverter (value = "LandLineNumberConverter")
-public class JobsLandLineNumberConverter implements Converter {
-
- /**
- * Logger instance
- */
- @Log
- private LoggerBeanLocal loggerBeanLocal;
+@FacesConverter ("LandLineNumberConverter")
+public class JobsLandLineNumberConverter implements Converter<DialableLandLineNumber> {
/**
* Phone EJB
*/
- private PhoneSessionBeanRemote phoneBean;
-
- /**
- * Initialization of this converter
- */
- public JobsLandLineNumberConverter () {
- // 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
- }
- }
+ private static JobsPhoneListWebViewController PHONE_LIST_CONTROLLER;
@Override
- public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
+ public DialableLandLineNumber 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;
+ // Is the instance there?
+ if (null == PHONE_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ PHONE_LIST_CONTROLLER = CDI.current().select(JobssPhoneListWebViewBean.class).get();
+ }
+
try {
// Try to parse the value as long
- Long landLineNumberId = Long.valueOf(submittedValue);
+ final Long landLineNumberId = Long.valueOf(submittedValue);
// Try to get mobile instance from it
- landLineNumber = this.phoneBean.findLandLineNumberById(landLineNumberId);
+ landLineNumber = PHONE_LIST_CONTROLLER.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
+ // @TODO Not possible here: this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
}
// Return it
}
@Override
- public String getAsString (final FacesContext context, final UIComponent component, final Object value) {
+ public String getAsString (final FacesContext context, final UIComponent component, final DialableLandLineNumber 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 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());
+ // Return id number
+ return String.valueOf(value.getPhoneId());
}
}