1 51 52 package org.objectweb.jass.examples.travelagency.ejbs; 53 54 import javax.activity.opennested.UserOpenNested; 55 import javax.ejb.EJBException ; 56 import javax.ejb.SessionBean ; 57 import javax.ejb.SessionContext ; 58 import javax.naming.Context ; 59 import javax.naming.InitialContext ; 60 61 import org 62 .objectweb 63 .jass 64 .examples 65 .travelagency 66 .exceptions 67 .NotEnoughRoomsException; 68 import org 69 .objectweb 70 .jass 71 .examples 72 .travelagency 73 .exceptions 74 .NotEnoughSeatsException; 75 76 84 public class TravelAgencyBean implements SessionBean { 85 86 private Airline airline; 87 private Hotel hotel; 88 private UserOpenNested uon; 89 90 public void ejbCreate() throws javax.ejb.CreateException { 91 airline = getAdaptAirlineEJB(); 92 hotel = getAdaptHotelEJB(); 93 uon = getUserOpenNested(); 94 System.out.println("Travel Agency stateless EJB created!!!"); 95 } 96 97 public void ejbActivate() throws EJBException { 98 } 99 100 public void ejbPassivate() throws EJBException { 101 } 102 103 public void ejbRemove() throws EJBException { 104 airline = null; 105 hotel = null; 106 uon = null; 107 System.out.println("Travel Agency stateless EJB removed!!!"); 108 } 109 110 public void setSessionContext(SessionContext sessionContext) 111 throws EJBException { 112 113 } 114 115 125 public void makeReservation(String name, int nSeats, int nRooms) 126 throws Exception { 127 128 try { 129 uon.activityBegin(0); 130 airline.reserveSeats(nSeats); 131 hotel.reserveRooms(nRooms); 132 uon.activityCommit(null); 133 } catch (NotEnoughSeatsException e) { 134 uon.activityRollback(); 135 throw e; 136 } catch (NotEnoughRoomsException e) { 137 uon.activityRollback(); 138 throw e; 139 } catch (Exception e) { 140 throw e; 141 } 142 } 143 144 147 private UserOpenNested getUserOpenNested() { 148 Context ctx = null; 149 150 try { 151 ctx = new InitialContext (); 152 uon = (UserOpenNested) ctx.lookup("UserOpenNested"); 153 } catch (Exception e) { 154 e.printStackTrace(); 155 } 156 return uon; 157 } 158 159 162 private Airline getAdaptAirlineEJB() { 163 Object obj = null; 164 Context ctx = null; 165 try { 166 ctx = new InitialContext (); 167 obj = ctx.lookup("AirlineEJB"); 168 AirlineHome airlineHome = 169 (AirlineHome) javax.rmi.PortableRemoteObject.narrow( 170 obj, 171 AirlineHome.class); 172 airline = airlineHome.create(); 173 } catch (Exception e) { 174 e.printStackTrace(); 175 } 176 return airline; 177 } 178 179 182 private Hotel getAdaptHotelEJB() { 183 Object obj = null; 184 Context ctx = null; 185 try { 186 ctx = new InitialContext (); 187 obj = ctx.lookup("HotelEJB"); 188 HotelHome hotelHome = 189 (HotelHome) javax.rmi.PortableRemoteObject.narrow( 190 obj, 191 HotelHome.class); 192 hotel = hotelHome.create(); 193 } catch (Exception e) { 194 e.printStackTrace(); 195 } 196 return hotel; 197 } 198 199 } 200 | Popular Tags |