c2b624c97a48f55067d0c2aee043f23036ac6308
[RRRRHHHH_Code] / ruralHouses / src / businessLogic / HouseManager.java
1 package businessLogic;
2
3 import java.rmi.RemoteException;
4 import java.rmi.server.UnicastRemoteObject;
5 import java.util.Vector;
6
7 import common.HouseInterface;
8
9 import dataAccess.DB4oManager;
10 import domain.Owner;
11 import domain.RuralHouse;
12
13
14 public class HouseManager extends UnicastRemoteObject implements HouseInterface {
15         /**
16          * 
17          */
18         private static final long serialVersionUID = 1L;
19         DB4oManager dbMngr;
20         public HouseManager() throws RemoteException {
21                 super();
22                 try {
23                         dbMngr = DB4oManager.getInstance();
24                 } catch (Exception e) {
25
26                         e.printStackTrace();
27                 }
28         }
29
30
31         private boolean suitsRegulations(int nKitchens, int nBaths, int nLivings) {
32                 if (nKitchens < 1 || nLivings < 3 || nBaths < 2)
33                         return false;
34                 else
35                         return true;
36         }
37
38         @Override
39         public boolean registerNewHouse(RuralHouse rh) {
40
41                 boolean stored = false;
42                 if (!suitsRegulations(rh.getFeatures().getnKitchens(), rh.getFeatures()
43                                 .getnBaths(), rh.getFeatures().getnKitchens()))
44                         return false;
45                 stored = this.dbMngr.storeRuralHouses(rh);
46                 return stored;
47         }
48
49         public void removeHouse(RuralHouse rh, Owner owner) {
50                 Vector<RuralHouse> temp = owner.getRuralHouses();
51                 temp.remove(rh);
52                 this.dbMngr.removeHouse(rh, owner);
53         }
54
55
56
57         public Vector<RuralHouse> getHouses(Owner ow, String name,String town, int nBed, int nKit,
58                         int nBath, int nPark, int nLiv) {
59
60                 return this.dbMngr.getRuralHouses( ow, name ,town, nBed, nKit, nBath, nPark, nLiv);
61         }
62         
63         
64
65
66 }