deleted aplicationFacade and imported it's functions to specific business logics.
[RRRRHHHH_Code] / ruralHouses / src / businessLogic / __FacadeImplementation.java
1 package businessLogic;
2
3 import java.rmi.RemoteException;
4 import java.rmi.server.UnicastRemoteObject;
5 import java.sql.Date;
6 import java.sql.SQLException;
7 import java.util.Vector;
8
9 import com.db4o.ObjectContainer;
10 import com.db4o.ObjectSet;
11
12 import configuration.ConfigXML;
13 import dataAccess.DB4oManager;
14 import domain.Booking;
15 import domain.Offer;
16 import domain.Owner;
17 import domain.RuralHouse;
18 import exceptions.BadDates;
19 import exceptions.DB4oManagerCreationException;
20 import exceptions.OfferCanNotBeBooked;
21 import exceptions.OverlappingOfferExists;
22
23
24 public class __FacadeImplementation extends UnicastRemoteObject implements __ApplicationFacadeInterface {
25
26         /**
27          * 
28          */
29         private static final long serialVersionUID = 1L;
30
31         Vector<Owner> owners;
32         Vector<RuralHouse> ruralHouses;
33         DB4oManager dB4oManager;
34  
35
36         public __FacadeImplementation() throws RemoteException, InstantiationException,
37                         IllegalAccessException, ClassNotFoundException, SQLException, DB4oManagerCreationException {
38                 owners=null;
39                 ruralHouses=null;
40                 try{
41                         dB4oManager=DB4oManager.getInstance();
42                 }
43                 catch (com.db4o.ext.DatabaseFileLockedException e) {
44                         System.out.println("Error in FacadeImplementation: "+e.toString());
45                         throw e;
46                 }
47                 catch (Exception e) {
48                         System.out.println("Error in FacadeImplementation: "+e.toString());
49                         throw new DB4oManagerCreationException();
50                 }
51         }
52         
53
54         /**
55          * This method creates an offer with a house number, first day, last day and price
56          * 
57          * @param House
58          *            number, start day, last day and price
59          * @return the created offer, or null, or an exception
60          */
61         public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay,
62                         float price) throws OverlappingOfferExists, BadDates, RemoteException, Exception {
63                 if (firstDay.compareTo(lastDay)>=0) throw new BadDates();
64                 ruralHouses=null;
65                 owners=null;
66                 boolean b = dB4oManager.existsOverlappingOffer(ruralHouse,firstDay,lastDay); // The ruralHouse object in the client may not be updated
67                 if (!b) return dB4oManager.createOffer(ruralHouse,firstDay,lastDay,price);                      
68                 return null;
69         }
70
71         /**
72          * This method creates a book with a corresponding parameters
73          * 
74          * @param First
75          *            day, last day, house number and telephone
76          * @return a book
77          */
78         public Booking createBooking(RuralHouse ruralHouse, Date firstDate, Date lastDate, String bookTelephoneNumber)
79                         throws OfferCanNotBeBooked {
80                 ruralHouses=null;
81                 owners=null;
82                 return dB4oManager.createBooking(ruralHouse,firstDate,lastDate,bookTelephoneNumber);
83         }
84
85
86         /**
87          * This method existing  owners 
88          * 
89          */
90         public Vector<Owner> getOwners() throws RemoteException,
91                         Exception {
92                 
93                 if (owners!=null) { System.out.println("Owners obtained directly from business logic layer");
94                                                         return owners; }
95                 else return owners=dB4oManager.getOwners();
96         }
97                 
98         public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
99         Exception {
100                 
101                 if (ruralHouses!=null) { System.out.println("RuralHouses obtained directly from business logic layer");
102                                                                  return ruralHouses; }
103                 else return ruralHouses=dB4oManager.getAllRuralHouses();
104
105         }
106         
107         public void close() throws RemoteException{
108                 dB4oManager.close();
109
110         }
111
112         }
113