]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Introduced getter + consumer remote bean lookup
authorRoland Haeder <roland@mxchange.org>
Mon, 7 Sep 2015 09:53:00 +0000 (11:53 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 7 Sep 2015 09:53:00 +0000 (11:53 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java
src/java/org/mxchange/pizzaapplication/beans/customer/PizzaServiceCustomerWebBean.java

index 3b815a8f154a2f9467bd64bab9df0d1ac6923da9..d6e49ac499bb64acab96dcf9cbe1d4e2fbcc5aa3 100644 (file)
@@ -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<Product> 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<Product> 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<Product> 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<Product> 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<Category> 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<Category> 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;
+       }
 }
index 9c6a75e54fa177f2d1ae672b61f70b36b17265a6..d0fb08ad23dd404166bb804218470c3079fa108b 100644 (file)
@@ -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