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

📄 trademanagementhelper.java

📁 Oracle的J2EE Sample
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * @author  : Pushkala
 * @version : 1.0
 *
 * Development Environment : Oracle9i JDeveloper
 *
 * Name of the File : TradeManagementHelper.java
 *
 * Creation / Modification History
 *    Pushkala        26-Apr-2002        Created
 *
 */
package oracle.otnsamples.ibfbs.trademanagement.helper;

// Required EJB Classes
import javax.ejb.CreateException;
import java.rmi.RemoteException;

// Utility classes
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Collection;
import java.util.Date;

// JNDI
import javax.naming.InitialContext;
import javax.naming.NamingException;

import java.sql.SQLException; // SQL
import javax.servlet.http.HttpServletRequest; // Required Servlet Classes

// Required TradeManagement classes
import oracle.otnsamples.ibfbs.trademanagement.ejb.TradeManagementSessionRemote;
import oracle.otnsamples.ibfbs.trademanagement.ejb.TradeManagementSessionHomeRemote;
import oracle.otnsamples.ibfbs.trademanagement.exception.TradeManagementEventException;
import oracle.otnsamples.ibfbs.trademanagement.helper.DateFormatter;

// Required UserManagement classes
import oracle.otnsamples.ibfbs.usermanagement.ejb.ContactInfo;
import oracle.otnsamples.ibfbs.usermanagement.ejb.AccountInfo;
import oracle.otnsamples.ibfbs.usermanagement.helper.UserManagementHelper;
import oracle.otnsamples.ibfbs.usermanagement.exception.ApplicationError;

// Required Admin classes
import oracle.otnsamples.ibfbs.admin.helper.StockSymbolHelper;
import oracle.otnsamples.ibfbs.admin.exception.AdminHelperException;

// Required Utility classes
import oracle.otnsamples.ibfbs.utils.ConnectionParams;

/**
 * This class is registered in the control.xml file of the application.
 * This forms the interface between the controller servlet and the model
 * where the business logic is embedded consisting of the
 * TradeManagementSessionFacadeBean which further accesses the Entity Beans.
 * This creates an instance of the TradeManagementSessionFacadeBean in the
 * constructor which can then be used in all the methods.
 *
 * @version 1.0
 * @since   1.0
 */
public class TradeManagementHelper {

  /** Reference to Remote interface */
  private TradeManagementSessionRemote     rmr  = null;

  /** Reference to Home interface */
  private TradeManagementSessionHomeRemote rmrh = null;

  /** Instance of StockSymbolHelper */
  private StockSymbolHelper ssh = null;

  /** Instance of UserManagementHelper */
  private UserManagementHelper umh = null;

  private Hashtable connHash = null;

  /**
   * Constructor of the class. Here the initialize method is called.
   */
  public TradeManagementHelper() {
    initialize();
  }

  /**
   * Initialization method used to initialize the Home and Remote
   * Interfaces of TradeManagementSessionFacadeBean. Here the instance
   * of TradeManagementSessionFacadeBean is created and stored in the
   * global variable.
   * @since 1.0
   */
  private void initialize() {

    if (rmr == null || rmrh == null) {

      try {

        InitialContext ic = new InitialContext();

        // Look up the TradeManagementSessionFacadeBean
        rmrh = (TradeManagementSessionHomeRemote)
                ic.lookup("java:comp/env/ejb/TradeManagementSessionHomeRemote");

        rmr = rmrh.create();

        // Instantiate StockSymbolHelper
        ssh = new StockSymbolHelper();

        // Instantiate UserManagementHelper
        umh = new UserManagementHelper();

      } catch(RemoteException ne) {
        ne.printStackTrace();
      } catch(CreateException ce) {
        ce.printStackTrace();
      } catch(NamingException ce) {
        ce.printStackTrace();
      } catch(Exception ex) {
        ex.printStackTrace();
      }
    }

    if(connHash == null)   {
      connHash = new Hashtable();
      connHash.put("EXCHQCONNFACTORY", ConnectionParams.exchangeQueueConnFactory);
      connHash.put("EXCHQUEUE", ConnectionParams.exchangeQueue);
    }
    
  }

  /**
   * This method calls the method in TradeManagementSessionFacadeBean
   * to get the Portfolio details corresponding to the Account Number
   * and then returns the obtained Collection.
   *
   * @param accountNo     Account Number
   * @param recordNumber  Record Number
   * @param linesPerPage  Lines Per Page
   * @return The Collection of Portfolio Information
   * @exception TradeManagementEventException
   * @since 1.0
   */
  private Collection getPortfolioInfo(Integer accountNo,
                                      String recordNumber,
                                      int linesPerPage)
      throws TradeManagementEventException {

    try {

      // Access the method of the Session Bean and return the Collection
      return rmr.getPortfolio(accountNo, recordNumber, linesPerPage);

    } catch(RemoteException re) {
      throw new TradeManagementEventException(
        "Remote Exception while getting Portfolio info : " + re.toString());
    }
  }

  /**
   * This method calls the method in the TradeManagementSessionFacadeBean
   * to get the Portfolio Valuation details corresponding to the
   * Account Number and returns the new Collection.
   *
   * @param accountNo     Account Number
   * @param recordNumber  Record Number
   * @param linesPerPage  Lines Per Page
   * @return The Collection of Portfolio Valuation Information
   * @exception TradeManagementEventException
   * @since 1.0
   */
  private Collection getPortfolioValuation(Integer accountNo,
                                           String recordNumber,
                                           int linesPerPage)
      throws TradeManagementEventException {

    try {

      // Access the method of the Session Bean and return the Collection
      return rmr.getPortfolioValuation(accountNo, recordNumber, linesPerPage);

    } catch(RemoteException re) {
      throw new TradeManagementEventException(
        "Remote Exception while getting Portfolio Valuation info : "
        + re.toString());
    }

  }

  /**
   * This method calls the method in the TradeManagementSessionFacadeBean to
   * get the Trade details corresponding to the input Account Number and then
   * returns the obtained Collection.
   *
   * @param accountNo     Account Number
   * @param recordNumber  Record Number
   * @param linesPerPage  Lines Per Page
   * @return The Collection of Trade Details Information
   * @exception TradeManagementEventException
   * @since 1.0
   */
  private Collection getTradeDetailsInfo(Integer accountNo,
                                         String recordNumber,
                                         int linesPerPage)
      throws TradeManagementEventException {

    try {

      // Access the method of the Session Bean and return the Collection
      return rmr.getTradeDetails(accountNo, recordNumber, linesPerPage);

    } catch(RemoteException re) {
      throw new TradeManagementEventException(
        "Remote Exception while getting Trade Details info : " + re.toString());
    }
  }

  /**
   * This method is registered in control.xml and will be called in the
   * controller servlet using Reflection to get the values required to be
   * displayed in the JSPs invoked by the client. This method calls the
   * methods in the same class to get Portfolio details along with Valuation
   * details, Account Information. This then creates a Hashmap of the
   * retrieved values and returns it to the calling JSP where it is displayed.
   *
   * @param req HttpServletRequest
   * @return The Hashmap containing the Portfolio Valuation Information
   *         and User Account Information
   * @exception TradeManagementEventException
   * @since 1.0
   */
  public HashMap populatePortfolioValuation(HttpServletRequest req)
      throws TradeManagementEventException {

    HashMap hm = new HashMap();

    // The User Account Number is retrieved from the session attribute
    Integer acctNo = (Integer)req.getSession().getAttribute("LOGIN.RESPONSE");

    // Access the method of the Session Bean and set the values in the Hashmap
    AccountInfo acInfo = (AccountInfo)getAccountInfo(acctNo);

    String recordNum = req.getParameter("RECORDNUM");

    if (recordNum == null) recordNum = "1";

    hm.put("ACCOUNTINFO",        acInfo);
    hm.put("PORTFOLIOVALUATION",
           getPortfolioValuation(acctNo, recordNum,
                                 acInfo.getLinesPerPage().intValue()));

    return hm;
  }

  /**
   * This method is registered in control.xml and will be called in the
   * controller servlet using Reflection to get the values required to be
   * displayed in the JSPs invoked by the client. This method calls the
   * methods in the same class to get Portfolio details, Account Information.
   * This then creates a Hashmap of the retrieved values and returns it to
   * the calling JSP where it is displayed.
   *
   * @param req HttpServletRequest
   * @return The Hashmap containing the Portfolio Information
   *         and User Account Information
   * @exception TradeManagementEventException
   * @since 1.0
   */
  public HashMap populatePortfolio(HttpServletRequest req)
      throws TradeManagementEventException {

    HashMap hm = new HashMap();

    // The User Account Number is retrieved from the session attribute
    Integer acctNo = (Integer)req.getSession().getAttribute("LOGIN.RESPONSE");

    // Access the method of the Session Bean and set the values in the Hashmap
    AccountInfo acInfo = (AccountInfo)getAccountInfo(acctNo);

    String recordNum = req.getParameter("RECORDNUM");

    if (recordNum == null) recordNum = "1";

    hm.put("ACCOUNTINFO",   acInfo);
    hm.put("PORTFOLIOINFO",
           getPortfolioInfo(acctNo, recordNum,
                            acInfo.getLinesPerPage().intValue()));

    return hm;
  }

  /**
   * This method returns the Account Information of the logged in user.
   *
   * @param accountNo User Account Number
   * @return The Account Information as a Value Object AccountInfo
   * @exception TradeManagementEventException
   * @since 1.0
   */
  private AccountInfo getAccountInfo(Integer accountNo)
      throws TradeManagementEventException {

    AccountInfo aInfo = null;

    try {
      // Get the Account Information of the User, Lines Per Page is required!

⌨️ 快捷键说明

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