The code for different owner operations mostly implemented
[RRRRHHHH_Code] / ruralHouses / src / businessLogic / FacadeImplementation.java
1 package businessLogic;
2
3 import java.rmi.RemoteException;
4 import java.rmi.server.UnicastRemoteObject;
5
6 import java.util.Date;
7 import java.util.Vector;
8
9 import java.sql.SQLException;
10
11 import com.db4o.ObjectContainer;
12 import com.db4o.ObjectSet;
13 import configuration.Config;
14
15 import dataAccess.DB4oManager;
16
17 import domain.Booking;
18 import domain.Offer;
19 import domain.Owner;
20 import domain.RuralHouse;
21
22 import exceptions.OfferCanNotBeBooked;
23
24 public class FacadeImplementation extends UnicastRemoteObject implements ApplicationFacadeInterface {
25
26         private static final long serialVersionUID = 1L;
27         DB4oManager dbMngr;
28
29         public FacadeImplementation() throws RemoteException, InstantiationException,
30         IllegalAccessException, ClassNotFoundException, SQLException {
31                 dbMngr = DB4oManager.getInstance();
32         }
33
34         /**
35          * This method obtains an owner's rural houses 
36          * 
37          * @param owner object
38          *            
39          * @return a vector of Rural Houses
40          */
41         public Vector<RuralHouse> getRuralHouses(Owner owner)
42                         throws RemoteException {
43                 return owner.getRuralHouses();          
44         }
45
46         public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay,
47                         float price) throws RemoteException, Exception {                 
48                 return dbMngr.createOffer(ruralHouse, firstDay, lastDay, price);
49         }
50
51         /**
52          * This method obtains available offers for a concrete house in a certain period 
53          * 
54          * @param houseNumber, the house number where the offers must be obtained 
55          * @param firstDay, first day in a period range 
56          * @param lastDay, last day in a period range
57          * @return a vector of offers(Offer class)  available  in this period
58          */
59         public Vector<Offer> getOffers(RuralHouse house,Date firstDay, Date lastDay) throws RemoteException,
60         Exception {             
61                 return house.getOffers(firstDay, lastDay);
62
63         }
64         /**
65          * This method finds all existing  owners 
66          * 
67          */
68         public Vector<Owner> getOwners() throws RemoteException,
69         Exception {
70                 return dbMngr.getOwners();
71         } 
72
73         public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
74         Exception {             
75                 return dbMngr.getAllRuralHouses();              
76         }
77
78         
79
80         public Booking createBooking(RuralHouse ruralHouse, Date firstDate, Date lastDate, String bookTelephoneNumber)
81                         throws OfferCanNotBeBooked {
82                 try {
83                         RuralHouse rh=dbMngr.getRuralHouse(ruralHouse);
84                         Offer offer = rh.findOffer(firstDate, lastDate);
85                         Booking b=dbMngr.createBooking(offer,bookTelephoneNumber);
86                         return b;
87                 } catch (Exception exc) {
88                         exc.printStackTrace();
89                         return null;
90                 }
91                 
92         }
93
94         
95
96 }
97