KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jass > examples > travelagency > ws > TravelAgencySoapBindingImpl


1 /**
2  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3  -
4  - JASS: Java Advanced tranSaction Support
5  -
6  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7  -
8  - This module was originally developed by
9  -
10  - LSD (Distributed Systems Lab, http://lsd.ls.fi.upm.es/lsd/lsd.htm)
11  - at Universidad Politecnica de Madrid (UPM) as an ObjectWeb Consortium
12  - (http://www.objectweb.org) project.
13  -
14  - This project has been partially funded by the European Commission under
15  - the IST programme of V FP grant IST-2001-37126 and by the Spanish
16  - Ministry of Science & Technology (MCyT) grants TIC2002-10376-E and
17  - TIC2001-1586-C03-02
18  -
19  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20  - The original code and portions created by LSD are
21  - Copyright (c) 2004 LSD (UPM)
22  - All rights reserved.
23  -
24  - Redistribution and use in source and binary forms, with or without
25  - modification, are permitted provided that the following conditions are met:
26  -
27  - -Redistributions of source code must retain the above copyright notice, this
28  - list of conditions and the following disclaimer.
29  -
30  - -Redistributions in binary form must reproduce the above copyright notice,
31  - this list of conditions and the following disclaimer in the documentation
32  - and/or other materials provided with the distribution.
33  -
34  - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
35  - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36  - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37  - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
38  - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
39  - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
40  - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41  - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
42  - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43  - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  - POSSIBILITY OF SUCH DAMAGE.
45  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46  -
47  - Author: Francisco Perez Sorrosal (frperezs)
48  -
49  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50 */

51
52 package org.objectweb.jass.examples.travelagency.ws;
53
54 import java.rmi.RemoteException JavaDoc;
55
56 import javax.activity.opennested.ONTActivity;
57 import javax.activity.opennested.UserOpenNested;
58 import javax.ejb.CreateException JavaDoc;
59 import javax.naming.Context JavaDoc;
60 import javax.naming.InitialContext JavaDoc;
61 import javax.naming.NamingException JavaDoc;
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     /**
79      * Constructor. Obtains a reference to the UserOpenNested and the EJBs.
80      */

81     public TravelAgencySoapBindingImpl() {
82         s = new SimpleSession();
83         uon = getUserOpenNested();
84         airline = getAdaptAirlineEJB();
85         hotel = getAdaptHotelEJB();
86     }
87
88     /**
89      * Makes the seat reservation calling the EJB.
90      */

91     public int reserveSeats(int in0)
92         throws
93             java.rmi.RemoteException JavaDoc,
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 JavaDoc 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 JavaDoc e1) {
124                 e1.printStackTrace();
125             }
126             throw new DBException();
127         } catch (Exception JavaDoc 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     /**
138      * Makes the rooms reservation calling the EJB.
139      */

140     public int reserveRooms(int in0)
141         throws
142             java.rmi.RemoteException JavaDoc,
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 JavaDoc 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 JavaDoc e1) {
180                 e1.printStackTrace();
181             }
182             throw new DBException();
183         } catch (Exception JavaDoc e) {
184             e.printStackTrace();
185         }
186
187         return in0;
188     }
189
190     /**
191     * Gets the reference to the UserOpenNested service.
192     */

193     private UserOpenNested getUserOpenNested() {
194         UserOpenNested uon = null;
195         Context JavaDoc ctx = null;
196
197         try {
198             ctx = new InitialContext JavaDoc();
199             uon = (UserOpenNested) ctx.lookup("UserOpenNested");
200         } catch (Exception JavaDoc e) {
201             e.printStackTrace();
202         }
203         return uon;
204     }
205
206     /**
207      * Gets the reference to the Airline EJB.
208      */

209     private Airline getAdaptAirlineEJB() {
210         Object JavaDoc obj = null;
211         Context JavaDoc ctx = null;
212         Airline airline = null;
213         try {
214             ctx = new InitialContext JavaDoc();
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 JavaDoc e) {
222             e.printStackTrace();
223         } catch (CreateException JavaDoc e) {
224             e.printStackTrace();
225         } catch (RemoteException JavaDoc e) {
226             e.printStackTrace();
227         }
228         return airline;
229     }
230
231     /**
232      * Gets the reference to the Hotel EJB.
233      */

234     private Hotel getAdaptHotelEJB() {
235         Object JavaDoc obj = null;
236         Context JavaDoc ctx = null;
237         Hotel hotel = null;
238         try {
239             ctx = new InitialContext JavaDoc();
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 JavaDoc e) {
247             e.printStackTrace();
248         } catch (CreateException JavaDoc e) {
249             e.printStackTrace();
250         } catch (RemoteException JavaDoc e) {
251             e.printStackTrace();
252         }
253         return hotel;
254     }
255
256 }
257
Popular Tags