From: Roland Häder Date: Sat, 19 Aug 2017 20:34:30 +0000 (+0200) Subject: Fixed JNDI names + moved converter to proper packages X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1d5ce891a7a69ba4d074e00ad9d09b2792ddaafe;p=jfinancials-war.git Fixed JNDI names + moved converter to proper packages Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBusinessContactConverter.java b/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBusinessContactConverter.java new file mode 100644 index 00000000..fbc9b624 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBusinessContactConverter.java @@ -0,0 +1,115 @@ +/* + * 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.business.basicdata; + +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.jcontacts.contact.Contact; +import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData; +import org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote; +import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataNotFoundException; + +/** + * Converter for contact id <-> valid business contact instance + *

+ * @author Roland Häder + */ +@FacesConverter (value = "BusinessContactConverter") +public class FinancialsBusinessContactConverter implements Converter { + + /** + * Business contact EJB + */ + private static BusinessDataSessionBeanRemote BUSINESS_CONTACT_BEAN; + + /** + * Default constructor + */ + public FinancialsBusinessContactConverter () { + } + + @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; + } + + // Is the bean there? + // @TODO Requires this synchronization or is it (sync) confusing the container? + if (null == FinancialsBusinessContactConverter.BUSINESS_CONTACT_BEAN) { + // Try to get it + try { + // Get initial context + Context initialContext = new InitialContext(); + + // ... and user controller + FinancialsBusinessContactConverter.BUSINESS_CONTACT_BEAN = (BusinessDataSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote"); //NOI18N + } catch (final NamingException ex) { + // Continue to throw it + throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N + } + } + + // Init instance + BusinessBasicData businessContact = null; + + try { + // Try to parse the value as long + Long contactId = Long.valueOf(submittedValue); + + // Try to get user instance from it + businessContact = FinancialsBusinessContactConverter.BUSINESS_CONTACT_BEAN.findBusinessDataById(contactId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final BusinessDataNotFoundException 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 businessContact; + } + + @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 Contact)) { + // Not same interface + throw new IllegalArgumentException(MessageFormat.format("value[]={0} does not implement Contact.", value.getClass().getSimpleName())); //NOI18N + } + + // Return id number + return String.valueOf(((BusinessBasicData) value).getBusinessDataId()); + } + +} diff --git a/src/java/org/mxchange/jfinancials/converter/business/company_employee/FinancialsCompanyEmployeeConverter.java b/src/java/org/mxchange/jfinancials/converter/business/company_employee/FinancialsCompanyEmployeeConverter.java new file mode 100644 index 00000000..e2126984 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/converter/business/company_employee/FinancialsCompanyEmployeeConverter.java @@ -0,0 +1,114 @@ +/* + * 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.business.company_employee; + +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.jcontactsbusiness.employee.CompanyEmployeeSessionBeanRemote; +import org.mxchange.jcontactsbusiness.employee.Employee; +import org.mxchange.jcontactsbusiness.exceptions.employee.CompanyEmployeeNotFoundException; + +/** + * Converter for converting company employee to and from id number + *

+ * @author Roland Häder + */ +@FacesConverter (value = "CompanyEmployeeConverter") +public class FinancialsCompanyEmployeeConverter implements Converter { + + /** + * CompanyEmployee EJB + */ + private static CompanyEmployeeSessionBeanRemote COMPANY_EMPLOYEE_BEAN; + + /** + * Default constructor + */ + public FinancialsCompanyEmployeeConverter () { + } + + @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; + } + + // Is the bean there? + // @TODO Requires this synchronization or is it (sync) confusing the container? + if (null == FinancialsCompanyEmployeeConverter.COMPANY_EMPLOYEE_BEAN) { + // Try to get it + try { + // Get initial context + Context initialContext = new InitialContext(); + + // ... and user controller + FinancialsCompanyEmployeeConverter.COMPANY_EMPLOYEE_BEAN = (CompanyEmployeeSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/companyEmployee!org.mxchange.jcontactsbusiness.company_employee.CompanyEmployeeSessionBeanRemote"); //NOI18N + } catch (final NamingException ex) { + // Continue to throw it + throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N + } + } + + // Init instance + Employee companyEmployee = null; + + try { + // Try to parse the value as long + Long employeeId = Long.valueOf(submittedValue); + + // Try to get user instance from it + companyEmployee = FinancialsCompanyEmployeeConverter.COMPANY_EMPLOYEE_BEAN.findCompanyEmployeeById(employeeId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final CompanyEmployeeNotFoundException 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 companyEmployee; + } + + @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 Employee)) { + // Not same interface + throw new IllegalArgumentException(MessageFormat.format("value[]={0} does not implement Employee.", value.getClass().getSimpleName())); //NOI18N + } + + // Return id number + return String.valueOf(((Employee) value).getEmployeeId()); + } + +} diff --git a/src/java/org/mxchange/jfinancials/converter/businesscontact/FinancialsBusinessContactConverter.java b/src/java/org/mxchange/jfinancials/converter/businesscontact/FinancialsBusinessContactConverter.java deleted file mode 100644 index f22fe9cd..00000000 --- a/src/java/org/mxchange/jfinancials/converter/businesscontact/FinancialsBusinessContactConverter.java +++ /dev/null @@ -1,115 +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 . - */ -package org.mxchange.jfinancials.converter.businesscontact; - -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.jcontacts.contact.Contact; -import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData; -import org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote; -import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataNotFoundException; - -/** - * Converter for contact id <-> valid business contact instance - *

- * @author Roland Häder - */ -@FacesConverter (value = "BusinessContactConverter") -public class FinancialsBusinessContactConverter implements Converter { - - /** - * Business contact EJB - */ - private static BusinessDataSessionBeanRemote BUSINESS_CONTACT_BEAN; - - /** - * Default constructor - */ - public FinancialsBusinessContactConverter () { - } - - @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; - } - - // Is the bean there? - // @TODO Requires this synchronization or is it (sync) confusing the container? - if (null == FinancialsBusinessContactConverter.BUSINESS_CONTACT_BEAN) { - // Try to get it - try { - // Get initial context - Context initialContext = new InitialContext(); - - // ... and user controller - FinancialsBusinessContactConverter.BUSINESS_CONTACT_BEAN = (BusinessDataSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote"); //NOI18N - } catch (final NamingException ex) { - // Continue to throw it - throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N - } - } - - // Init instance - BusinessBasicData businessContact = null; - - try { - // Try to parse the value as long - Long contactId = Long.valueOf(submittedValue); - - // Try to get user instance from it - businessContact = FinancialsBusinessContactConverter.BUSINESS_CONTACT_BEAN.findBusinessDataById(contactId); - } catch (final NumberFormatException ex) { - // Throw again - throw new ConverterException(ex); - } catch (final BusinessDataNotFoundException 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 businessContact; - } - - @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 Contact)) { - // Not same interface - throw new IllegalArgumentException(MessageFormat.format("value[]={0} does not implement Contact.", value.getClass().getSimpleName())); //NOI18N - } - - // Return id number - return String.valueOf(((BusinessBasicData) value).getBusinessDataId()); - } - -} diff --git a/src/java/org/mxchange/jfinancials/converter/company_employee/FinancialsCompanyEmployeeConverter.java b/src/java/org/mxchange/jfinancials/converter/company_employee/FinancialsCompanyEmployeeConverter.java deleted file mode 100644 index 645fc220..00000000 --- a/src/java/org/mxchange/jfinancials/converter/company_employee/FinancialsCompanyEmployeeConverter.java +++ /dev/null @@ -1,114 +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 . - */ -package org.mxchange.jfinancials.converter.company_employee; - -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.jcontactsbusiness.employee.CompanyEmployeeSessionBeanRemote; -import org.mxchange.jcontactsbusiness.employee.Employee; -import org.mxchange.jcontactsbusiness.exceptions.employee.CompanyEmployeeNotFoundException; - -/** - * Converter for converting company employee to and from id number - *

- * @author Roland Häder - */ -@FacesConverter (value = "CompanyEmployeeConverter") -public class FinancialsCompanyEmployeeConverter implements Converter { - - /** - * CompanyEmployee EJB - */ - private static CompanyEmployeeSessionBeanRemote COMPANY_EMPLOYEE_BEAN; - - /** - * Default constructor - */ - public FinancialsCompanyEmployeeConverter () { - } - - @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; - } - - // Is the bean there? - // @TODO Requires this synchronization or is it (sync) confusing the container? - if (null == FinancialsCompanyEmployeeConverter.COMPANY_EMPLOYEE_BEAN) { - // Try to get it - try { - // Get initial context - Context initialContext = new InitialContext(); - - // ... and user controller - FinancialsCompanyEmployeeConverter.COMPANY_EMPLOYEE_BEAN = (CompanyEmployeeSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/companyEmployee!org.mxchange.jcontactsbusiness.company_employee.CompanyEmployeeSessionBeanRemote"); //NOI18N - } catch (final NamingException ex) { - // Continue to throw it - throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N - } - } - - // Init instance - Employee companyEmployee = null; - - try { - // Try to parse the value as long - Long employeeId = Long.valueOf(submittedValue); - - // Try to get user instance from it - companyEmployee = FinancialsCompanyEmployeeConverter.COMPANY_EMPLOYEE_BEAN.findCompanyEmployeeById(employeeId); - } catch (final NumberFormatException ex) { - // Throw again - throw new ConverterException(ex); - } catch (final CompanyEmployeeNotFoundException 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 companyEmployee; - } - - @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 Employee)) { - // Not same interface - throw new IllegalArgumentException(MessageFormat.format("value[]={0} does not implement Employee.", value.getClass().getSimpleName())); //NOI18N - } - - // Return id number - return String.valueOf(((Employee) value).getEmployeeId()); - } - -}