EJBs: Session Beans (EJB Components)

You learned about session beans on Days 10 and 11. Listings C.28 C.33 are the detailed listings for each of the session beans described in Chapter 11 for the MVC application. These files are to be placed in the directory called ejb_components_src, discussed on Day 16.

Listing C.28 CustomerServiceAgentHome.java
 /******************************************************************************  * Class Name:CustomerServiceAgentHome.java  * Description:Home Interface for CustomerServiceAgent.  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.sessionbean; import javax.ejb.*; import java.rmi.RemoteException; public interface CustomerServiceAgentHome extends EJBHome {   public CustomerServiceAgentInterface create()   throws CreateException, RemoteException; } 
Listing C.29 CustomerServiceAgentInterface.java
 /******************************************************************************  * Class Name:CustomerServiceAgentInterface.java  * Description:Remote Interface for CustomerServiceAgent.  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.sessionbean; import javax.ejb.*; import java.rmi.RemoteException; import com.sams.learnweblogic7.airlines.businessobject.*; import com.sams.learnweblogic7.airlines.constants.*; import com.sams.learnweblogic7.airlines.exception.*; public interface CustomerServiceAgentInterface extends EJBObject {   public MVCAppValueObject authenticateUser(MVCAppValueObject objValue)   throws RemoteException, GenericException;   public MVCAppValueObject createUserProfile(MVCAppValueObject objValue)   throws RemoteException, GenericException;   public MVCAppValueObject viewAvailableFlights(MVCAppValueObject objValue)   throws RemoteException, GenericException; } 
Listing C.30 CustomerServiceAgentBean.java
 /******************************************************************************  * Class Name:CustomerServiceAgentBean.java  * Description:Bean Implementation for CustomerServiceAgent.  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.sessionbean; import javax.ejb.*; import java.util.*; import javax.naming.*; import javax.rmi.*; import com.sams.learnweblogic7.airlines.businessobject.*; import com.sams.learnweblogic7.airlines.constants.*; import com.sams.learnweblogic7.airlines.entitybean.*; import com.sams.learnweblogic7.airlines.exception.*; public class CustomerServiceAgentBean implements javax.ejb.SessionBean {   public CustomerServiceAgentBean()   {   }   // ---------------------------------------------------------------   // private fields   private SessionContext ctx;   private String sep=System.getProperty( "line.separator" );   // ---------------------------------------------------------------   // SessionBean interface implementation   public void ejbActivate()   {   }   public void ejbPassivate()   {   }   public void ejbRemove()   {   }   public void setSessionContext(SessionContext ctx)   {     this.ctx=ctx;   }   // ---------------------------------------------------------------   // create methods   public void ejbCreate()   {   }   // ---------------------------------------------------------------   // business methods   public MVCAppValueObject authenticateUser(MVCAppValueObject objValue)           throws GenericException   {     String errorDesc="";     PassengerHome passengerHomeObj=null;     PassengerInterface passengerRemoteObj=null;     MVCAppValueObject returnValueObject=null;     try     {       passengerHomeObj=lookupPassengerHome();       String profileID=               (String)objValue.get(JspFieldConstants.LOGIN_PAGE_USER_NAME);       String password=               (String)objValue.get(JspFieldConstants.LOGIN_PAGE_PASSWORD);       passengerRemoteObj=passengerHomeObj.findByPassword(profileID, password);     }catch(javax.ejb.ObjectNotFoundException e)     {       errorDesc="Error while Authenticating User               (Please check if User ID and Password are valid)" + sep;       throw new GenericException(errorDesc);     }     catch(Exception exp)     {       throw new GenericException(exp);     }     if (passengerRemoteObj==null)     {       errorDesc="Error while Authenticating User               (Please check if User ID and Password are valid)" + sep;       throw new GenericException(errorDesc);     }     try     {       returnValueObject=createPassengerMVCValueObject(passengerRemoteObj);         }catch(Exception exp)     {       errorDesc="Error while Authenticating User .... Internal error occurred"               + sep;       errorDesc=errorDesc + " Please try later ";       throw new GenericException(errorDesc,exp);     }     return returnValueObject;   }   public MVCAppValueObject createUserProfile(MVCAppValueObject objValue)           throws GenericException   {     String errorDesc="";     MVCAppValueObject valueObj=new MVCAppValueObject();     PassengerHome passengerHomeObj=null;     PassengerInterface passengerRemoteObj=null;     String profileID="";     String password="";     String firstName="";     String lastName="";     String address="";     String phoneNo="";     String emailID="";     String cardNo="";     String cardType="";     String ccMonth="";     String ccYear="";     try     {       passengerHomeObj=lookupPassengerHome();         }catch(Exception exp)     {       errorDesc="Error while creating the User Profile .... Internal error               occurred" + sep;       errorDesc=errorDesc + " Please try later ";       exp.printStackTrace();       throw new GenericException(errorDesc,exp);     }     profileID=             (String)objValue.get(JspFieldConstants.REGISTER_USER_PROFILE_PAGE             _USER_ID);     password=(String)objValue.             get(JspFieldConstants.REGISTER_USER_PROFILE_PAGE_PASSWORD);     firstName=(String)objValue.             get(JspFieldConstants.REGISTER_USER_PROFILE_PAGE_FIRST_NAME);     lastName=(String)objValue.             get(JspFieldConstants.REGISTER_USER_PROFILE_PAGE_LAST_NAME);     address=(String)objValue.             get(JspFieldConstants.REGISTER_USER_PROFILE_PAGE_ADDRESS);     phoneNo=(String)objValue.             get(JspFieldConstants.REGISTER_USER_PROFILE_PAGE_PHONE_NO);     emailID=(String)objValue.             get(JspFieldConstants.REGISTER_USER_PROFILE_PAGE_EMAIL_ADDRESS);     cardNo=(String)objValue.              get(JspFieldConstants.REGISTER_USER_PROFILE_PAGE_CC_NO);     cardType=(String)objValue.              get(JspFieldConstants.REGISTER_USER_PROFILE_PAGE_CC_TYPE);     ccMonth=(String)objValue.              get(JspFieldConstants.REGISTER_USER_PROFILE_PAGE_EXP_MONTH);     ccYear=(String)objValue.              get(JspFieldConstants.REGISTER_USER_PROFILE_PAGE_EXP_YEAR);     try     {       passengerRemoteObj=passengerHomeObj.findByPrimaryKey(profileID);     }catch(javax.ejb.ObjectNotFoundException e)     {       // here do nothing since this exception only means that the profileID       // does not exist and user can go ahead with the registration.     }     catch(Exception e)     {       errorDesc="Error while creating the User Profile ....               Internal error occurred" + sep;       errorDesc=errorDesc + " Please try later ";       throw new GenericException(errorDesc,e);     }     if (passengerRemoteObj !=null)     {       errorDesc="Error while creating the User Profile ....               User Name already exists " + sep;       errorDesc=errorDesc + " Please enter a different User Name ";       throw new GenericException(errorDesc);     }     try     {      passengerRemoteObj=(PassengerInterface)PortableRemoteObject.              narrow(passengerHomeObj.create(profileID,password,              firstName,lastName,address,phoneNo,emailID,cardNo,cardType,              Integer.parseInt(ccMonth),Integer.parseInt(ccYear)),              PassengerInterface.class);       PassengerProfile profileObj=new PassengerProfile();       profileObj.setProfileID(profileID);       profileObj.setPassword(password);       profileObj.setFirstName(firstName);       profileObj.setLastName(lastName);       profileObj.setAddress(address);       profileObj.setTelNo(phoneNo);       profileObj.setEmailID(emailID);       profileObj.setCardNumber(cardNo);       profileObj.setCardType(cardType);       profileObj.setExpirationMonth(Integer.parseInt(ccMonth));       profileObj.setExpirationYear(Integer.parseInt(ccYear));       valueObj.put(MVCConstants.PASSENGER_PROFILE, profileObj);         }catch(Exception exp)     {       errorDesc="Error while creating the User Profile ....               Internal error occurred" + sep;       errorDesc=errorDesc + " Please try later ";       throw new GenericException(errorDesc,exp);     }     return valueObj;   }   public MVCAppValueObject viewAvailableFlights(MVCAppValueObject objValue)           throws GenericException   {     //first find out if there is an entry for a flight for the selected    //date getting the FLIGHT home interface    String errorDesc="";     MVCAppValueObject valueObj=new MVCAppValueObject();     Collection col=null;     try     {       FlightHome flightHomeObj=lookupFlightHome();       String fromLocation=(String)objValue.               get(JspFieldConstants.CHECK_AVAIL_FLIGHTS_PAGE_DEP_CITY);       String toLocation=(String)objValue.               get(JspFieldConstants.CHECK_AVAIL_FLIGHTS_PAGE_ARR_CITY);       String day=(String)objValue.               get(JspFieldConstants.CHECK_AVAIL_FLIGHTS_PAGE_DEP_DAY);       String month=(String)objValue.               get(JspFieldConstants.CHECK_AVAIL_FLIGHTS_PAGE_DEP_MONTH);       String year=(String)objValue.               get(JspFieldConstants.CHECK_AVAIL_FLIGHTS_PAGE_DEP_YEAR);       Calendar buildSqlDate=Calendar.getInstance();       buildSqlDate.set(Integer.parseInt(year), Integer.parseInt(month),               Integer.parseInt(day));       java.sql.Date bookDate=new java.sql.Date(buildSqlDate.getTime().getTime());       col=flightHomeObj.findAvailableFlights(fromLocation, toLocation, bookDate);    }catch(Exception exp)     {       errorDesc="Error while searching the available flights ...*.               Internal error occurred" + sep;       errorDesc=errorDesc + " Please try later ";       throw new GenericException(errorDesc,exp);     }     if(col.isEmpty())     {       errorDesc="No Flights available for the selected date or location!";       throw new GenericException(errorDesc);     }     try     {       Iterator it=col.iterator();       Vector flightVec=new Vector();       while (it.hasNext())       {         FlightInterface flightRemoteObj=(FlightInterface)PortableRemoteObject.                 narrow(it.next(), FlightInterface.class);         flightVec.addElement(createFlightMVCValueObject(flightRemoteObj));       }       valueObj.put(MVCConstants.ALL_FLIGHTS_INFORMATION, flightVec);         }catch(Exception exp)     {       errorDesc="Error while searching the available flights ....               Internal error occurred" + sep;       errorDesc=errorDesc + " Please try later ";       throw new GenericException(errorDesc,exp);     }       return valueObj;   }   private MVCAppValueObject createPassengerMVCValueObject           (PassengerInterface passengerRemoteObj) throws Exception   {         PassengerProfile profileObj=new PassengerProfile();         profileObj.setProfileID(passengerRemoteObj.getProfileId());         profileObj.setPassword(passengerRemoteObj.getPassword());         profileObj.setFirstName(passengerRemoteObj.getFirstName());         profileObj.setLastName(passengerRemoteObj.getLastName());         profileObj.setAddress(passengerRemoteObj.getAddress());         profileObj.setTelNo(passengerRemoteObj.getTelNo());         profileObj.setCardNumber(passengerRemoteObj.getCardNumber());         profileObj.setCardType(passengerRemoteObj.getCardType());         profileObj.setExpirationMonth(passengerRemoteObj.getExpirationMonth());         profileObj.setExpirationYear(passengerRemoteObj.getExpirationYear());         MVCAppValueObject valueObj=new MVCAppValueObject();         valueObj.put(MVCConstants.PASSENGER_PROFILE, profileObj);     return valueObj;     }   private FlightDetails createFlightMVCValueObject           (FlightInterface flightRemoteObj) throws Exception   {       FlightDetails flightDetailsBO=new FlightDetails();       flightDetailsBO.setAirlineID(flightRemoteObj.getAirlineId());       flightDetailsBO.setAirlineName(flightRemoteObj.getAirlineName());       flightDetailsBO.setFlightDepartureTime(flightRemoteObj.getDepartureTime());       flightDetailsBO.setFlightArrivalTime(flightRemoteObj.getArrivalTime());       flightDetailsBO.setFlightID(flightRemoteObj.getFlightId());       flightDetailsBO.setFromLocation(flightRemoteObj.getFromLocation());       flightDetailsBO.setToLocation(flightRemoteObj.getToLocation());       flightDetailsBO.setPrice(flightRemoteObj.getPrice());       flightDetailsBO.setDepartureDate(flightRemoteObj.getFlightDepartureDate());       return flightDetailsBO;   }   /**      * Look up the Airline bean's home interface using JNDI.      */     private FlightHome lookupFlightHome()throws NamingException     {     Hashtable h=new Hashtable();     h.put(Context.INITIAL_CONTEXT_FACTORY, MVCConstants.             WEBLOGIC_INITIAL_CONTEXT_FACTORY);     h.put(Context.PROVIDER_URL, MVCConstants.WEBLOGIC_PROVIDER_URL);     Context ctx=new InitialContext(h);     try {       Object home=(FlightHome)ctx.lookup("Flight_Home");       return (FlightHome) PortableRemoteObject.narrow(home, FlightHome.class);     } catch (NamingException ne) {       System.out.println("Unable to lookup the EJBHome.  Verify the ejb JNDI               name FlightHome on the WebLogic server");       ne.printStackTrace();       throw ne;     }     }   /**      * Look up the Airline bean's home interface using JNDI.      */     private PassengerHome lookupPassengerHome()throws NamingException     {     Hashtable h=new Hashtable();     h.put(Context.INITIAL_CONTEXT_FACTORY, MVCConstants.             WEBLOGIC_INITIAL_CONTEXT_FACTORY);     h.put(Context.PROVIDER_URL, MVCConstants.WEBLOGIC_PROVIDER_URL);     Context ctx=new InitialContext(h);     System.out.println("Initial context to look up CMP PassengerHome created "             +ctx);     try {       Object home=(PassengerHome)ctx.lookup("Passenger");       return (PassengerHome) PortableRemoteObject.narrow(home,               PassengerHome.class);     } catch (NamingException ne) {       System.out.println("Unable to lookup the EJBHome.Verify the ejb               JNDI name CustomerServiceAgentHome on the WebLogic server");       throw ne;     }   } } 
Listing C.31 TicketSalesAgentHome.java
 /******************************************************************************  * Class Name: TicketSalesAgentHome.java  * Description:Home Interface for TicketSalesAgentBean.  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.sessionbean; import javax.ejb.*; import java.rmi.RemoteException; public interface TicketSalesAgentHome extends EJBHome {   public TicketSalesAgentInterface create()   throws CreateException, RemoteException; } 
Listing C.32 TicketSalesAgentInterface.java
 /******************************************************************************  * Class Name: TicketSalesAgentInterface.java  * Description:Remote Interface for TicketSalesAgentBean.  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.sessionbean; import javax.ejb.*; import com.sams.learnweblogic7.airlines.businessobject.*; import com.sams.learnweblogic7.airlines.constants.*; import com.sams.learnweblogic7.airlines.exception.*; import java.rmi.RemoteException; public interface TicketSalesAgentInterface extends EJBObject {   public MVCAppValueObject confirmBooking()   throws RemoteException, GenericException;   public MVCAppValueObject cancelBooking()   throws RemoteException, GenericException;   public MVCAppValueObject addOrder(MVCAppValueObject objValue)   throws RemoteException, GenericException;   public void putUserInformation(MVCAppValueObject objValue)   throws RemoteException;   public MVCAppValueObject getUserInformation()   throws RemoteException, GenericException;   public MVCAppValueObject getSessionData()   throws RemoteException;   public void setSessionData(MVCAppValueObject SessionData)   throws RemoteException;   public MVCAppValueObject getUserTicketInfo()   throws RemoteException, GenericException; } 
Listing C.33 TicketSalesAgentBean.java
 /******************************************************************************  * Class Name: TicketSalesAgentBean.java  * Description:Bean Implementation for TicketSalesAgentBean.  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.sessionbean; import java.sql.Date; import javax.ejb.*; import java.util.*; import javax.naming.*; import javax.rmi.*; import com.sams.learnweblogic7.airlines.constants.*; import com.sams.learnweblogic7.airlines.businessobject.*; import com.sams.learnweblogic7.airlines.util.*; import com.sams.learnweblogic7.airlines.entitybean.*; import com.sams.learnweblogic7.airlines.exception.*; public class TicketSalesAgentBean implements javax.ejb.SessionBean,         javax.ejb.SessionSynchronization {   // ---------------------------------------------------------------   // conversational state fields   public MVCAppValueObject sessionData;   // ---------------------------------------------------------------   // private fields   private SessionContext ctx;   private String sep=System.getProperty( "line.separator" );   public TicketSalesAgentBean()   {   }   // ---------------------------------------------------------------   // SessionBean interface implementation   public void ejbActivate()   {   }   public void ejbPassivate()   {   }   public void ejbRemove()   {   }   public void setSessionContext(SessionContext ctx)   {     this.ctx=ctx;   }   // ---------------------------------------------------------------   // SessionSynchronization interface implementation   public void afterBegin()   {   }   public void afterCompletion(boolean committed)   {   }   public void beforeCompletion()   {   }   // ---------------------------------------------------------------   // create methods   public void ejbCreate()   {     sessionData=new MVCAppValueObject();   }   // ---------------------------------------------------------------   // business methods   public MVCAppValueObject confirmBooking() throws GenericException   {     String errorDesc="";     MVCAppValueObject returnValueObj=new MVCAppValueObject();     // get the data from the session     PassengerProfile passengerProfileBO=(PassengerProfile)sessionData.             get(MVCConstants.PASSENGER_PROFILE);     FlightDetails flightDetailsBO=(FlightDetails)sessionData.             get(MVCConstants.PASSENGER_FLIGHT_DETAILS);     if (passengerProfileBO==null || flightDetailsBO==null)     {       errorDesc="Error while Confirming User Booking....               Internal error occurred" + sep;       errorDesc=errorDesc + " Please try later ";       throw new GenericException(errorDesc);     }     try     {       // first, charge the credit card       String ccNo=passengerProfileBO.getCardNumber();       String ccType=passengerProfileBO.getCardType();       String fullName=passengerProfileBO.getFirstName() + passengerProfileBO.               getLastName();       int expiryMonth=passengerProfileBO.getExpirationMonth();       int expiryYear=passengerProfileBO.getExpirationYear();       boolean ccFlag=new CreditCardProcessing().process(ccNo, ccType, fullName,               expiryMonth, expiryYear);     }catch(Exception exp)     {       errorDesc="Error while Processing the Credit Card" + sep;       errorDesc=errorDesc + " Please enter the correct Credit Card Details ";       throw new GenericException(errorDesc,exp);     }     try     {       // second, insert a row in the TICKETINFO table       // and return a unique ticket number       TicketInfoHome ticketInfoHomeObj=lookupTicketInfoHome();       long ticketID=System.currentTimeMillis ();       String profileID=passengerProfileBO.getProfileID();       String status="confirmed";       int flightId=flightDetailsBO.getFlightID();       Date departureDate=flightDetailsBO.getDepartureDate();       TicketInfoInterface ticketInfoRemoteObj=(TicketInfoInterface)               PortableRemoteObject.narrow(ticketInfoHomeObj.create               (ticketID,profileID,status,flightId,departureDate),               TicketInfoInterface.class);       TicketDetails ticketDetailsBO=new TicketDetails();       ticketDetailsBO.setTicketID(ticketID);       ticketDetailsBO.setProfileID(profileID);       ticketDetailsBO.setStatus(status);       ticketDetailsBO.setFlightID(flightId);       ticketDetailsBO.setDepartureDate(departureDate);       // now put the ticket details in the session       sessionData.put(MVCConstants.PASSENGER_TICKET_DETAILS, ticketDetailsBO);       // also put in the return object       returnValueObj.put(MVCConstants.PASSENGER_TICKET_DETAILS, ticketDetailsBO);       // commit the transaction       // send the email with ticket details       String emailAddress=passengerProfileBO.getEmailID();       boolean emailFlag=new Email().sendEmail(emailAddress, "Ticket Confirmtion",               ticketID+"");     }catch(Exception exp)     {       errorDesc="Error while Confirming User Booking.... Internal error occurred"               + sep;       errorDesc=errorDesc + " Please try later ";       throw new GenericException(errorDesc,exp);     }     return returnValueObj;   }   public MVCAppValueObject cancelBooking() throws GenericException   {     String errorDesc="";     MVCAppValueObject returnValueObj=new MVCAppValueObject();     try     {       // remove the ticket ordered from the session       sessionData.remove(MVCConstants.PASSENGER_TICKET_DETAILS);     }catch(Exception exp)     {       errorDesc="Error while Canceling User Booking.... Internal error occurred"               + sep;       errorDesc=errorDesc + " Please try later ";       throw new GenericException(errorDesc,exp);     }     return returnValueObj;   }   public MVCAppValueObject addOrder(MVCAppValueObject objValue)           throws GenericException   {     MVCAppValueObject returnValueObj=new MVCAppValueObject();     try     {       // first get the flight id for a date that the user is interested in buying       String strFlightID=(String)objValue.               get(JspFieldConstants.DISPLAY_AVAIL_FLIGHTS_PAGE_FLIGHT_ID);       int flightID=Integer.parseInt(strFlightID);       String strDepartureDate=(String)objValue.               get(JspFieldConstants.DISPLAY_AVAIL_FLIGHTS_PAGE_DEP_DATE);       java.sql.Date departureDate=java.sql.Date.valueOf(strDepartureDate);       // add the selected flight details in the user session       FlightHome flightHomeObj=lookupFlightHome();       FlightInterface flightRemoteObj= flightHomeObj.findFlightForADate(flightID, departureDate);       FlightDetails flightDetailsBO=createFlightMVCValueObject(flightRemoteObj);       sessionData.put(MVCConstants.PASSENGER_FLIGHT_DETAILS, flightDetailsBO);     }catch(Exception exp)     {       exp.printStackTrace();       throw new GenericException(exp);     }     return returnValueObj;   }   public void putUserInformation(MVCAppValueObject objValue)   {     PassengerProfile passengerProfileObj=(PassengerProfile)objValue.             get(MVCConstants.PASSENGER_PROFILE);     sessionData.put(MVCConstants.PASSENGER_PROFILE, passengerProfileObj);   }   public MVCAppValueObject getUserInformation() throws GenericException   {     String errorDesc="";     MVCAppValueObject userInfoValueObject=new MVCAppValueObject();     PassengerProfile passengerProfileObj=(PassengerProfile)sessionData.             get(MVCConstants.PASSENGER_PROFILE);     if (passengerProfileObj==null)     {       errorDesc="Error while receiving the User Information.... Internal               error occurred " + sep;       errorDesc=errorDesc + " Please try later ";       throw new GenericException(errorDesc);     }     userInfoValueObject.put(MVCConstants.PASSENGER_PROFILE, passengerProfileObj);     return userInfoValueObject;   }   public MVCAppValueObject getUserTicketInfo()   {     Collection col=null;     FlightHome flightHomeObj=null;     MVCAppValueObject userInfoValueObject=new MVCAppValueObject();     PassengerProfile passengerProfileObj=(PassengerProfile)sessionData.             get(MVCConstants.PASSENGER_PROFILE);     Vector tickets=new Vector();     try     {       flightHomeObj=lookupFlightHome();       TicketInfoHome ticketInfoHomeObj=lookupTicketInfoHome();       col=ticketInfoHomeObj.findByProfileID(passengerProfileObj.getProfileID());       if(col.isEmpty())       {         System.out.println("No ticket information avaialble ");       }       Iterator it=col.iterator();       while (it.hasNext())       {         MVCAppValueObject flightInfoValueObject=new MVCAppValueObject();         TicketInfoInterface ticketInfoRemoteObj=(TicketInfoInterface) PortableRemoteObject.narrow(it.next(),TicketInfoInterface.class);         TicketDetails ticketDetailsBO=new TicketDetails();         ticketDetailsBO.setTicketID(ticketInfoRemoteObj.getTicketId());         ticketDetailsBO.setProfileID(ticketInfoRemoteObj.getProfileId());         ticketDetailsBO.setStatus(ticketInfoRemoteObj.getStatus());         ticketDetailsBO.setFlightID(ticketInfoRemoteObj.getFlightId());         ticketDetailsBO.setDepartureDate(ticketInfoRemoteObj.getDepartureDate());         flightInfoValueObject.put(MVCConstants.PASSENGER_TICKET_DETAILS,                 ticketDetailsBO);         // now that you have the ticket information, get the flight details         //for that ticket         FlightInterface flightRemoteObj=flightHomeObj.                 findFlightForADate(ticketInfoRemoteObj.getFlightId(),                 ticketInfoRemoteObj.getDepartureDate());         FlightDetails flightDetailsBO=createFlightMVCValueObject(flightRemoteObj);         flightInfoValueObject.put(MVCConstants.PASSENGER_FLIGHT_DETAILS,                 flightDetailsBO);         tickets.addElement(flightInfoValueObject);       }     }     catch(Exception e){       System.out.println("Error in TicketSalesAgent - "+e);       e.printStackTrace();     }     userInfoValueObject.put(MVCConstants.PASSENGER_TICKET_INFO, tickets);     return userInfoValueObject;   }   // ---------------------------------------------------------------   // get/set conversational state   public MVCAppValueObject getSessionData()   {     return this.sessionData;   }   public void setSessionData(MVCAppValueObject sessionData)   {     this.sessionData=sessionData;   }   // --------------------------------------------------------   /**      * Look up the Airline bean's home interface using JNDI      */     private TicketInfoHome lookupTicketInfoHome() throws NamingException     {     Hashtable h=new Hashtable();     h.put(Context.INITIAL_CONTEXT_FACTORY,             MVCConstants.WEBLOGIC_INITIAL_CONTEXT_FACTORY);     h.put(Context.PROVIDER_URL, MVCConstants.WEBLOGIC_PROVIDER_URL);     Context ctx=new InitialContext(h);     try {       Object home=(TicketInfoHome)ctx.lookup("TicketInfo");       return (TicketInfoHome) PortableRemoteObject.narrow(home,               TicketInfoHome.class);     } catch (NamingException ne) {       System.out.println("Unable to lookup the EJBHome.  Verify the ejb               JNDI name CustomerServiceAgentHome on the WebLogic server");       throw ne;     } }   /**      * Look up the Flight bean's home interface using JNDI.      */     private FlightHome lookupFlightHome() throws NamingException     {     Hashtable h=new Hashtable();     h.put(Context.INITIAL_CONTEXT_FACTORY,             MVCConstants.WEBLOGIC_INITIAL_CONTEXT_FACTORY);     h.put(Context.PROVIDER_URL, MVCConstants.WEBLOGIC_PROVIDER_URL);     Context ctx=new InitialContext(h);     try {       Object home=(FlightHome)ctx.lookup("Flight_Home");       return (FlightHome) PortableRemoteObject.narrow(home, FlightHome.class);     } catch (NamingException ne) {       System.out.println("Unable to lookup the EJBHome.               Verify the ejb JNDI name FlightHome on the WebLogic server");       throw ne;     } }   private FlightDetails createFlightMVCValueObject            (FlightInterface flightRemoteObj) throws Exception   {     FlightDetails flightDetailsBO=new FlightDetails();     flightDetailsBO.setAirlineID(flightRemoteObj.getAirlineId());     flightDetailsBO.setAirlineName(flightRemoteObj.getAirlineName());     flightDetailsBO.setFlightDepartureTime(flightRemoteObj.getDepartureTime());     flightDetailsBO.setFlightID(flightRemoteObj.getFlightId());     flightDetailsBO.setFromLocation(flightRemoteObj.getFromLocation());     flightDetailsBO.setToLocation(flightRemoteObj.getToLocation());     flightDetailsBO.setPrice(flightRemoteObj.getPrice());     flightDetailsBO.setFlightDuration(flightRemoteObj.getDuration());     flightDetailsBO.setDepartureDate(flightRemoteObj.getFlightDepartureDate());     return flightDetailsBO;   } } 


Sams Teach Yourself BEA WebLogic Server 7. 0 in 21 Days
Sams Teach Yourself BEA WebLogic Server 7.0 in 21 Days
ISBN: 0672324334
EAN: 2147483647
Year: 2002
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net