]> git.mxchange.org Git - pizzaservice-war.git/blobdiff - src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java
updated jshop-ee-jar + made first calls
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / controller / PizzaServiceWebBean.java
index e69bba25a0cdf564b225f3158becde83d358e013..41f61484673a5c85557bc44be4daf057de3df8b8 100644 (file)
@@ -23,14 +23,18 @@ import java.sql.SQLException;
 import java.util.Deque;
 import java.util.Iterator;
 import javax.annotation.PostConstruct;
+import javax.ejb.EJB;
 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.jshopcore.exceptions.CategoryTitleAlreadyUsedException;
 import org.mxchange.jshopcore.exceptions.ProductTitleAlreadyUsedException;
 import org.mxchange.jshopcore.model.category.Category;
 import org.mxchange.jshopcore.model.product.Product;
+import org.mxchange.jshopeelib.beans.remote.shop.ShopSessionBeanRemote;
 
 /**
  * Main application class
@@ -45,6 +49,12 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe
         */
        private static final long serialVersionUID = 58137539530279L;
 
+       /**
+        * Remote bean
+        */
+       @EJB
+       private final ShopSessionBeanRemote remote;
+
        /**
         * Initializer block
         */
@@ -55,9 +65,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"); //NOI18N
        }
 
        @Override
@@ -68,20 +86,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<Product> 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 +101,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe
        @Override
        public Iterator<Product> 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 +111,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe
        @Override
        public Deque<Product> 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 +121,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe
        @Override
        public Deque<Product> 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 +131,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe
        @Override
        public Iterator<Category> 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 +141,7 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe
        @Override
        public Deque<Category> 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 +151,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 +161,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);