From: Roland Haeder Date: Sat, 5 Sep 2015 13:51:44 +0000 (+0200) Subject: Continued a bit: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=95ad217ccc5bcafe553e759a528549695e3bb405;p=pizzaservice-war.git Continued a bit: - renamed getGenders() to allGenders() - tried to get initial context and lookup bean - the EJB methods allGenders() and selectableGenders() may now work? Signed-off-by:Roland Häder --- diff --git a/lib/jshop-ejb.jar b/lib/jshop-ejb.jar deleted file mode 100644 index 0ba207f1..00000000 Binary files a/lib/jshop-ejb.jar and /dev/null differ diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index b37418b1..76bf3058 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,4 +1,4 @@ -build.xml.data.CRC32=f043d149 +build.xml.data.CRC32=ff1dc0da build.xml.script.CRC32=82213886 build.xml.stylesheet.CRC32=651128d4@1.68.1.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. diff --git a/nbproject/project.xml b/nbproject/project.xml index 257793f7..53d981ae 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -14,6 +14,14 @@ ${file.reference.jcoreee.jar} WEB-INF/lib + + ${file.reference.jshop-core.jar} + WEB-INF/lib + + + ${reference.PizzaService-lib.jar} + WEB-INF/lib + ${file.reference.cdi-api.jar} WEB-INF/lib @@ -42,14 +50,6 @@ ${file.reference.log4j-web-2.3.jar} WEB-INF/lib - - ${file.reference.jshop-core.jar} - WEB-INF/lib - - - ${reference.PizzaService-lib.jar} - WEB-INF/lib - ${file.reference.jshop-ejb.jar} WEB-INF/lib diff --git a/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java index e69bba25..6949560f 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java @@ -26,7 +26,10 @@ import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; import javax.faces.FacesException; import javax.inject.Named; +import javax.naming.InitialContext; +import javax.naming.NamingException; import org.mxchange.jcoreee.beans.BaseFrameworkBean; +import org.mxchange.jshop.beans.shop.ShopSessionBeanRemote; import org.mxchange.jshopcore.exceptions.CategoryTitleAlreadyUsedException; import org.mxchange.jshopcore.exceptions.ProductTitleAlreadyUsedException; import org.mxchange.jshopcore.model.category.Category; @@ -45,6 +48,11 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe */ private static final long serialVersionUID = 58137539530279L; + /** + * Remote bean + */ + private final ShopSessionBeanRemote remote; + /** * Initializer block */ @@ -55,9 +63,17 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe /** * Default constructor + * + * @throws javax.naming.NamingException Something happened here? */ - public PizzaServiceWebBean () { + public PizzaServiceWebBean () throws NamingException { this.getLogger().trace("CALLED!"); //NOI18N + + // Get initial context + InitialContext context = new InitialContext(); + + // Try to lookup the bean + this.remote = (ShopSessionBeanRemote) context.lookup("ejb/stateless-shop"); } @Override @@ -68,20 +84,12 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe // Super call super.init(); - - try { - // Call init method - this.app.init(); - } catch (final SQLException | IOException ex) { - // Continue to throw - throw new FacesException(ex); - } } @Override public Iterator getAvailableProductsIterator () throws RemoteException { try { - return this.app.getAvailableProductsIterator(); + return this.remote.getAvailableProductsIterator(); } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw throw new RemoteException("getAvailableProductsIterator() failed", ex); @@ -91,7 +99,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe @Override public Iterator getAllProductsIterator () throws RemoteException { try { - return this.app.getAllProductsIterator(); + return this.remote.getAllProductsIterator(); } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw throw new RemoteException("getAllProductsIterator() failed.", ex); @@ -101,7 +109,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe @Override public Deque getAvailableProducts () throws RemoteException { try { - return this.app.getAvailableProducts(); + return this.remote.getAvailableProducts(); } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw throw new RemoteException("getAvailableProducts() failed.", ex); @@ -111,7 +119,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe @Override public Deque getAllProducts () throws RemoteException { try { - return this.app.getAllProducts(); + return this.remote.getAllProducts(); } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw throw new RemoteException("getAllProducts() failed", ex); @@ -121,7 +129,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe @Override public Iterator getAllCategoriesIterator () throws RemoteException { try { - return this.app.getAllCategoriesIterator(); + return this.remote.getAllCategoriesIterator(); } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw throw new RemoteException("getAllCategoriesIterator() failed.", ex); @@ -131,7 +139,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe @Override public Deque getAllCategories () throws RemoteException { try { - return this.app.getAllCategories(); + return this.remote.getAllCategories(); } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw throw new RemoteException("getAllCategories() failed.", ex); @@ -141,7 +149,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe @Override public void doAdminAddCategory (final Category category) throws RemoteException, CategoryTitleAlreadyUsedException { try { - this.app.doAdminAddCategory(category); + this.remote.doAdminAddCategory(category); } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw throw new RemoteException("doAdminAddCategory() failed.", ex); @@ -151,7 +159,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe @Override public void doAdminAddProduct (final Product product) throws RemoteException, ProductTitleAlreadyUsedException { try { - this.app.doAdminAddProduct(product); + this.remote.doAdminAddProduct(product); } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw throw new RemoteException("doAdminAddProduct() failed.", ex); diff --git a/src/java/org/mxchange/pizzaapplication/beans/enums/DataWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/enums/DataWebBean.java index 5fe8435d..076b02b2 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/enums/DataWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/enums/DataWebBean.java @@ -26,16 +26,18 @@ import org.mxchange.jcoreee.beans.FrameworkBean; * @author Roland Haeder */ public interface DataWebBean extends FrameworkBean { + /** * Getter for all genders as array * * @return All genders as array */ - public Gender[] getGenders (); + public Gender[] allGenders (); + /** * Getter for only selectable genders as array, UNKNOWN is not selectable * * @return All genders as array */ - public List getSelectableGenders (); + public List selectableGenders (); } diff --git a/src/java/org/mxchange/pizzaapplication/beans/enums/PizzaServiceDataWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/enums/PizzaServiceDataWebBean.java index 87ed577b..86f77a90 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/enums/PizzaServiceDataWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/enums/PizzaServiceDataWebBean.java @@ -17,12 +17,14 @@ package org.mxchange.pizzaapplication.beans.enums; import java.text.MessageFormat; -import java.util.Arrays; import java.util.List; import javax.enterprise.context.ApplicationScoped; import javax.inject.Named; +import javax.naming.InitialContext; +import javax.naming.NamingException; import org.mxchange.jcore.model.contact.gender.Gender; import org.mxchange.jcoreee.beans.BaseFrameworkBean; +import org.mxchange.jshop.beans.data.ShopDataBeanRemote; /** * A customer bean which hides the customer instance @@ -38,23 +40,41 @@ public class PizzaServiceDataWebBean extends BaseFrameworkBean implements DataWe */ private static final long serialVersionUID = 835482364189L; + /** + * Remote bean + */ + private final ShopDataBeanRemote remote; + + /** + * Default constructor + * + * @throws javax.naming.NamingException If something happens? + */ + public PizzaServiceDataWebBean () throws NamingException { + // Get initial context + InitialContext context = new InitialContext(); + + // Try to lookup bean + this.remote = (ShopDataBeanRemote) context.lookup("ejb/stateless-data"); + } + @Override - public Gender[] getGenders () { + public Gender[] allGenders () { // Trace message - this.getLogger().trace(MessageFormat.format("Genders={0} - EXIT!", Arrays.toString(Gender.values()))); + this.getLogger().trace("CALLED!"); // Return it - return Gender.values(); + return this.getRemote().allGenders(); } @Override - public List getSelectableGenders () { + public List selectableGenders () { // Trace message this.getLogger().trace("CALLED!"); //NOI18N // Init array // TODO Call EJB here? - List genders = null; + List genders = this.getRemote().selectableGenders(); // Trace message this.getLogger().trace(MessageFormat.format("genders={0} - EXIT!", genders)); //NOI18N @@ -62,4 +82,11 @@ public class PizzaServiceDataWebBean extends BaseFrameworkBean implements DataWe // Return it return genders; } + + /** + * @return the remote + */ + private ShopDataBeanRemote getRemote () { + return this.remote; + } }