3 import java.rmi.RemoteException;
4 import java.rmi.server.UnicastRemoteObject;
6 import java.util.Vector;
8 import javax.mail.MessagingException;
10 import com.db4o.ObjectContainer;
11 import com.db4o.ObjectSet;
12 import common.BookingInterface;
14 import dataAccess.DB4oManager;
15 import domain.Booking;
17 import domain.RuralHouse;
18 import exceptions.OfferCanNotBeBooked;
22 public final class BookingManager extends UnicastRemoteObject implements BookingInterface {
27 private static final long serialVersionUID = 1L;
28 private int bookingNumber = 0;
29 dataAccess.DB4oManager dbMngr;
31 private static BookingManager theBookingManager;
33 public BookingManager() throws RemoteException {
36 this.dbMngr = DB4oManager.getInstance();
37 } catch (Exception e) {
43 * This method returns the next Booking number
45 * @return the book number
48 public int getNumber() throws RemoteException{
49 ObjectContainer db=DB4oManager.getContainer();
50 BookingManager b=getInstance();
54 return b.bookingNumber;
58 * This method returns the instance of the BookingManager class
60 * @return the booking manager
61 * @throws RemoteException
64 public BookingManager getInstance() throws RemoteException {
65 ObjectContainer db=DB4oManager.getContainer();
66 BookingManager b = new BookingManager();
67 ObjectSet<BookingManager> result = db.queryByExample(b);
68 if (!result.hasNext()){
69 theBookingManager = new BookingManager();
70 db.store(theBookingManager);
72 } else theBookingManager=(BookingManager)result.next();
73 return theBookingManager;
76 public void denyBooking(Booking b) throws RemoteException{
77 this.dbMngr.removeBooking(b);
79 MailManager.getInstance().Send(b.getClient().getMailAccount(), "Your booking has not been accepted","We are sorry");
80 } catch (MessagingException e) {
86 public void acceptBooking(Booking b) throws RemoteException{
87 b.getOffer().setBooked(true);
88 b.getOffer().getBookings().clear();
89 b.getOffer().getBookings().add(b);
90 this.dbMngr.acceptBooking(b.getOffer());
92 MailManager.getInstance().Send(b.getClient().getMailAccount(), "Your booking has been accepted","Here should be the bill");
93 } catch (MessagingException e) {
99 * This method creates a book with a corresponding parameters
102 * day, last day, house number and telephone
105 public Vector<Booking> createBooking(RuralHouse ruralHouse, Date firstDate,
106 Date lastDate, Client client)
107 throws OfferCanNotBeBooked,RemoteException {
109 return dbMngr.createBooking(ruralHouse, firstDate, lastDate,