]> git.mxchange.org Git - pizzaservice-war.git/blobdiff - src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java
updated jcore-ee-logger.jar, jshop-ee-lib.jar + added some stuff + renamed variable...
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / controller / PizzaServiceWebBean.java
index dd896a6c86e1af9507e3ba4b79e2c6a88ad650c1..c184dbcf4fb2d503cb2c5f78f887c24eb9606299 100644 (file)
  */
 package org.mxchange.pizzaapplication.beans.controller;
 
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
 import java.rmi.RemoteException;
 import java.sql.SQLException;
-import java.text.MessageFormat;
 import java.util.Deque;
-import java.util.Iterator;
+import java.util.Queue;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.SessionScoped;
 import javax.faces.FacesException;
 import javax.inject.Named;
-import org.mxchange.jshopcore.exceptions.CategoryTitleAlreadyUsedException;
-import org.mxchange.jshopcore.exceptions.ProductTitleAlreadyUsedException;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jcoreee.beans.BaseFrameworkBean;
 import org.mxchange.jshopcore.model.category.Category;
+import org.mxchange.jshopcore.model.category.CategorySessionBeanRemote;
+import org.mxchange.jshopcore.model.category.ProductCategory;
 import org.mxchange.jshopcore.model.product.Product;
-import org.mxchange.jshopejb.beans.BaseFrameworkBean;
+import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote;
 
 /**
  * Main application class
@@ -44,159 +44,85 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe
        /**
         * Serial id
         */
-       private static final long serialVersionUID = 58137539530279L;
+       private static final long serialVersionUID = 58_137_539_530_279L;
 
        /**
-        * Initializer block
+        * Remote bean for categories
         */
-       {
-               // Get new application instance
-               this.getLogger().debug("INITIALIZER!"); //NOI18N
-       }
+       private final CategorySessionBeanRemote category;
 
        /**
-        * Default constructor
+        * Remote bean for products
         */
-       public PizzaServiceWebBean () {
-               this.getLogger().trace("CALLED!"); //NOI18N
-       }
+       private final ProductSessionBeanRemote product;
 
-       @Override
-       @PostConstruct
-       public void init () throws FacesException {
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("application={0} - CALLED!", this.getApplication())); //NOI18N
-
-               // Must not be null
-               if (this.getApplication() == null) {
-                       // Abort here
-                       throw new NullPointerException("application is null"); //NOI18N
-               }
-
-               try {
-                       // Call init method
-                       this.app.init();
-               } catch (final SQLException | IOException ex) {
-                       // Continue to throw
-                       throw new FacesException(ex);
-               }
-       }
-
-       @Override
-       @Deprecated
-       public String getPrintableProductAvailability (final Product product) {
-               return this.app.getPrintableProductAvailability(product);
-       }
+       /**
+        * Default constructor
+        * 
+        * @throws javax.naming.NamingException Something happened here?
+        */
+       public PizzaServiceWebBean () throws NamingException {
+               // Get initial context
+               InitialContext context = new InitialContext();
 
-       @Override
-       public Iterator<Product> getAvailableProductsIterator () throws RemoteException {
-               try {
-                       return this.app.getAvailableProductsIterator();
-               } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
-                       // Continue to throw
-                       throw new RemoteException("getAvailableProductsIterator() failed", ex);
-               }
-       }
+               // Try to lookup the bean
+               this.category = (CategorySessionBeanRemote) context.lookup("ejb/stateless-category"); //NOI18N
 
-       @Override
-       public Iterator<Product> getAllProductsIterator () throws RemoteException {
-               try {
-                       return this.app.getAllProductsIterator();
-               } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
-                       // Continue to throw
-                       throw new RemoteException("getAllProductsIterator() failed.", ex);
-               }
+               // Try to lookup the bean
+               this.product = (ProductSessionBeanRemote) context.lookup("ejb/stateless-product"); //NOI18N
        }
 
-       @Override
-       public Deque<Product> getAvailableProducts () throws RemoteException {
-               try {
-                       return this.app.getAvailableProducts();
-               } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
-                       // Continue to throw
-                       throw new RemoteException("getAvailableProducts() failed.", ex);
-               }
-       }
-
-       @Override
-       public Deque<Product> getAllProducts () throws RemoteException {
-               try {
-                       return this.app.getAllProducts();
-               } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
-                       // Continue to throw
-                       throw new RemoteException("getAllProducts() failed", ex);
-               }
+       @PostConstruct
+       public void init () throws RuntimeException {
+               // Call super init first
+               super.genericInit();
        }
 
        @Override
-       public Iterator<Category> getAllCategoriesIterator () throws RemoteException {
+       public Queue<Product> getAvailableProducts () throws FacesException {
                try {
-                       return this.app.getAllCategoriesIterator();
-               } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+                       return this.getProduct().getAvailableProducts();
+               } catch (final RemoteException ex) {
                        // Continue to throw
-                       throw new RemoteException("getAllCategoriesIterator() failed.", ex);
+                       throw new FacesException(ex);
                }
        }
 
        @Override
-       public Deque<Category> getAllCategories () throws RemoteException {
+       public Queue<Category> getAllCategories () throws FacesException {
                try {
-                       return this.app.getAllCategories();
-               } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
-                       // Continue to throw
-                       throw new RemoteException("getAllCategories() failed.", ex);
-               }
-       }
+                       // Fake zero category
+                       Category c = new ProductCategory(0L, "Ist oberste Kategorie", 0L);
 
-       @Override
-       public void doAdminAddCategory (final Category category) throws RemoteException, CategoryTitleAlreadyUsedException {
-               try {
-                       this.app.doAdminAddCategory(category);
-               } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
-                       // Continue to throw
-                       throw new RemoteException("doAdminAddCategory() failed.", ex);
-               }
-       }
+                       // Get List back
+                       Deque<Category> deque = this.getCategory().getAllCategories();
 
-       @Override
-       public void doAdminAddProduct (final Product product) throws RemoteException, ProductTitleAlreadyUsedException {
-               try {
-                       this.app.doAdminAddProduct(product);
-               } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
-                       // Continue to throw
-                       throw new RemoteException("doAdminAddProduct() failed.", ex);
-               }
-       }
+                       // Add fake category
+                       deque.addFirst(c);
 
-       @Override
-       @Deprecated
-       public String getPrintableProduktCategory (final Product product) throws RemoteException {
-               try {
-                       return this.app.getPrintableProductCategory(product);
-               } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+                       // Return it
+                       return deque;
+               } catch (final SQLException ex) {
                        // Continue to throw
-                       throw new RemoteException("getPrintableProduktCategory() failed.", ex);
+                       throw new FacesException(ex);
                }
        }
 
-       @Override
-       @Deprecated
-       public void doAdminHandleProductForms () throws RemoteException {
-               // Deprecated method called
-               throw new UnsupportedOperationException("Deprecated method called");
-       }
-
-       @Override
-       @Deprecated
-       public void doAdminHandleCategoryForms () throws RemoteException {
-               // Deprecated method called
-               throw new UnsupportedOperationException("Deprecated method called");
+       /**
+        * Getter for shop remote bean
+        *
+        * @return Remote shop bean
+        */
+       private CategorySessionBeanRemote getCategory () {
+               return this.category;
        }
 
-       @Override
-       @Deprecated
-       public String generateLinkForParent (final Category category) {
-               // Deligate to app
-               return this.app.generateLinkForParent(category);
+       /**
+        * Getter for shop remote bean
+        *
+        * @return Remote shop bean
+        */
+       private ProductSessionBeanRemote getProduct () {
+               return this.product;
        }
 }