3 import java.rmi.RemoteException;
4 import java.rmi.server.UnicastRemoteObject;
6 import java.util.Vector;
8 import com.db4o.ObjectContainer;
9 import com.db4o.ObjectSet;
10 import common.BookingInterface;
12 import dataAccess.DB4oManager;
13 import domain.Booking;
15 import domain.RuralHouse;
16 import exceptions.OfferCanNotBeBooked;
20 public final class BookingManager extends UnicastRemoteObject implements BookingInterface {
25 private static final long serialVersionUID = 1L;
26 private int bookingNumber = 0;
27 dataAccess.DB4oManager dbMngr;
29 private static BookingManager theBookingManager;
31 public BookingManager() throws RemoteException {
34 this.dbMngr = DB4oManager.getInstance();
35 } catch (Exception e) {
41 * This method returns the next Booking number
43 * @return the book number
46 public int getNumber() throws RemoteException{
47 ObjectContainer db=DB4oManager.getContainer();
48 BookingManager b=getInstance();
52 return b.bookingNumber;
56 * This method returns the instance of the BookingManager class
58 * @return the booking manager
59 * @throws RemoteException
62 public BookingManager getInstance() throws RemoteException {
63 ObjectContainer db=DB4oManager.getContainer();
64 BookingManager b = new BookingManager();
65 ObjectSet<BookingManager> result = db.queryByExample(b);
66 if (!result.hasNext()){
67 theBookingManager = new BookingManager();
68 db.store(theBookingManager);
70 } else theBookingManager=(BookingManager)result.next();
71 return theBookingManager;
74 public void removeDenyBooking(Booking b) throws RemoteException{
75 b.getOffer().getBookings().remove(b);
76 this.dbMngr.removeBooking(b);
80 public void acceptBooking(Booking b) throws RemoteException{
81 b.getOffer().setBooked(true);
82 for(Booking boo : b.getOffer().getBookings()){
84 b.getOffer().getBookings().remove(b);
86 this.dbMngr.acceptBooking(b.getOffer());
88 MailManager.getInstance().Send(b.getClient().getMailAccount(), "Your booking has been accepted","Here should be the bill");
89 } catch (MessagingException e) {
90 // TODO Auto-generated catch block
96 * This method creates a book with a corresponding parameters
99 * day, last day, house number and telephone
102 public Vector<Booking> createBooking(RuralHouse ruralHouse, Date firstDate,
103 Date lastDate, Client client)
104 throws OfferCanNotBeBooked,RemoteException {
106 return dbMngr.createBooking(ruralHouse, firstDate, lastDate,