⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customermanager.java

📁 ORACLE AQ sample 演示的如何出列
💻 JAVA
字号:
package oracle.otnsamples.AQ.Manager;

/**
 * @author  Rajat Gupta
 * @version 1.0
 *
 * Name of the Application        :  CustomerManager.java
 * Development Environment        :  Oracle 9i JDeveloper
 * Creation/Modification History  :
 *
 *    Rajat Gupta       15-Jan-2001      Created
 *
 */

// Servlet imports
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

// Util imports
import java.util.Hashtable;

// Other files
import oracle.otnsamples.AQ.Helper.CustomerHelper;

/**
 * This class is called for all the requests that originate from a customer.
 * This class with the help of other Helper classes can display the products
 * to be sold, update the contents of a shopping cart, add or delete a product
 * to it or order the contents
 * of the Shopping Cart.
 *
 * @see Manager.java
 */
public class CustomerManager implements Manager{

  /**
   * HttpServlet Session Object
   */
  HttpSession m_session;

  /**
   * Empty Constructor
   */
  public CustomerManager(){
  }

  /**
   * This method is called to display all the products that the
   * Retail Shop can sell. It adds these products to the Session
   * as a Hashtable. This method also adds an empty Hashtable to
   * the session which acts as the Shopping Cart.
   *
   * @param p_request HttpServlet Request Object
   * @exception Exception In case an unreported exception is thrown
   * @see CustomerHelper.java
   */
  public void displayProducts(HttpServletRequest p_request) throws Exception{
    setParameters(p_request);
    String user =(String)m_session.getAttribute("User");

    m_session.setAttribute("ProductsList", CustomerHelper.displayProducts(user));
    m_session.setAttribute("ShoppingCart", new Hashtable());

    return;
  }

  /**
   * This is an empty method. When for some particular request, no operation
   * has to be done, then this method is called.
   *
   * @exception Exception In case an unreported exception is thrown
   * @param p_request HttpServlet Request Object
   */
  public void updateRequest(HttpServletRequest p_request) throws Exception{
    return;
  }

  /**
   * This method is invoked when the customer wants to delete some
   * products from his shopping cart. It gets all the required parameters
   * from the session and request objects which are then passed to the
   * helper classes.
   *
   * @param p_request HttpServlet Request Object
   * @exception Exception In case an unreported exception is thrown
   * @see CustomerHelper.java
   */
  public void deleteFromCart(HttpServletRequest p_request) throws Exception{
    setParameters(p_request);
    String[] deleteProducts = p_request.getParameterValues("ProductsInSC");
    Hashtable shoppingCart = CustomerHelper.deleteFromShoppingCart(deleteProducts,
                                (Hashtable)m_session.getAttribute("ShoppingCart"));
    m_session.setAttribute("ShoppingCart", shoppingCart);

    return;
  }

  /**
   * This method is invoked if the customer wants to order all the products
   * added to his/her shopping cart. A SOAP message is created which is stored
   * in the request object. This SOAP message is sent as a request to the IDAP.
   *
   * @since CustomerHelper.java
   * @exception Exception In case an unreported exception is thrown
   * @param p_request HttpServlet Request Object
   */
  public void purchaseItems(HttpServletRequest p_request) throws Exception{
    setParameters(p_request);
    String soapMessage = CustomerHelper.createSOAPMessage((Hashtable)m_session.getAttribute("ShoppingCart"),
                                              (String)m_session.getAttribute("ID"));
    p_request.setAttribute("SoapMessage",soapMessage);

    return;
  }

  /**
   * This method is invoked if the customer wants to add some products
   * to his shopping cart.
   *
   * @param p_request HttpServlet Request Object
   * @exception Exception In case an unreported exception is thrown
   * @see CustomerHelper.java
   */
  public void addToShoppingCart(HttpServletRequest p_request) throws Exception{
    setParameters(p_request);
    String[] addProducts = p_request.getParameterValues("ProductsToSell");
    Hashtable shoppingCart = CustomerHelper.addToShoppingCart(addProducts,
                                (Hashtable)m_session.getAttribute("ProductsList"),
                                (Hashtable)m_session.getAttribute("ShoppingCart"));
    m_session.setAttribute("ShoppingCart", shoppingCart);

    return;
  }

  /**
   * This method is invoked if the customer wants to update the quantity
   * to be purchased for a particular product.
   *
   * @exception Exception In case an unreported exception is thrown
   * @param p_request HttpServlet Request Object
   * @see CustomerHelper.java
   */
  public void updateShoppingCart(HttpServletRequest p_request) throws Exception{
    setParameters(p_request);
    String[] updateProducts = p_request.getParameterValues("NoOfProducts");
    Hashtable shoppingCart = CustomerHelper.updateShoppingCart(updateProducts,
                                (Hashtable)m_session.getAttribute("ShoppingCart"));
    m_session.setAttribute("ShoppingCart", shoppingCart);

    return;
  }

  /**
   * This method just gets the session object from the request
   * object and stores it in a global variable to be used by other
   * methods.
   *
   * @param p_request HttpServlet Request Object
   * @exception Exception In case an unreported exception is thrown
   */
  private void setParameters(HttpServletRequest p_request) throws Exception{
    m_session = p_request.getSession(false);
    if (m_session == null){
      throw new Exception("AQ-1018");
    }

  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -