001: package com.uvw.travel.impl;
002:
003: import com.uvw.travel.*;
004: import java.util.Date;
005:
006: /**
007: * @author Adrian Price
008: */
009: public final class BookingsImpl implements Bookings {
010: private final Customer customer;
011: private final CreditCard creditCard;
012: private FlightBooking flightBooking;
013: private HotelBooking hotelBooking;
014: private RentalCarBooking rentalCarBooking;
015:
016: public abstract class BookingImpl implements Booking {
017: private final Person[] people;
018: private int status = PENDING;
019: String creditCardAuthorizationCode;
020:
021: protected BookingImpl(Person[] people) {
022: this .people = people;
023: }
024:
025: public int getStatus() {
026: return status;
027: }
028:
029: public void setStatus(int status) {
030: this .status = status;
031: }
032:
033: public String getCreditCardAuthorizationCode() {
034: return creditCardAuthorizationCode;
035: }
036:
037: public void setCreditCardAuthorizationCode(
038: String creditCardAuthorizationCode) {
039:
040: this .creditCardAuthorizationCode = creditCardAuthorizationCode;
041: }
042:
043: public Person[] getPeople() {
044: return people;
045: }
046:
047: public Customer getCustomer() {
048: return customer;
049: }
050:
051: public CreditCard getCreditCard() {
052: return creditCard;
053: }
054: }
055:
056: public final class FlightBookingImpl extends BookingImpl implements
057: FlightBooking {
058:
059: private final Flight[] flights;
060:
061: public FlightBookingImpl(Person[] people, Flight[] flights) {
062: super (people);
063: this .flights = flights;
064: }
065:
066: public Flight[] getFlights() {
067: return (Flight[]) flights.clone();
068: }
069: }
070:
071: public final class HotelBookingImpl extends BookingImpl implements
072: HotelBooking {
073:
074: private final String hotelName;
075: private final Address hotelAddress;
076: private final Date checkinDate;
077: private final Date checkoutDate;
078:
079: public HotelBookingImpl(Person[] people, String hotelName,
080: Address hotelAddress, Date checkinDate,
081: Date checkoutDate) {
082:
083: super (people);
084: this .hotelName = hotelName;
085: this .hotelAddress = hotelAddress;
086: this .checkinDate = checkinDate;
087: this .checkoutDate = checkoutDate;
088: }
089:
090: public String getHotelName() {
091: return hotelName;
092: }
093:
094: public Address getHotelAddress() {
095: return hotelAddress;
096: }
097:
098: public Date getCheckinDate() {
099: return checkinDate;
100: }
101:
102: public Date getCheckoutDate() {
103: return checkoutDate;
104: }
105: }
106:
107: public final class RentalCarBookingImpl extends BookingImpl
108: implements RentalCarBooking {
109:
110: private final String rentalAgency;
111: private final String carClass;
112: private final Date pickupDate;
113: private final Date dropoffDate;
114:
115: public RentalCarBookingImpl(Person[] people,
116: String rentalAgency, String carClass, Date pickupDate,
117: Date dropoffDate) {
118:
119: super (people);
120: this .rentalAgency = rentalAgency;
121: this .carClass = carClass;
122: this .pickupDate = pickupDate;
123: this .dropoffDate = dropoffDate;
124: }
125:
126: public String getRentalAgency() {
127: return rentalAgency;
128: }
129:
130: public String getCarClass() {
131: return carClass;
132: }
133:
134: public Date getPickupDate() {
135: return pickupDate;
136: }
137:
138: public Date getDropoffDate() {
139: return dropoffDate;
140: }
141: }
142:
143: public BookingsImpl(Customer customer, CreditCard creditCard) {
144: this .customer = customer;
145: this .creditCard = creditCard;
146: }
147:
148: public FlightBooking createFlightBooking(Person[] people,
149: Flight[] flights) {
150: if (flightBooking != null) {
151: throw new IllegalStateException(
152: "Flight booking already exists");
153: }
154: return flightBooking = new FlightBookingImpl(people, flights);
155: }
156:
157: public HotelBooking createHotelBooking(Person[] people,
158: String hotelName, Address hotelAddress, Date checkinDate,
159: Date checkoutDate) {
160:
161: if (hotelBooking != null)
162: throw new IllegalStateException(
163: "Hotel booking already exists");
164: return hotelBooking = new HotelBookingImpl(people, hotelName,
165: hotelAddress, checkinDate, checkoutDate);
166: }
167:
168: public RentalCarBooking createRentalCarBooking(Person[] people,
169: String rentalAgency, String carClass, Date pickupDate,
170: Date dropoffDate) {
171:
172: if (rentalCarBooking != null) {
173: throw new IllegalStateException(
174: "Rental car booking already exists");
175: }
176: return rentalCarBooking = new RentalCarBookingImpl(people,
177: rentalAgency, carClass, pickupDate, dropoffDate);
178: }
179:
180: public Customer getCustomer() {
181: return customer;
182: }
183:
184: public CreditCard getCreditCard() {
185: return creditCard;
186: }
187:
188: public FlightBooking getFlightBooking() {
189: return flightBooking;
190: }
191:
192: public HotelBooking getHotelBooking() {
193: return hotelBooking;
194: }
195:
196: public RentalCarBooking getRentalCarBooking() {
197: return rentalCarBooking;
198: }
199: }
|