1 51 52 package org.objectweb.jass.examples.travelagency.ws; 53 54 import java.rmi.RemoteException ; 55 56 import javax.activity.opennested.ONTActivity; 57 import javax.activity.opennested.UserOpenNested; 58 import javax.ejb.CreateException ; 59 import javax.naming.Context ; 60 import javax.naming.InitialContext ; 61 import javax.naming.NamingException ; 62 63 import org.apache.axis.session.Session; 64 import org.apache.axis.session.SimpleSession; 65 import org.objectweb.jass.examples.travelagency.ejbs.Airline; 66 import org.objectweb.jass.examples.travelagency.ejbs.AirlineHome; 67 import org.objectweb.jass.examples.travelagency.ejbs.Hotel; 68 import org.objectweb.jass.examples.travelagency.ejbs.HotelHome; 69 70 public class TravelAgencySoapBindingImpl 71 implements org.objectweb.jass.examples.travelagency.ws.TravelAgency { 72 73 private UserOpenNested uon = null; 74 private Airline airline; 75 private Hotel hotel; 76 private Session s = null; 77 78 81 public TravelAgencySoapBindingImpl() { 82 s = new SimpleSession(); 83 uon = getUserOpenNested(); 84 airline = getAdaptAirlineEJB(); 85 hotel = getAdaptHotelEJB(); 86 } 87 88 91 public int reserveSeats(int in0) 92 throws 93 java.rmi.RemoteException , 94 org.objectweb.jass.examples.travelagency.ws.NotEnoughSeatsException, 95 org.objectweb.jass.examples.travelagency.ws.DBException { 96 try { 97 System.out.println("Starting ROOT activity"); 98 uon.activityBegin(0); 99 System.out.println("Calling EJB to reserve seats"); 100 airline.reserveSeats(in0); 101 System.out.println("Seats reserved"); 102 } catch ( 103 org 104 .objectweb 105 .jass 106 .examples 107 .travelagency 108 .exceptions 109 .NotEnoughSeatsException e) { 110 try { 111 System.out.println( 112 "Not enough seats!!! Rolling-back ROOT acitivity"); 113 uon.activityRollback(); 114 } catch (Exception e1) { 115 e1.printStackTrace(); 116 } 117 throw new NotEnoughSeatsException(); 118 } catch ( 119 org.objectweb.jass.examples.travelagency.exceptions.DBException e) { 120 try { 121 System.out.println("DB Error. Rolling-back ROOT activity"); 122 uon.activityRollback(); 123 } catch (Exception e1) { 124 e1.printStackTrace(); 125 } 126 throw new DBException(); 127 } catch (Exception e) { 128 e.printStackTrace(); 129 } 130 System.out.println("Suspending ROOT activity"); 131 ONTActivity activity = uon.suspend(); 132 System.out.println("ROOT activity suspended"); 133 s.set("ACTIVITY", activity); 134 return in0; 135 } 136 137 140 public int reserveRooms(int in0) 141 throws 142 java.rmi.RemoteException , 143 org.objectweb.jass.examples.travelagency.ws.NotEnoughRoomsException, 144 org.objectweb.jass.examples.travelagency.ws.DBException { 145 146 System.out.println("Resuming ROOT activity"); 147 ONTActivity activity = (ONTActivity) s.get("ACTIVITY"); 148 uon.resume(activity); 149 System.out.println("ROOT activity resumed"); 150 151 try { 152 System.out.println("Calling EJB to reserve rooms"); 153 hotel.reserveRooms(in0); 154 System.out.println("Rooms reserved"); 155 System.out.println("Committing ROOT activity"); 156 uon.activityCommit(null); 157 System.out.println("ROOT activity committed!!!"); 158 } catch ( 159 org 160 .objectweb 161 .jass 162 .examples 163 .travelagency 164 .exceptions 165 .NotEnoughRoomsException e) { 166 try { 167 System.out.println( 168 "Not enough rooms!!! Rolling-back ROOT acitivity"); 169 uon.activityRollback(); 170 } catch (Exception e1) { 171 e1.printStackTrace(); 172 } 173 throw new NotEnoughRoomsException(); 174 } catch ( 175 org.objectweb.jass.examples.travelagency.exceptions.DBException e) { 176 try { 177 System.out.println("DB Error. Rolling-back ROOT activity"); 178 uon.activityRollback(); 179 } catch (Exception e1) { 180 e1.printStackTrace(); 181 } 182 throw new DBException(); 183 } catch (Exception e) { 184 e.printStackTrace(); 185 } 186 187 return in0; 188 } 189 190 193 private UserOpenNested getUserOpenNested() { 194 UserOpenNested uon = null; 195 Context ctx = null; 196 197 try { 198 ctx = new InitialContext (); 199 uon = (UserOpenNested) ctx.lookup("UserOpenNested"); 200 } catch (Exception e) { 201 e.printStackTrace(); 202 } 203 return uon; 204 } 205 206 209 private Airline getAdaptAirlineEJB() { 210 Object obj = null; 211 Context ctx = null; 212 Airline airline = null; 213 try { 214 ctx = new InitialContext (); 215 obj = ctx.lookup("AirlineEJB"); 216 AirlineHome airlineHome = 217 (AirlineHome) javax.rmi.PortableRemoteObject.narrow( 218 obj, 219 AirlineHome.class); 220 airline = airlineHome.create(); 221 } catch (NamingException e) { 222 e.printStackTrace(); 223 } catch (CreateException e) { 224 e.printStackTrace(); 225 } catch (RemoteException e) { 226 e.printStackTrace(); 227 } 228 return airline; 229 } 230 231 234 private Hotel getAdaptHotelEJB() { 235 Object obj = null; 236 Context ctx = null; 237 Hotel hotel = null; 238 try { 239 ctx = new InitialContext (); 240 obj = ctx.lookup("HotelEJB"); 241 HotelHome hotelHome = 242 (HotelHome) javax.rmi.PortableRemoteObject.narrow( 243 obj, 244 HotelHome.class); 245 hotel = hotelHome.create(); 246 } catch (NamingException e) { 247 e.printStackTrace(); 248 } catch (CreateException e) { 249 e.printStackTrace(); 250 } catch (RemoteException e) { 251 e.printStackTrace(); 252 } 253 return hotel; 254 } 255 256 } 257 | Popular Tags |