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

📄 jsphelper.java

📁 BEA WebLogic Server 8.1大全 = BEA webLogic server 8.1 unleashed (美) Mark Artiges等著 袁毅 ... [等] 译 eng
💻 JAVA
字号:
/* 
 * WebLogic Server Unleashed
 * 
 */


package com.wlsunleashed.ejb.session.jspclasses;

import com.wlsunleashed.ejb.session.stateful.AirlineShoppingCartException;
import com.wlsunleashed.ejb.session.stateful.AirlineShoppingCartLocalHome;
import com.wlsunleashed.ejb.session.stateful.AirlineShoppingCartLocalObject;

import java.util.Properties;
import java.util.Vector;

import javax.ejb.CreateException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;


/**
 * This class Contains some helper methods for the JSP Clients for the Session
 * EJB examples
 * 
 * @version 1.0
 */
public class JSPHelper {
    /** Stores the Local object of the shopping cart */
    private AirlineShoppingCartLocalObject asclo = null;

    /** Stores the Initial Context */
    private Context ctx = null;

    /**
     * Creates a new JSPHelper object.
     */
    public JSPHelper() {
    }

    /**
     * Returns the total cost of the reservation
     * 
     * @return The total cost (double)
     */
    public double getTotalCost() {
        if (asclo == null) {
            return 0;
        }

        return asclo.getTotalCost();
    }

    /**
     * Initializes the client
     * 
     * @throws NamingException Thrown when any naming  exception occurs while
     *         looking up the initial context
     * @throws CreateException Thrown when any error  occurs while creating the
     *         bean instance
     */
    public void initClient()
                    throws NamingException, CreateException {
        ctx = new InitialContext();

        /*
           Object obj = 
                           ctx.lookup("AirlineShoppingCartBean");
           AirlineShoppingCartRemoteHome ascrh = 
                   (AirlineShoppingCartRemoteHome) PortableRemoteObject.narrow(
                                   obj, AirlineShoppingCartRemoteHome.class);
           
           ascro = 
                   (AirlineShoppingCartRemoteObject) ascrh.create(
                           origin,
                           destination) ;
         */
        AirlineShoppingCartLocalHome asclh = (AirlineShoppingCartLocalHome) ctx.lookup(
                                                     "LocalAirlineShoppingCartBean");

        asclo = asclh.create();
    }

    /**
     * Reserves seats for the given flights
     * 
     * @param flightNumber Flight number
     * @param numSeats Number of seats
     * 
     * @throws NamingException Thrown when any error occurs while getting the
     *         initial context
     * @throws CreateException Thrown when any error occurs while creating the
     *         bean instance
     * @throws AirlineShoppingCartException Thrown when any business exception
     *         occurs
     */
    public void reserveSeats(int flightNumber, int numSeats)
                      throws NamingException, CreateException, 
                             AirlineShoppingCartException {
        if (asclo == null) {
            initClient();
        }

        asclo.setFlightNumber(flightNumber);
        asclo.setNumSeats(numSeats);
        asclo.reserveSeats();
    }

    /**
     * Searches flights based on the given origin and destination
     * 
     * @param origin The origin airport
     * @param destination The destination airport
     * 
     * @return The list of flight information based on the  inputs
     * 
     * @throws NamingException Thrown when any error occurs while getting the
     *         initial context
     * @throws CreateException Thrown when any error occurs while creating the
     *         bean instance
     * @throws AirlineShoppingCartException Thrown when any business exception
     *         occurs
     */
    public Vector searchFlights(String origin, String destination)
                         throws NamingException, CreateException, 
                                AirlineShoppingCartException {
        if (asclo == null) {
            initClient();
        }

        asclo.setOrigin(origin);
        asclo.setDestination(destination);

        int[] flightNumbers = asclo.searchFlights();

        Properties props = null;
        Vector infos = new Vector();

        for (int i = 0; i < flightNumbers.length; i++) {
            asclo.setFlightNumber(flightNumbers[i]);
            infos.add(asclo.getFlightInfo());
        }

        return infos;
    }

    /**
     * Terminates the client connection (cleans resources)
     */
    public void termClient() {
        try {
            if (asclo != null) {
                asclo.remove();
            }

            if (ctx != null) {
                ctx.close();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

⌨️ 快捷键说明

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