From: Roland Haeder Date: Sun, 10 Apr 2016 12:40:44 +0000 (+0200) Subject: moved to new place X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=38b7c491d01a828a107da03511fbafc7cb6651f2;p=pizzaservice-war.git moved to new place --- diff --git a/src/java/org/mxchange/jshopcore/model/category/PizzaCategoryConverter.java b/src/java/org/mxchange/jshopcore/model/category/PizzaCategoryConverter.java deleted file mode 100644 index 9df4097b..00000000 --- a/src/java/org/mxchange/jshopcore/model/category/PizzaCategoryConverter.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * 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.jshopcore.model.category; - -import java.text.MessageFormat; -import java.util.List; -import java.util.Objects; -import javax.faces.component.UIComponent; -import javax.faces.context.FacesContext; -import javax.faces.convert.Converter; -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; - -/** - * A converter for transfering category objects - *

- * @author Roland Haeder - */ -@FacesConverter ("CategoryConverter") -public class PizzaCategoryConverter implements Converter { - - /** - * Category EJB - */ - private CategorySessionBeanRemote categoryBean; - - /** - * Logger instance - */ - @Log - private LoggerBeanLocal loggerBeanLocal; - - /** - * Default constructor - */ - public PizzaCategoryConverter () { - // Try to get it - try { - // Get initial context - Context context = new InitialContext(); - - // Lookup category bean - this.categoryBean = (CategorySessionBeanRemote) context.lookup("java:global/jshop-ejb/category!org.mxchange.jshopcore.model.category.CategorySessionBeanRemote"); //NOI18N - - // Lookup logger - this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //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 - this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2} - CALLED!", context, component, submittedValue)); //NOI18N - - // Get full list - List categoryList = this.categoryBean.getAllCategories(); - - // Is the value null or empty? - if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { - // Trace message - this.loggerBeanLocal.logTrace("getAsObject: submittedValue is null or empty - EXIT!"); //NOI18N - - // Return null - return null; - } - - // Init value - Category category = null; - - // Try this better - try { - // Convert it to long - Long categoryId = Long.parseLong(submittedValue); - - // Category id should not be below 1 - assert (categoryId > 0) : "categoryId is smaller than one: " + categoryId; //NOI18N - - // Debug message - this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: categoryId={0}", categoryId)); //NOI18N - - // Try to find it - for (final Category cat : categoryList) { - // Is the id the same? (null-safe) - if (Objects.equals(cat.getCategoryId(), categoryId)) { - // Found it - category = cat; - break; - } - } - - // Debug message - this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: category={0}", category)); //NOI18N - } catch (final NumberFormatException ex) { - // Log exception (maybe to much?) - this.loggerBeanLocal.logException(ex); - } - - // Trace message - this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: category={0} - EXIT!", category)); //NOI18N - - // Return it - return category; - } - - @Override - public String getAsString (final FacesContext context, final UIComponent component, final Object value) { - // Is the object null? - if (null == value) { - // Is null - return ""; //NOI18N - } else if (!(value instanceof Category)) { - // Not same interface - throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement Category.", value)); //NOI18N - } - - // Return category id - return String.valueOf(((Category) value).getCategoryId()); - } - -} diff --git a/src/java/org/mxchange/pizzaapplication/converter/category/PizzaCategoryConverter.java b/src/java/org/mxchange/pizzaapplication/converter/category/PizzaCategoryConverter.java new file mode 100644 index 00000000..1e9ba561 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/converter/category/PizzaCategoryConverter.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * 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.pizzaapplication.converter.category; + +import java.text.MessageFormat; +import java.util.List; +import java.util.Objects; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +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.jshopcore.model.category.Category; +import org.mxchange.jshopcore.model.category.CategorySessionBeanRemote; + +/** + * A converter for transfering category objects + *

+ * @author Roland Haeder + */ +@FacesConverter ("CategoryConverter") +public class PizzaCategoryConverter implements Converter { + + /** + * Category EJB + */ + private CategorySessionBeanRemote categoryBean; + + /** + * Logger instance + */ + @Log + private LoggerBeanLocal loggerBeanLocal; + + /** + * Default constructor + */ + public PizzaCategoryConverter () { + // Try to get it + try { + // Get initial context + Context context = new InitialContext(); + + // Lookup category bean + this.categoryBean = (CategorySessionBeanRemote) context.lookup("java:global/jshop-ejb/category!org.mxchange.jshopcore.model.category.CategorySessionBeanRemote"); //NOI18N + + // Lookup logger + this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //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 + this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2} - CALLED!", context, component, submittedValue)); //NOI18N + + // Get full list + List categoryList = this.categoryBean.getAllCategories(); + + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Trace message + this.loggerBeanLocal.logTrace("getAsObject: submittedValue is null or empty - EXIT!"); //NOI18N + + // Return null + return null; + } + + // Init value + Category category = null; + + // Try this better + try { + // Convert it to long + Long categoryId = Long.parseLong(submittedValue); + + // Category id should not be below 1 + assert (categoryId > 0) : "categoryId is smaller than one: " + categoryId; //NOI18N + + // Debug message + this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: categoryId={0}", categoryId)); //NOI18N + + // Try to find it + for (final Category cat : categoryList) { + // Is the id the same? (null-safe) + if (Objects.equals(cat.getCategoryId(), categoryId)) { + // Found it + category = cat; + break; + } + } + + // Debug message + this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: category={0}", category)); //NOI18N + } catch (final NumberFormatException ex) { + // Log exception (maybe to much?) + this.loggerBeanLocal.logException(ex); + } + + // Trace message + this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: category={0} - EXIT!", category)); //NOI18N + + // Return it + return category; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final Object value) { + // Is the object null? + if (null == value) { + // Is null + return ""; //NOI18N + } else if (!(value instanceof Category)) { + // Not same interface + throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement Category.", value)); //NOI18N + } + + // Return category id + return String.valueOf(((Category) value).getCategoryId()); + } + +}