From: Roland Haeder Date: Mon, 7 Sep 2015 09:53:00 +0000 (+0200) Subject: Introduced getter + consumer remote bean lookup X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9a1c797e8a7e7e36280f0ca0d359581fced7dfc7;p=pizzaservice-war.git Introduced getter + consumer remote bean lookup Signed-off-by:Roland Häder --- diff --git a/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java index 3b815a8f..d6e49ac4 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java @@ -51,7 +51,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe * Remote bean */ @EJB - private final ShopSessionBeanRemote remote; + private final ShopSessionBeanRemote shop; /** * Initializer block @@ -73,7 +73,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe InitialContext context = new InitialContext(); // Try to lookup the bean - this.remote = (ShopSessionBeanRemote) context.lookup("ejb/stateless-shop"); //NOI18N + this.shop = (ShopSessionBeanRemote) context.lookup("ejb/stateless-shop"); //NOI18N } @Override @@ -86,7 +86,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe @Override public Iterator getAvailableProductsIterator () throws FacesException { try { - return this.remote.getAvailableProductsIterator(); + return this.getShop().getAvailableProductsIterator(); } catch (final RemoteException ex) { // Continue to throw throw new FacesException(ex); @@ -96,7 +96,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe @Override public Iterator getAllProductsIterator () throws FacesException { try { - return this.remote.getAllProductsIterator(); + return this.getShop().getAllProductsIterator(); } catch (final RemoteException ex) { // Continue to throw throw new FacesException(ex); @@ -106,7 +106,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe @Override public Deque getAvailableProducts () throws FacesException { try { - return this.remote.getAvailableProducts(); + return this.getShop().getAvailableProducts(); } catch (final RemoteException ex) { // Continue to throw throw new FacesException(ex); @@ -116,7 +116,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe @Override public Deque getAllProducts () throws FacesException { try { - return this.remote.getAllProducts(); + return this.getShop().getAllProducts(); } catch (final RemoteException ex) { // Continue to throw throw new FacesException(ex); @@ -126,7 +126,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe @Override public Iterator getAllCategoriesIterator () throws FacesException { try { - return this.remote.getAllCategoriesIterator(); + return this.getShop().getAllCategoriesIterator(); } catch (final RemoteException ex) { // Continue to throw throw new FacesException(ex); @@ -136,7 +136,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe @Override public Deque getAllCategories () throws FacesException { try { - return this.remote.getAllCategories(); + return this.getShop().getAllCategories(); } catch (final RemoteException ex) { // Continue to throw throw new FacesException(ex); @@ -146,7 +146,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe @Override public void doAdminAddCategory (final Category category) throws FacesException { try { - this.remote.doAdminAddCategory(category); + this.getShop().doAdminAddCategory(category); } catch (final IOException | CategoryTitleAlreadyUsedException ex) { // Continue to throw throw new FacesException(ex); @@ -156,10 +156,19 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe @Override public void doAdminAddProduct (final Product product) throws FacesException { try { - this.remote.doAdminAddProduct(product); + this.getShop().doAdminAddProduct(product); } catch (final IOException | ProductTitleAlreadyUsedException ex) { // Continue to throw throw new FacesException(ex); } } + + /** + * Getter for shop remote bean + * + * @return Remote shop bean + */ + private ShopSessionBeanRemote getShop () { + return this.shop; + } } diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaServiceCustomerWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaServiceCustomerWebBean.java index 9c6a75e5..d0fb08ad 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaServiceCustomerWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaServiceCustomerWebBean.java @@ -20,6 +20,8 @@ import javax.annotation.PostConstruct; import javax.ejb.EJB; import javax.enterprise.context.SessionScoped; import javax.inject.Named; +import javax.naming.InitialContext; +import javax.naming.NamingException; import org.mxchange.jcoreee.beans.BaseFrameworkBean; import org.mxchange.jshopeelib.beans.remote.customer.CustomerSessionBeanRemote; @@ -40,12 +42,19 @@ public class PizzaServiceCustomerWebBean extends BaseFrameworkBean implements Cu * Remote customer bean */ @EJB - private CustomerSessionBeanRemote customer; + private final CustomerSessionBeanRemote customer; /** * Default constructor + * + * @throws javax.naming.NamingException If something happens? */ - public PizzaServiceCustomerWebBean () { + public PizzaServiceCustomerWebBean () throws NamingException { + // Get initial context + InitialContext context = new InitialContext(); + + // Try to lookup + this.customer = (CustomerSessionBeanRemote) context.lookup("ejb/stateless-consumer"); } @Override