X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Fjjobs%2Fconverter%2Flandline%2FJobsLandLineNumberConverter.java;h=ed7f613e9b1d0caf93007a6479a9dbda3b4d996f;hb=88344c201dccb8ccc2dec09190ab3efd596ef210;hp=008d34075f90ff7a3adbdbbd2dd9e48f7f2cb6c5;hpb=34b8e5f2b3cbb3545f0d5d99b8cb0c9685fe4f32;p=jjobs-war.git diff --git a/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java b/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java index 008d3407..ed7f613e 100644 --- a/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java +++ b/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java @@ -1,5 +1,5 @@ /* - * 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 @@ -16,67 +16,42 @@ */ 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.JobsPhoneWebRequestBean; +import org.mxchange.jjobs.beans.phone.JobsPhoneWebRequestController; +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 *

* @author Roland Häder */ -@FacesConverter (value = "LandLineNumberConverter") -public class JobsLandLineNumberConverter implements Converter { - - /** - * Logger instance - */ - @Log - private LoggerBeanLocal loggerBeanLocal; +@FacesConverter ("LandLineNumberConverter") +public class JobsLandLineNumberConverter implements Converter { /** * Phone EJB */ - private PhoneSessionBeanRemote phoneBean; + private static JobsPhoneWebRequestController PHONE_CONTROLLER; - /** - * 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 + @Override + public DialableLandLineNumber getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the instance there? + if (PHONE_CONTROLLER == null) { + // Get bean from CDI directly + PHONE_CONTROLLER = CDI.current().select(JobsPhoneWebRequestBean.class).get(); } - } - @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 + // @TODO Not possible here: this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N // Return null return null; @@ -87,16 +62,16 @@ public class JobsLandLineNumberConverter implements Converter { 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_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 @@ -104,18 +79,15 @@ public class JobsLandLineNumberConverter implements Converter { } @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()); } }