KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > j2ee > blueprints > consumerwebsite > actions > TransportSearchHTMLAction


1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistribution in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Sun Microsystems, Inc. or the names of
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * This software is provided "AS IS," without a warranty of any
21 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
22 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
24 * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
25 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
26 * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
27 * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
28 * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
29 * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
30 * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
31 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 * You acknowledge that Software is not designed, licensed or intended
34 * for use in the design, construction, operation or maintenance of
35 * any nuclear facility.
36 */

37
38 package com.sun.j2ee.blueprints.consumerwebsite.actions;
39
40 import java.io.*;
41 import java.util.*;
42
43 // j2ee imports
44
import javax.servlet.http.*;
45
46 // waf imports
47
import com.sun.j2ee.blueprints.waf.controller.*;
48 import com.sun.j2ee.blueprints.waf.controller.web.html.*;
49
50 //adventure imports
51
import com.sun.j2ee.blueprints.consumerwebsite.*;
52
53 // Catalog imports
54
import com.sun.j2ee.blueprints.catalog.*;
55 import com.sun.j2ee.blueprints.catalog.dao.*;
56
57 /**
58  * Implementation of HTMLAction that processes a
59  * user change in language.
60  */

61
62 public final class TransportSearchHTMLAction extends HTMLActionSupport {
63
64     public Event perform(HttpServletRequest request)
65   throws HTMLActionException {
66             
67             HttpSession session = request.getSession();
68              // look up the adventure transportation
69
AdventureComponentManager acm =
70                         (AdventureComponentManager)session.getAttribute(AdventureKeys.COMPONENT_MANAGER);
71             Cart cart = acm.getCart(session);
72             String JavaDoc origin = request.getParameter("origin");
73             // if we are doing a search for a different flight from the cart page
74
if (origin == null) {
75                 origin = cart.getOrigin();
76             } else {
77                 cart.setOrigin(origin);
78             }
79              
80             ArrayList transpDepartureBeans = null;
81             ArrayList transpReturnBeans = null;
82             
83             String JavaDoc noTransport = request.getParameter("no_transport");
84             String JavaDoc showTransport = request.getParameter("show_flights");
85             Locale locale = new Locale("en","us");
86             String JavaDoc destination = cart.getDestination();
87             //access catalog component and retrieve data from the database
88
transpDepartureBeans = searchTransportation(origin, destination, locale);
89             transpReturnBeans = searchTransportation(destination, origin, locale);
90             
91             // places result bean data in the request
92
request.setAttribute("departure_result", transpDepartureBeans );
93             request.setAttribute("return_result", transpReturnBeans );
94             request.setAttribute("search_target","transportation");
95         return null;
96     }
97     
98         /**
99      * Access catalog component and retrieve transportation data from the database
100      */

101     public ArrayList searchTransportation(String JavaDoc origin, String JavaDoc destination ,Locale locale) throws HTMLActionException {
102         ArrayList transportation = null;
103         ArrayList transportationBean = new ArrayList();
104         
105         //call catalog component
106
try {
107             CatalogFacade catalogFacade = new CatalogFacade();
108             transportation = catalogFacade.getTransportations(origin, destination, locale);
109         
110         // Catch catalog exceptions and re-throw them as
111
// mini-app application defined exceptions.
112
} catch (Exception JavaDoc e) {
113             throw new HTMLActionException("Transportation Search Exception:: Catalog Exception accessing catalog component: " + e);
114         }
115         for(int i=0;i<transportation.size() ;++i){
116             transportationBean.add(new TransportationBean(((com.sun.j2ee.blueprints.catalog.Transportation)transportation.get(i)).getTransportationId(),
117                                                            ((com.sun.j2ee.blueprints.catalog.Transportation)transportation.get(i)).getName(),
118                                                            ((com.sun.j2ee.blueprints.catalog.Transportation)transportation.get(i)).getDescription(),
119                                                             ((com.sun.j2ee.blueprints.catalog.Transportation)transportation.get(i)).getImageURI(),
120                                                            ((com.sun.j2ee.blueprints.catalog.Transportation)transportation.get(i)).getPrice(),
121                                                            ((com.sun.j2ee.blueprints.catalog.Transportation)transportation.get(i)).getOrigin(),
122                                                            ((com.sun.j2ee.blueprints.catalog.Transportation)transportation.get(i)).getDestination(),
123                                                            ((com.sun.j2ee.blueprints.catalog.Transportation)transportation.get(i)).getCarrier(),
124                                                            ((com.sun.j2ee.blueprints.catalog.Transportation)transportation.get(i)).getDepartureTime(),
125                                                            ((com.sun.j2ee.blueprints.catalog.Transportation)transportation.get(i)).getArrivalTime(),
126                                                            ((com.sun.j2ee.blueprints.catalog.Transportation)transportation.get(i)).getTravelClass()));
127         }
128         return transportationBean ;
129     }
130 }
131     
132
Popular Tags