--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src" />
+ <classpathentry kind="con"
+ path="org.eclipse.jdt.launching.JRE_CONTAINER" />
+ <classpathentry kind="lib" path="lib/additionalLibs/jcalendar.jar" />
+ <classpathentry kind="lib"
+ path="lib/db4o/lib/db4o-8.0.249.16098-all-java5.jar" />
+ <classpathentry kind="output" path="bin" />
+</classpath>
--- /dev/null
+/bin
+/lib
+/db
+/src/*/*.class
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>ruralHouses_client</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<config>
+ <businessLogic local="true">
+ <businessLogicNode>localhost</businessLogicNode>
+ <portRMI>1099</portRMI>
+ <serviceRMI>RuralHouses</serviceRMI>
+ </businessLogic>
+ <database local="true">
+
+ <databaseNode>localhost</databaseNode>
+ <db4oFilename>db/casas.db4o</db4oFilename>
+ <dataBaseOpenMode>initialize</dataBaseOpenMode>
+ <activationDepth>10</activationDepth>
+ <updateDepth>10</updateDepth>
+ <databasePort>8100</databasePort>
+ <user>softEng</user>
+ <password>i4softwEngin2matx</password>
+</database>
+<javaPolicyPath>java.policy</javaPolicyPath>
+
+</config>
\ No newline at end of file
--- /dev/null
+grant {
+permission java.security.AllPermission;
+};
+// If there problems with permissions:
+// permission java.security.AllPermission;
+//permission java.net.SocketPermission "localhost:1099", "connect,resolve";
+//permission java.net.SocketPermission "*", "accept,resolve";
+//permission java.io.FilePermission "casas.db4o", "delete,read,write";
+//permission java.util.PropertyPermission "*", "read";
\ No newline at end of file
--- /dev/null
+package common;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+import domain.Account;
+
+public interface AccountInterface extends Remote{
+
+
+ public boolean addAccount(Account ac) throws RemoteException;
+
+ public boolean removeAccount(Account ac) throws RemoteException;
+}
--- /dev/null
+package common;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.util.Vector;
+
+import domain.Account;
+import domain.RuralHouse;
+
+public interface AdminInterface extends Remote {
+
+
+ public Vector<RuralHouse> getAdditionRequests() throws RemoteException;
+
+ public Vector<RuralHouse> getDeletionRequests() throws RemoteException ;
+
+ public Vector<Account> getOwnerAdditionRequests() throws RemoteException ;
+
+ public void removeHouseAdditionRequests(RuralHouse house) throws RemoteException ;
+
+ public void removeHouseDeletionRequests(RuralHouse house) throws RemoteException ;
+
+ public void removeOwnerAdditionRequests(Account acc) throws RemoteException ;
+
+ public boolean addAdditionRequest(RuralHouse rh) throws RemoteException ;
+
+ public boolean addDeletionRequest(RuralHouse rh) throws RemoteException ;
+
+ public boolean addAccount(Account acc) throws RemoteException ;
+
+ public void saveInstance() throws RemoteException;
+
+
+}
--- /dev/null
+package common;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.util.Date;
+import java.util.Vector;
+
+import domain.Booking;
+import domain.Client;
+import domain.RuralHouse;
+import exceptions.OfferCanNotBeBooked;
+
+public interface BookingInterface extends Remote {
+
+
+ public int getNumber() throws RemoteException;
+
+
+ public void removeDenyBooking(Booking b) throws RemoteException;
+
+
+ public void acceptBooking(Booking b) throws RemoteException;
+
+ public Vector<Booking> createBooking(RuralHouse ruralHouse, Date firstDate,
+ Date lastDate, Client client)
+ throws OfferCanNotBeBooked,RemoteException ;
+
+}
\ No newline at end of file
-package businessLogic;
+package common;
+import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Vector;
import domain.Owner;
import domain.RuralHouse;
-public interface HouseManagerInterface {
+public interface HouseInterface extends Remote {
// For future implementation
// public void modifyHouse(int houseName, Owner owner,
// String description, String town, int nRooms, int nKitchens,
// int nBaths, int nLivings, int nParkings);
- public void removeHouse(RuralHouse rh, Owner owner);
+ public void removeHouse(RuralHouse rh, Owner owner)throws RemoteException;
- public Vector<RuralHouse> getHouses(String name,String town,int nBed , int nKit, int nBath, int nPark, int nLiv) ;
+ public Vector<RuralHouse> getHouses(String name,String town,int nBed , int nKit, int nBath, int nPark, int nLiv) throws RemoteException;
/**
* This method retrieves the existing rural houses
* @return a Set of rural houses
*/
public Vector<RuralHouse> getAllRuralHouses()throws RemoteException,
- Exception;
+ Exception, RemoteException;
- public boolean registerNewHouse(RuralHouse rh);
+ public boolean registerNewHouse(RuralHouse rh)throws RemoteException;
}
--- /dev/null
+package common;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+import domain.Account;
+
+public interface LoginInterface extends Remote {
+
+ public Account checkCredentials(String usr, String pwd)throws RemoteException;
+
+
+
+
+}
--- /dev/null
+package common;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.sql.Date;
+
+import domain.Offer;
+import domain.RuralHouse;
+import exceptions.BadDates;
+import exceptions.OverlappingOfferExists;
+
+public interface OfferInterface extends Remote {
+
+ /**
+ * This method creates an offer with a house number, first day, last day and
+ * price
+ *
+ * @param House
+ * number, start day, last day and price
+ * @return the created offer, or null, or an exception
+ */
+ public Offer createOffer(RuralHouse ruralHouse, Date firstDay,
+ Date lastDay, float price) throws OverlappingOfferExists, BadDates,
+ RemoteException, Exception;
+
+ public void deleteOffer(RuralHouse rh, Offer o) throws RemoteException,
+ Exception;
+
+}
-package businessLogic;
+package common;
+import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Vector;
import domain.Owner;
-public interface OwnerManagerInterface {
+public interface OwnerInterface extends Remote {
public Vector<Owner> getOwners() throws RemoteException,
--- /dev/null
+package configuration;
+
+import java.io.File;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class ConfigXML {
+ private String businessLogicNode;
+
+ private String portRMI;
+
+ private String serviceRMI;
+
+ private String javaPolicyPath;
+
+ private static String db4oFilename;
+
+ //Two possible values: "open" or "initialize"
+ private String dataBaseOpenMode;
+
+ //Two possible values: true (no instance of RemoteServer needs to be launched) or false (RemoteServer needs to be run first)
+ private boolean businessLogicLocal;
+
+ //Two possible values: true (if the database is in same node as business logic ) or false (in other case)
+ private boolean databaseLocal;
+
+ private String databaseNode;
+
+ private int activationDepth;
+
+ private int updateDepth;
+
+ private int databasePort;
+
+ private String user;
+
+ private String password;
+
+ public int getDatabasePort() {
+ return databasePort;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public int getActivationDepth() {
+ return activationDepth;
+ }
+
+ public int getUpdateDepth() {
+ return updateDepth;
+ }
+
+ public boolean isDatabaseLocal() {
+ return databaseLocal;
+ }
+
+ public boolean isBusinessLogicLocal() {
+ return businessLogicLocal;
+ }
+ private static ConfigXML theInstance = new ConfigXML();
+
+ private ConfigXML(){
+
+ try {
+ DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+ Document doc = dBuilder.parse(new File("config.xml"));
+ doc.getDocumentElement().normalize();
+
+ NodeList list = doc.getElementsByTagName("config");
+ Element config = (Element) list.item(0); // list.item(0) is a Node that is an Element
+
+
+ //Two possible values: true (no instance of RemoteServer needs to be launched) or false (RemoteServer needs to be run first)
+ String value= ((Element)config.getElementsByTagName("businessLogic").item(0)).getAttribute("local");
+ businessLogicLocal=value.equals("true");
+
+ businessLogicNode = getTagValue("businessLogicNode", config);
+
+ portRMI = getTagValue("portRMI", config);
+
+ serviceRMI = getTagValue("serviceRMI", config);
+
+ javaPolicyPath= getTagValue("javaPolicyPath", config);
+
+ db4oFilename = getTagValue("db4oFilename", config);
+
+ //Two possible values: true (no instance of RemoteServer needs to be launched) or false (RemoteServer needs to be run first)
+ value= ((Element)config.getElementsByTagName("database").item(0)).getAttribute("local");
+ databaseLocal=value.equals("true");
+
+
+ //Two possible values: "open" or "initialize"
+ dataBaseOpenMode= getTagValue("dataBaseOpenMode", config);
+
+
+ databaseNode = getTagValue("databaseNode", config);
+
+ activationDepth=Integer.parseInt(getTagValue("activationDepth", config));
+
+ updateDepth=Integer.parseInt(getTagValue("updateDepth", config));
+
+
+ databasePort=Integer.parseInt(getTagValue("databasePort", config));
+
+ user=getTagValue("user", config);
+
+ password=getTagValue("password", config);
+
+ System.out.print("Read from config.xml: ");
+ System.out.print("\t businessLogicLocal="+businessLogicLocal);
+ System.out.print("\t databaseLocal="+databaseLocal);
+ System.out.println("\t dataBaseOpenMode="+dataBaseOpenMode);
+
+ } catch (Exception e) {
+ System.out.println("Error in ConfigXML.java: problems with config.xml");
+ e.printStackTrace();
+ }
+
+
+
+
+ }
+
+ private static String getTagValue(String sTag, Element eElement)
+ {
+ NodeList nlList= eElement.getElementsByTagName(sTag).item(0).getChildNodes();
+ Node nValue = (Node) nlList.item(0);
+
+ return nValue.getNodeValue();
+
+ }
+
+ public static ConfigXML getInstance() {
+ return theInstance;
+ }
+
+ public String getBusinessLogicNode() {
+ return businessLogicNode;
+ }
+
+ public String getPortRMI() {
+ return portRMI;
+ }
+
+ public String getServiceRMI() {
+ return serviceRMI;
+ }
+ public String getDb4oFilename(){
+ return db4oFilename;
+ }
+ public String getJavaPolicyPath(){
+ return javaPolicyPath;
+ }
+ public String getDataBaseOpenMode(){
+ return dataBaseOpenMode;
+ }
+
+ public String getDatabaseNode() {
+ return databaseNode;
+ }
+
+}
--- /dev/null
+package configuration;
+
+public class ___IntNames {
+ private static String serverPath = "rmi://158.227.140.215:9999//";
+ public static String AdminManager = serverPath+"AdM";
+ public static String BookingManager = serverPath+"BoM";
+ public static String HouseManager = serverPath+"HoM";
+ public static String LoginManager = serverPath+"LoM";
+ public static String OfferManager = serverPath+"OfM";
+ public static String OwnerManager = serverPath+"OwM";
+
+}
--- /dev/null
+package domain;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+
+
+public class Account implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+
+ private byte[] username;
+ private byte[] password;
+ private byte[] salt;
+
+
+ private Owner owner;
+ private boolean admin = false;
+
+
+ public Account(String usr){
+
+
+ }
+ public Account(String usr, String pass, boolean isAdmin) {
+
+
+ }
+
+ public Account(String usr, String pass, Owner ow) {
+
+
+ }
+
+ public byte[] getUsername() {
+ return username;
+ }
+
+ public byte[] getPassword() {
+ return password;
+ }
+
+ public Owner getOwner() {
+ return owner;
+ }
+
+ public boolean getAdmin() {
+ return admin;
+ }
+
+ public void setAdmin(boolean admin) {
+ this.admin = admin;
+ }
+
+ public byte[] getSalt() {
+ return salt;
+ }
+
+ public void setSalt(byte[] salt) {
+ this.salt = salt;
+ }
+
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Account other = (Account) obj;
+ if (!Arrays.equals(password, other.password))
+ return false;
+ if (!Arrays.equals(username, other.username))
+ return false;
+ return true;
+ }
+
+}
--- /dev/null
+package domain;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+
+import configuration.ConfigXML;
+
+public class Administrator implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ private static Administrator admin = null;
+ private static LinkedList<RuralHouse> addRequest;
+ private static LinkedList<RuralHouse> removeRequest;
+ private static LinkedList<Account> newOwnerRequest;
+ static ConfigXML c;
+
+ private Administrator() {
+ addRequest = new LinkedList<RuralHouse>();
+ removeRequest = new LinkedList<RuralHouse>();
+ newOwnerRequest = new LinkedList<Account>();
+ }
+
+ public static Administrator getInstance() {
+ return null;
+
+
+ }
+
+ public static void saveInstance() {
+
+ }
+
+ public LinkedList<RuralHouse> getAddRequest() {
+ return addRequest;
+ }
+
+ public LinkedList<RuralHouse> getRemoveRequest() {
+ return removeRequest;
+ }
+
+ public void setAddRequest(LinkedList<RuralHouse> addRequest) {
+ Administrator.addRequest = addRequest;
+ }
+
+ public void setRemoveRequest(LinkedList<RuralHouse> removeRequest) {
+ Administrator.removeRequest = removeRequest;
+
+ }
+
+ public LinkedList<Account> getNewOwnerRequest() {
+ return newOwnerRequest;
+ }
+
+ public void setNewOwnerRequest(LinkedList<Account> newOwnerRequest) {
+ Administrator.newOwnerRequest = newOwnerRequest;
+ }
+
+}
--- /dev/null
+package domain;
+
+import java.io.Serializable;
+import java.util.Date;
+
+public class Booking implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private int bookingNumber;
+ private boolean isPaid;
+ private Date bookingDate;
+ private Client client;
+ private Offer offer;
+
+
+ public Booking() {
+ }
+
+ public Booking(int bN , Offer offer,Client client) {
+
+ this.bookingNumber = bN;
+ this.offer = offer;
+ this.client=client;
+ //Booking date is assigned to actual date
+ this.bookingDate= new java.util.Date(System.currentTimeMillis());
+ this.isPaid=false;
+ }
+
+ public void imprimete(){
+ System.out.println(bookingNumber);
+ System.out.println(isPaid);
+ System.out.println(bookingDate);
+ System.out.println(client.toString());
+ System.out.println(offer);
+ }
+
+ public int getBookNumber() {
+ return this.bookingNumber;
+ }
+
+ public void setOffer(Offer offer) {
+ this.offer = offer;
+ }
+
+ public Offer getOffer() {
+ return this.offer;
+ }
+
+ public float getPrice() {
+ return this.offer.getPrice();
+ }
+
+ public void setBookDate(Date bookDate) {
+ this.bookingDate = bookDate;
+ }
+
+ public Date getBookDate() {
+ return this.bookingDate;
+ }
+
+ public void paid() {
+ this.isPaid = true;
+ }
+
+ public void notPaid() {
+ this.isPaid=false;
+ }
+
+ public boolean isPaid() {
+ return isPaid;
+ }
+
+
+
+ public Client getClient() {
+ return client;
+ }
+
+ public void setClient(Client client) {
+ this.client = client;
+ }
+
+}
\ No newline at end of file
--- /dev/null
+package domain;
+
+public class Client {
+
+ private String name;
+ private String mailAccount;
+ private String telephone;
+
+ public Client(String name, String mailAccount, String telephone) {
+ super();
+ this.name = name;
+ this.mailAccount = mailAccount;
+ this.telephone = telephone;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getMailAccount() {
+ return mailAccount;
+ }
+
+ public void setMailAccount(String mailAccount) {
+ this.mailAccount = mailAccount;
+ }
+
+ public String getTelephone() {
+ return telephone;
+ }
+
+ public void setTelephone(String telephone) {
+ this.telephone = telephone;
+ }
+
+}
--- /dev/null
+package domain;
+
+import java.io.Serializable;
+
+public enum Districs implements Serializable {
+
+ /**
+ *
+ */
+ BEA("Beatriz"), GUA("Guazate"), VEG("Vegas"), FAR("Farallón"), CED("Cedro"), MOT(
+ "Monte LLano"), RIN("Rincón"), PUE("Pueblo"), QUA("Quebrada Arriba"), QEB(
+ "Quebrada Abajo"), TOI("Toita"), MAB("Matón Abajo"), MAA(
+ "Matón Arriba"), PIE("Piedras"), PAV("Pasto Viejo"), PEA(
+ "PedroAvila"), SUM("Sumido"), LAP("Lapa"), CER("Cercadillo"), JAJ(
+ "JájomeAlto"), CUL("CulebrasAbajo");
+
+ private static final long serialVersionUID = 1L;
+
+
+ private final String longName;
+
+ Districs(String longName) {
+ this.longName = longName;
+ }
+
+ public static String[] longNames() {
+ String[] result = new String[Districs.values().length];
+ for (Districs d : Districs.values()) {
+ result[d.ordinal()] = d.longName;
+ }
+ return result;
+
+ }
+}
--- /dev/null
+package domain;
+
+import java.io.Serializable;
+
+public class HouseFeatures implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private int nRooms;
+ private int nKitchens;
+ private int nBaths;
+ private int nLivings;
+ private int nParkings;
+
+ public HouseFeatures(int nRooms, int nKitchens, int nBaths, int nLivings,
+ int nParkings) {
+ super();
+ this.setnRooms(nRooms);
+ this.setnKitchens(nKitchens);
+ this.setnBaths(nBaths);
+ this.setnLivings(nLivings);
+ this.setnParkings(nParkings);
+ }
+
+ public int getnRooms() {
+ return nRooms;
+ }
+
+ public void setnRooms(int nRooms) {
+ this.nRooms = nRooms;
+ }
+
+ public int getnKitchens() {
+ return nKitchens;
+ }
+
+ public void setnKitchens(int nKitchens) {
+ this.nKitchens = nKitchens;
+ }
+
+ public int getnBaths() {
+ return nBaths;
+ }
+
+ public void setnBaths(int nBaths) {
+ this.nBaths = nBaths;
+ }
+
+ public int getnLivings() {
+ return nLivings;
+ }
+
+ public void setnLivings(int nLivings) {
+ this.nLivings = nLivings;
+ }
+
+ public int getnParkings() {
+ return nParkings;
+ }
+
+ public void setnParkings(int nParkings) {
+ this.nParkings = nParkings;
+ }
+
+}
--- /dev/null
+package domain;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.Vector;
+
+
+@SuppressWarnings("serial")
+public class Offer implements Serializable {
+
+
+ private int offerNumber;
+ private Date firstDay; // Dates are stored as java.util.Date objects instead of java.sql.Date objects
+ private Date lastDay; // because, they are not well stored in db4o as java.util.Date objects
+ private float price; // This is coherent because objects of java.sql.Date are objects of java.util.Date ç
+ private boolean isBooked;
+ private Vector<Booking> bookings = new Vector<Booking>(); // That is: java.sql.Date is a subclass (or extends) java.util.Date
+ private RuralHouse ruralHouse;
+
+
+ public Offer(int offerNumber,RuralHouse ruralHouse, Date firstDay, Date lastDay, float price){
+ this.firstDay=firstDay;
+ this.lastDay=lastDay;
+ this.price=price;
+ this.ruralHouse=ruralHouse;
+ this.offerNumber=offerNumber;
+ }
+ /**
+ * Get the house number of the offer
+ *
+ * @return the house number
+ */
+ public RuralHouse getRuralHouse() {
+ return this.ruralHouse;
+ }
+
+ /**
+ * Set the house number to a offer
+ *
+ * @param house number
+ */
+ public void setRuralHouse(RuralHouse ruralHouse) {
+ this.ruralHouse = ruralHouse;
+ }
+
+
+ /**
+ * Get the offer number
+ *
+ * @return offer number
+ */
+ public int getOfferNumber() {
+ return this.offerNumber;
+ }
+
+
+
+ /**
+ * Get the first day of the offer
+ *
+ * @return the first day
+ */
+ public Date getFirstDay() {
+ return this.firstDay;
+ }
+
+ /**
+ * Set the first day of the offer
+ *
+ * @param firstDay
+ * The first day
+ */
+ public void setFirstDay(Date firstDay) {
+ this.firstDay = firstDay;
+ }
+
+ /**
+ * Get the last day of the offer
+ *
+ * @return the last day
+ */
+ public Date getLastDay() {
+ return this.lastDay;
+ }
+
+ /**
+ * Set the last day of the offer
+ *
+ * @param lastDay
+ * The last day
+ */
+ public void setLastDay(Date lastDay) {
+ this.lastDay = lastDay;
+ }
+
+ /**
+ * Get the price
+ *
+ * @return price
+ */
+ public float getPrice() {
+ return this.price;
+ }
+
+ /**
+ * Set the price
+ *
+ * @param price
+ */
+ public void setPrice(float price) {
+ this.price = price;
+ }
+
+
+ /**
+ * This method creates a book with a corresponding parameters
+ *
+ * @param First day, last day, house number and telephone
+ * @return a book
+ */
+ public Vector<Booking> createBooking(int numBooking,Client client) {
+ Booking b = new Booking(numBooking,this,client);
+ this.bookings.add(b);
+ return this.bookings;
+
+ }
+
+ public String toString(){
+ return firstDay.toString()+", "+lastDay.toString()+", "+price;
+ }
+ public Vector<Booking> getBookings() {
+ return bookings;
+ }
+ public void setBookings(Vector<Booking> bookings) {
+ this.bookings = bookings;
+ }
+ public boolean isBooked() {
+ return isBooked;
+ }
+ public void setBooked(boolean isBooked) {
+ this.isBooked = isBooked;
+ }
+}
\ No newline at end of file
--- /dev/null
+package domain;
+
+import java.io.Serializable;
+import java.util.Vector;
+
+public class Owner implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private String bankAccount = "";
+ private String name = "";
+ private String mailAccount = "";
+ private Vector<RuralHouse> ruralHouses;
+
+// public Owner(String name) {
+// this.name = name;
+// ruralHouses = new Vector<RuralHouse>();
+// }
+
+ public Owner(String name, String bankAccount,String mail) {
+ this.bankAccount = bankAccount;
+ this.name = name;
+ this.mailAccount = mail;
+ ruralHouses = new Vector<RuralHouse>();
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getBankAccount() {
+ return this.bankAccount;
+ }
+
+ public void setBankAccount(String bankAccount) {
+ this.bankAccount = bankAccount;
+ }
+
+ public Vector<RuralHouse> getRuralHouses(){
+ return this.ruralHouses;
+ }
+
+
+
+ public RuralHouse addRuralHouse(String houseName, String description,
+ String town, int nRooms, int nKitchens, int nBaths, int nLivings,
+ int nParkings) {
+ HouseFeatures feature = new HouseFeatures(nRooms, nKitchens, nBaths, nLivings, nParkings);
+ RuralHouse rh = new RuralHouse(houseName, this, description, town,feature);
+ ruralHouses.add(rh);
+ return rh;
+ }
+
+ public RuralHouse addRuralHouse(RuralHouse rh) {
+ ruralHouses.add(rh);
+ return rh;
+ }
+
+ public String toString() {
+ return name;
+ }
+
+ public String getMailAccount() {
+ return mailAccount;
+ }
+
+ public void setMailAccount(String mailAccount) {
+ this.mailAccount = mailAccount;
+ }
+
+ public Vector<Offer> getAllOffers (){
+ Vector<Offer> offers = new Vector<Offer>();
+ for(RuralHouse rh: this.ruralHouses){
+ for(Offer of : rh.getAllOffers()){
+ offers.add(of);
+ }
+ }
+ return offers;
+ }
+
+}
\ No newline at end of file
--- /dev/null
+package domain;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Vector;
+
+public class RuralHouse implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private String houseName;
+ private String description;
+ private Owner owner;
+ private String district;
+ private HouseFeatures features;
+ public Vector<Offer> offers;
+ public boolean isAccepted;
+
+ public RuralHouse() {
+ super();
+ }
+
+ public RuralHouse(String houseName, Owner owner, String description,
+ String ds, HouseFeatures features) {
+ this.houseName = houseName;
+ this.description = description;
+ this.owner = owner;
+ this.district = ds;
+ this.features = features;
+ offers = new Vector<Offer>();
+ }
+
+ public String getHouseName() {
+ return houseName;
+ }
+
+ public void setHouseName(String houseName) {
+ this.houseName = houseName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Owner getOwner() {
+ return owner;
+ }
+
+ public void setOwner(Owner owner) {
+ this.owner = owner;
+ }
+
+ public String getDistrict() {
+ return district;
+ }
+
+ public void setDistrict(String ds) {
+ this.district = ds;
+ }
+
+ public HouseFeatures getFeatures() {
+ return features;
+ }
+
+ public void setFeatures(HouseFeatures features) {
+ this.features = features;
+ }
+
+ public String toString() {
+ return this.houseName + ": " + this.district;
+ }
+
+ public Offer createOffer(int offerNumber, Date firstDay, Date lastDay,
+ float price) {
+ Offer off = new Offer(offerNumber, this, firstDay, lastDay, price);
+ offers.add(off);
+ return off;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ RuralHouse other = (RuralHouse) obj;
+ if (houseName == null) {
+ if (other.houseName != null)
+ return false;
+ } else if (!houseName.equals(other.houseName))
+ return false;
+ return true;
+ }
+
+ /**
+ * This method obtains available offers for a concrete house in a certain
+ * period
+ *
+ * @param houseName
+ * , the house number where the offers must be obtained
+ * @param firstDay
+ * , first day in a period range
+ * @param lastDay
+ * , last day in a period range
+ * @return a vector of offers(Offer class) available in this period
+ */
+ public Vector<Offer> getOffers(Date firstDay, Date lastDay) {
+ Vector<Offer> availableOffers = new Vector<Offer>();
+ Iterator<Offer> e = offers.iterator();
+ Offer offer;
+ while (e.hasNext()) {
+ offer = e.next();
+ if ((offer.getFirstDay().compareTo(firstDay) >= 0)
+ && (offer.getLastDay().compareTo(lastDay) <= 0)
+ && (!offer.isBooked()))
+ availableOffers.add(offer);
+ }
+ return availableOffers;
+ }
+
+ public Vector<Offer> getAllOffers() {
+
+ return this.offers;
+ }
+
+ /**
+ * This method obtains the offer that match exactly with a given dates that
+ * has not been booked
+ *
+ * @param firstDay
+ * , first day in a period range
+ * @param lastDay
+ * , last day in a period range
+ * @return the offer(Offer class) available for a this period
+ */
+ public Offer findOffer(Date firstDay, Date lastDay) {
+ Iterator<Offer> e = offers.iterator();
+ Offer offer = null;
+ while (e.hasNext()) {
+ offer = e.next();
+ if ((offer.getFirstDay().compareTo(firstDay) == 0)
+ && (offer.getLastDay().compareTo(lastDay) == 0)
+ && (!offer.isBooked()))
+ return offer;
+ }
+ return null;
+ }
+
+ public Offer overlapsWith(Date firstDay, Date lastDay) {
+
+ Iterator<Offer> e = offers.iterator();
+ Offer offer = null;
+ while (e.hasNext()) {
+ offer = e.next();
+ if ((offer.getFirstDay().compareTo(lastDay) < 0)
+ && (offer.getLastDay().compareTo(firstDay) > 0))
+ return offer;
+ }
+ return null;
+
+ }
+
+}
--- /dev/null
+package exceptions;
+public class BadDates extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public BadDates()
+ {
+ super();
+ }
+ /**This exception is triggered if first date is greater than last date in offers
+ *@param String
+ *@return None
+ */
+ public BadDates(String s)
+ {
+ super(s);
+ }
+}
\ No newline at end of file
--- /dev/null
+package exceptions;
+public class DB4oManagerCreationException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public DB4oManagerCreationException()
+ {
+ super();
+ }
+ /**This exception is triggered if there is a problem when constructor of DB4oManager is executed
+ *@param String
+ *@return None
+ */
+ public DB4oManagerCreationException(String s)
+ {
+ super(s);
+ }
+}
\ No newline at end of file
--- /dev/null
+package exceptions;
+public class OfferCanNotBeBooked extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public OfferCanNotBeBooked() {
+ super();
+ }
+
+ /**This exception is triggered if an offer cannot be booked
+ *@param String
+ *@return None
+ */
+ public OfferCanNotBeBooked(String s)
+ {
+ super(s);
+ }
+}
\ No newline at end of file
--- /dev/null
+package exceptions;
+public class OverlappingOfferExists extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public OverlappingOfferExists()
+ {
+ super();
+ }
+ /**This exception is triggered if there exists an overlapping offer
+ *@param String
+ *@return None
+ */
+ public OverlappingOfferExists(String s)
+ {
+ super(s);
+ }
+}
\ No newline at end of file
import java.awt.event.FocusListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.rmi.Naming;
import java.sql.Date;
import java.text.DateFormat;
import java.util.Calendar;
import javax.swing.JLabel;
import javax.swing.JTextField;
-import businessLogic.OfferManager;
-
import com.toedter.calendar.JCalendar;
+import common.OfferInterface;
+import configuration.___IntNames;
import domain.RuralHouse;
import exceptions.BadDates;
import exceptions.OverlappingOfferExists;
float price= Float.parseFloat(jTextField3.getText());
//Obtain the business logic from a StartWindow class (local or remote)
- OfferManager offerM = new OfferManager();
-
+ OfferInterface offerM = null;
+ try {
+ offerM = (OfferInterface) Naming
+ .lookup(___IntNames.OfferManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
+
offerM.createOffer(ruralHouse, firstDay, lastDay, price);
jLabel5.setText("Offer created");
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
-import domain.Administrator;
-
public class AdminMenuGUI extends JFrame {
/**
public AdminMenuGUI() {
- Administrator.getInstance();
this.setTitle("Administrator Menu");
this.getContentPane().setLayout(null);
setBounds(100, 100, 450, 473);
JButton btnOwneraddition = new JButton("OwnerAddition");
btnOwneraddition.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- Frame a = new ownerAddittionRequests();
+ Frame a = new listOfOwnerAddittionRequests();
a.setVisible(true);
}
});
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
+import java.rmi.Naming;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JRadioButton;
import javax.swing.border.EmptyBorder;
-import businessLogic.OfferManager;
+import common.OfferInterface;
+
+import configuration.___IntNames;
import domain.Offer;
import domain.Owner;
import domain.RuralHouse;
private void actionListenerButton(ActionEvent e) {
Offer toDel = (Offer) comboBox_1.getSelectedItem();
- OfferManager oM = new OfferManager();
+ OfferInterface oM = null;
+ try {
+ oM = (OfferInterface) Naming
+ .lookup(___IntNames.OfferManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
+
try {
oM.deleteOffer((RuralHouse) comboBox.getSelectedItem(), toDel);
comboBox_1.removeItem(toDel);
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
+import java.rmi.Naming;
import java.util.Date;
import java.util.Enumeration;
import java.util.Vector;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
-import businessLogic.BookingManager;
+import common.BookingInterface;
+
+import configuration.___IntNames;
import domain.Booking;
import domain.Client;
import domain.Offer;
while (rhs.hasMoreElements()) {
Offer of = rhs.nextElement();
if (of.getBookings() == null
- || !(of.getBookings().size() == 1 && of.isBooked())) {
+ || of.isBooked()) {
Vector<Object> row = new Vector<Object>();
row.add(of.getOfferNumber());
row.add(of.getFirstDay());
}
private void jButton_ActionPerformed(ActionEvent arg0) {
- BookingManager bookingM = new BookingManager();
+ BookingInterface bookingM = null;
+ try {
+ bookingM = (BookingInterface) Naming
+ .lookup(___IntNames.BookingManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
+
+ //RegExp to see if telephone number is correct??TODO
if (telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}")
&& mailField
- .getText()
- .matches(
- "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
- && !nameField.getText().isEmpty()) {
+ .getText()
+ .matches(
+ "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
+ && !nameField.getText().isEmpty()) {
labelPhone.setText("");
Vector<Booking> book = null;
try {
import java.awt.Color;
import java.awt.Frame;
+import java.awt.KeyEventDispatcher;
+import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
-import businessLogic.LoginManager;
-import businessLogic.LoginManagerInterface;
+import common.LoginInterface;
+
+import configuration.___IntNames;
import domain.Account;
public class LoginGUI extends JFrame {
private JPanel jContentPane = null;
private JTextField usernameField;
private JPasswordField passwordField;
- private LoginManagerInterface loginManager = new LoginManager();
+ private LoginInterface loginManager = null;
private JLabel loginFeedback;
private JButton btnRegister;
+ protected boolean isFocused = false;
public LoginGUI() {
super();
initialize();
}
private void initialize() {
+ try {
+ loginManager = (LoginInterface) Naming
+ .lookup(___IntNames.LoginManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
this.setSize(449, 293);
this.setContentPane(getJContentPane());
this.setTitle("Login");
+ addWindowListener(new WindowAdapter() {
+
+ @Override
+ public void windowGainedFocus(WindowEvent e) {
+ isFocused = true;
+ }
+
+ @Override
+ public void windowLostFocus(WindowEvent e) {
+ isFocused = false;
+ }
+ });
+
+ KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
+
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent e) {
+ if (isFocused && e.getKeyCode() == KeyEvent.VK_ENTER )
+ jButton_ActionPerformed();
+
+ return false;
+ }});
}
+
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
- jButton_ActionPerformed(arg0);
+ jButton_ActionPerformed();
}
});
loginButton.setBounds(95, 179, 117, 25);
}
- private void jButton_ActionPerformed(ActionEvent e){
+
+
+
+ private void jButton_ActionPerformed(){
- Account acc = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword()));
+ Account acc = null;
+ try {
+ acc = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword()));
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
if (acc == null) loginFeedback.setText("Incorrect username or password");
else if( acc.getAdmin()) {
this.setVisible(false);
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
-import businessLogic.HouseManager;
+import common.HouseInterface;
+
+import configuration.___IntNames;
import domain.Districs;
import domain.HouseFeatures;
import domain.Owner;
baths_f.getText()), new Integer(
lRooms_f.getText()), new Integer(
parkings_f.getText())));
- HouseManager hm = new HouseManager();
-
- if (hm.registerNewHouse(newRh)) {
- owner.getRuralHouses().add(newRh);
- houseBox.removeItem(rh);
- feedback.setText("House properly modified");
- } else
- feedback.setText("Imposible to modify the house");
+ HouseInterface hm= null;
+ try {
+ hm = (HouseInterface) Naming
+ .lookup(___IntNames.HouseManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
+
+ try {
+ if (hm.registerNewHouse(newRh)) {
+ owner.getRuralHouses().add(newRh);
+ houseBox.removeItem(rh);
+ feedback.setText("House properly modified");
+ } else
+ feedback.setText("Imposible to modify the house");
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
});
import java.awt.event.ItemListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.rmi.Naming;
import java.sql.Date;
import java.text.DateFormat;
import java.util.Calendar;
import javax.swing.JLabel;
import javax.swing.JTextField;
-import businessLogic.OfferManager;
-
import com.toedter.calendar.JCalendar;
+import common.OfferInterface;
+import configuration.___IntNames;
import domain.Offer;
import domain.RuralHouse;
import exceptions.BadDates;
// Obtain the business logic from a StartWindow class (local or
// remote)
- OfferManager offerM = new OfferManager();
+ OfferInterface offerM = null;
+ try {
+ offerM = (OfferInterface) Naming
+ .lookup(___IntNames.OfferManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
+
offerM.deleteOffer(ruralHouse, (Offer) comboBox_o.getSelectedItem());
offerM.createOffer(ruralHouse, firstDay, lastDay, price);
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
-import businessLogic.AdminManager;
+import common.AdminInterface;
+
+import configuration.___IntNames;
import domain.Account;
import domain.Owner;
private JPanel panel;
private JTextField nameField;
private JTextField userNameField;
- private AdminManager am = new AdminManager();
+ private AdminInterface am = null;
private JTextField passField;
private JTextField bank1Field;
private JTextField bank2Field;
* Create the frame.
*/
public OwnerRegistrationGUI() {
+
+ try {
+ am = (AdminInterface) Naming
+ .lookup(___IntNames.AdminManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
setTitle("Owner registration");
setBounds(100, 100, 500, 400);
panel = new JPanel();
Account acc = new Account(this.userNameField.getText(),
this.passField.getText(), own);
- if (this.am.addAccount(acc)) {
- this.feedback.setText("Request sended");
- } else {
- this.feedback.setText("Can't send the request");
+ try {
+ if (this.am.addAccount(acc)) {
+ this.feedback.setText("Request sended");
+ } else {
+ this.feedback.setText("Can't send the request");
+ }
+ } catch (RemoteException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
}
}
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
import java.sql.Date;
import java.text.DateFormat;
import java.util.Calendar;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
-import businessLogic.HouseManager;
-
import com.toedter.calendar.JCalendar;
+import common.HouseInterface;
+import configuration.___IntNames;
import domain.Districs;
import domain.RuralHouse;
private final JTextField nBaths = new JTextField();
private final JLabel lblParkings = new JLabel("Parking slots:");
private final JTextField nParkings = new JTextField();
- private HouseManager houseMan = new HouseManager();
+ private HouseInterface houseMan = null;
private final JLabel lblNumberOfLivings = new JLabel("Number of Livings:");
private final JTextField nLivings = new JTextField();
private final JLabel feedback = new JLabel("");
public QueryAvailabilityGUI2() {
+
+ try {
+ houseMan = (HouseInterface) Naming
+ .lookup(___IntNames.HouseManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
nLivings.setText("0");
nLivings.setColumns(10);
nParkings.setText("0");
private void jButton1_actionPerformed(ActionEvent e) {
if (this.district.isSelected()) {
- Vector<RuralHouse> houses = houseMan.getHouses(null, jComboBox1
- .getSelectedItem().toString(), Integer.parseInt(nBedrooms
- .getText()), Integer.parseInt(nKitchens.getText()), Integer
- .parseInt(nBaths.getText()), Integer.parseInt(nParkings
- .getText()), Integer.parseInt(nLivings.getText()));
+ Vector<RuralHouse> houses = null;
+ try {
+ houses = houseMan.getHouses(null, jComboBox1
+ .getSelectedItem().toString(), Integer.parseInt(nBedrooms
+ .getText()), Integer.parseInt(nKitchens.getText()), Integer
+ .parseInt(nBaths.getText()), Integer.parseInt(nParkings
+ .getText()), Integer.parseInt(nLivings.getText()));
+ } catch (NumberFormatException | RemoteException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
listOfHousesGUI list = new listOfHousesGUI(houses);
list.setVisible(true);
} else if (this.ruralHouseName.isSelected()) {
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JRadioButton;
import javax.swing.border.EmptyBorder;
-import businessLogic.AdminManager;
+import common.AdminInterface;
+
+import configuration.___IntNames;
import domain.Owner;
import domain.RuralHouse;
private Owner owner;
private JComboBox<RuralHouse> comboBox;
private JButton btnDelete;
- private AdminManager am;
+ private AdminInterface am = null;
JLabel feedback = new JLabel("");
/**
* Create the frame.
*/
public RequestDeleteHouseGUI(Owner o) {
- am = new AdminManager();
+ try {
+ am = (AdminInterface) Naming
+ .lookup(___IntNames.AdminManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
this.owner = o;
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
private void actionListenerButton(ActionEvent e){
RuralHouse toDel = (RuralHouse)comboBox.getSelectedItem();
- if(am.addDeletionRequest(toDel)){
- feedback.setText("Delete request sended");
-
- }else{
- feedback.setText("Request cannot be sended(Already sended)");
+ try {
+ if(am.addDeletionRequest(toDel)){
+ feedback.setText("Delete request sended");
+
+ }else{
+ feedback.setText("Request cannot be sended(Already sended)");
+ }
+ } catch (RemoteException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
}
}
}
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
-import businessLogic.AdminManager;
+import common.AdminInterface;
+
+import configuration.___IntNames;
import domain.Districs;
import domain.HouseFeatures;
import domain.Owner;
private JLabel lblBaths;
private JTextField baths_f;
private JButton btnRegister;
- private AdminManager am;
+ private AdminInterface am = null;
private JComboBox<String> comboBox;
public RequestNewHouseGUI(Owner o) {
comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
Districs.longNames()));
- am = new AdminManager();
+ try {
+ am = (AdminInterface) Naming
+ .lookup(___IntNames.AdminManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
this.setTitle("New House");
setBackground(Color.WHITE);
this.getContentPane().setLayout(null);
e.printStackTrace();
}
- if(am.addAdditionRequest(rh)){
- feedback.setText("Request sended");
- }else{
- feedback.setText("Request cannot be sended(Already added)");
+ try {
+ if(am.addAdditionRequest(rh)){
+ feedback.setText("Request sended");
+ }else{
+ feedback.setText("Request cannot be sended(Already added)");
+ }
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
}
});
*/
import java.awt.Color;
import java.awt.Font;
+import java.awt.KeyEventDispatcher;
+import java.awt.KeyboardFocusManager;
+import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.rmi.RMISecurityManager;
import configuration.ConfigXML;
-
@SuppressWarnings("deprecation")
public class StartWindow extends JFrame {
-
+
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JButton boton3 = null;
private static configuration.ConfigXML c;
- //public static ApplicationFacadeInterface facadeInterface;
+ // public static ApplicationFacadeInterface facadeInterface;
private JLabel lblNewLabel;
-
+
public static void main(String[] args) {
StartWindow a = new StartWindow();
- a.setVisible(true);
+ System.setProperty("java.security.policy", "java.policy");
+
+ a.setVisible(true);
+
try {
- c=ConfigXML.getInstance();
+ c = ConfigXML.getInstance();
System.setProperty("java.security.policy", c.getJavaPolicyPath());
-
+
System.setSecurityManager(new RMISecurityManager());
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- c=configuration.ConfigXML.getInstance();
+ c = configuration.ConfigXML.getInstance();
- }catch (com.db4o.ext.DatabaseFileLockedException e) {
- a.lblNewLabel.setText("Database locked: Do not run BusinessLogicServer or BusinessLogicServer!!");
- a.lblNewLabel.setForeground(Color.RED);
- System.out.println("Error in StartWindow: "+e.toString());
+ } catch (com.db4o.ext.DatabaseFileLockedException e) {
+ a.lblNewLabel
+ .setText("Database locked: Do not run BusinessLogicServer or BusinessLogicServer!!");
+ a.lblNewLabel.setForeground(Color.RED);
+ System.out.println("Error in StartWindow: " + e.toString());
} catch (Exception e) {
- a.lblNewLabel.setText("Error: "+e.toString());
- a.lblNewLabel.setForeground(Color.RED);
- System.out.println("Error in StartWindow: "+e.toString());
+ a.lblNewLabel.setText("Error: " + e.toString());
+ a.lblNewLabel.setForeground(Color.RED);
+ System.out.println("Error in StartWindow: " + e.toString());
}
-
-
}
+
/**
* This is the default constructor
*/
System.exit(1);
}
+
});
+
+ KeyboardFocusManager.getCurrentKeyboardFocusManager()
+ .addKeyEventDispatcher(new KeyEventDispatcher() {
+
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent e) {
+ switch (e.getKeyCode()) {
+
+ case KeyEvent.VK_ESCAPE:
+ System.exit(1);
+
+ }
+ return false;
+ }
+ });
initialize();
- //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ // this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
-
-
/**
* This method initializes this
}
return boton2;
}
-
+
/**
* This method initializes boton3
*
boton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
// C?digo cedido por la universidad
- //JFrame a = new QueryAvailabilityWindow();
+ // JFrame a = new QueryAvailabilityWindow();
JFrame a = new QueryAvailabilityGUI2();
a.setVisible(true);
}
return boton3;
}
-
private JLabel getLblNewLabel() {
if (lblNewLabel == null) {
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
import java.util.Enumeration;
import java.util.Vector;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
-import businessLogic.AdminManager;
-import businessLogic.HouseManager;
-import businessLogic.HouseManagerInterface;
-import domain.Administrator;
+import common.AdminInterface;
+import common.HouseInterface;
+
+import configuration.___IntNames;
import domain.RuralHouse;
public class listOfAdditionRequestsGUI extends JFrame {
private JPanel contentPane;
private JTable table;
private DefaultTableModel tableModel;
- private AdminManager am = new AdminManager();
+ private AdminInterface am = null;
private Vector<RuralHouse> houses;
/**
* Create the frame.
*/
public listOfAdditionRequestsGUI() {
+
+ try {
+ am = (AdminInterface) Naming
+ .lookup(___IntNames.AdminManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
+
setTitle("Adding requests");
try {
this.houses= am.getAdditionRequests();
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
- HouseManagerInterface hm = new HouseManager();
+ HouseInterface hm= null;
+ try {
+ hm = (HouseInterface) Naming
+ .lookup(___IntNames.HouseManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
+
RuralHouse rh = houses.get(table.getSelectedRow());
//TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
- hm.registerNewHouse(rh);
- am.removeHouseAdditionRequests(rh);
- Administrator.saveInstance();
+ try {
+ hm.registerNewHouse(rh);
+ am.removeHouseAdditionRequests(rh);
+ am.saveInstance();
+ } catch (RemoteException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
houses.remove(rh);
}
public void actionPerformed(ActionEvent arg0) {
if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
RuralHouse rh = houses.get(table.getSelectedRow());
- am.removeHouseAdditionRequests(rh);
- Administrator.saveInstance();
+ try {
+ am.removeHouseAdditionRequests(rh);
+ am.saveInstance();
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
houses.remove(rh);
}
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.rmi.RemoteException;
import java.util.Enumeration;
import java.util.Vector;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
-import businessLogic.BookingManager;
+import common.BookingInterface;
+
import domain.Booking;
import domain.Offer;
private JPanel contentPane;
private JTable table;
private Offer off;
- private BookingManager bookM = new BookingManager();
+ private BookingInterface bookM =null;
private DefaultTableModel tableModel;
private Vector<Booking> bookings = new Vector<Booking>();
public listOfBookingRequestsGUI(Offer of) {
setTitle("Adding requests");
this.off = of;
+
try {
init();
if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
Booking book = bookings.get(table.getSelectedRow());
- bookM.acceptBooking(book);
+ try {
+ bookM.acceptBooking(book);
+ } catch (RemoteException e1) {
+ e1.printStackTrace();
+ }
}
+
}
}
});
public void actionPerformed(ActionEvent arg0) {
if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
Booking book = bookings.get(table.getSelectedRow());
- bookM.removeDenyBooking(book);
+ try {
+ bookM.removeDenyBooking(book);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+
}
}
});
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
import java.util.Enumeration;
import java.util.Vector;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
-import businessLogic.AccountManager;
-import businessLogic.AdminManager;
+import common.AccountInterface;
+import common.AdminInterface;
+
+import configuration.___IntNames;
import domain.Account;
-import domain.Administrator;
-public class ownerAddittionRequests extends JFrame {
+public class listOfOwnerAddittionRequests extends JFrame {
/**
*
private JPanel contentPane;
private JTable table;
private DefaultTableModel tableModel;
- private AdminManager am = new AdminManager();
+ private AdminInterface am = null;
private Vector<Account> accounts;
/**
* Create the frame.
*/
- public ownerAddittionRequests() {
+ public listOfOwnerAddittionRequests() {
+ try {
+ am = (AdminInterface) Naming
+ .lookup(___IntNames.AdminManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
setTitle("Adding requests");
try {
- this.accounts= am.getOwnerAdditionReuests();
+ this.accounts= am.getOwnerAdditionRequests();
init();
} catch (Exception e) {
e.printStackTrace();
}
private void init() throws Exception {
+
+ try {
+ am = (AdminInterface) Naming
+ .lookup(___IntNames.AdminManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
setBounds(100, 100, 600, 450);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
- AccountManager ama = new AccountManager();
+ AccountInterface acm = null;
+
+ try {
+ acm = (AccountInterface) Naming
+ .lookup(___IntNames.AdminManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
Account accou = accounts.get(table.getSelectedRow());
- //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
- ama.addAccount(accou);
- am.removeOwnerAdditionRequests(accou);;
- Administrator.saveInstance();
+ try {
+ acm.addAccount(accou);
+ am.removeOwnerAdditionRequests(accou);
+ am.saveInstance();
+ } catch (RemoteException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
((DefaultTableModel)table.getModel()).removeRow(accounts.indexOf(accou));
accounts.remove(accou);
}
public void actionPerformed(ActionEvent arg0) {
if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
Account acc = accounts.get(table.getSelectedRow());
- am.removeOwnerAdditionRequests(acc);
- Administrator.saveInstance();
+ try {
+ am.removeOwnerAdditionRequests(acc);
+ am.saveInstance();
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
((DefaultTableModel)table.getModel()).removeRow(accounts.indexOf(acc));
accounts.remove(acc);
}
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
import java.util.Enumeration;
import java.util.Vector;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
-import businessLogic.AdminManager;
-import businessLogic.HouseManager;
-import businessLogic.HouseManagerInterface;
-import domain.Administrator;
+import common.AdminInterface;
+import common.HouseInterface;
+
+import configuration.___IntNames;
import domain.RuralHouse;
public class listOfRemovalRequestsGUI extends JFrame {
private JPanel contentPane;
private JTable table;
private DefaultTableModel tableModel;
- private AdminManager am = new AdminManager();
+ private AdminInterface am = null;
private Vector<RuralHouse> houses;
/**
* Create the frame.
*/
public listOfRemovalRequestsGUI() {
+ try {
+ am = (AdminInterface) Naming
+ .lookup(___IntNames.AdminManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
setTitle("Deleting requests");
try {
this.houses = am.getDeletionRequests();
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
- HouseManagerInterface hm = new HouseManager();
+ HouseInterface hm= null;
+ try {
+ hm = (HouseInterface) Naming
+ .lookup(___IntNames.HouseManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
RuralHouse rh = houses.get(table.getSelectedRow());
((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
- hm.removeHouse(rh, rh.getOwner());
+ try {
+ hm.removeHouse(rh, rh.getOwner());
+ am.removeHouseDeletionRequests(rh);
+ am.saveInstance();
+ } catch (RemoteException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
houses.remove(rh);
- am.removeHouseDeletionRequests(rh);
- Administrator.saveInstance();
+
}
RuralHouse rh = houses.get(table.getSelectedRow());
((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
houses.remove(rh);
- am.removeHouseDeletionRequests(rh);
- Administrator.saveInstance();
+ try {
+ am.removeHouseDeletionRequests(rh);
+ am.saveInstance();
+ } catch (RemoteException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
}
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/additionalLibs/jcalendar.jar"/>
<classpathentry kind="lib" path="lib/db4o/lib/db4o-8.0.249.16098-all-java5.jar"/>
- <classpathentry kind="lib" path="lib/javax.mail.jar"/>
+ <classpathentry kind="lib" path="lib/mail/javax.mail.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
/bin
/lib
+!lib/mail/
/db
-/src/*/*.class
\ No newline at end of file
+/src/*/*.class
package businessLogic;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+
import javax.mail.MessagingException;
+import common.AccountInterface;
import dataAccess.DB4oManager;
import domain.Account;
-public class AccountManager {
+public class AccountManager extends UnicastRemoteObject implements AccountInterface {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
private DB4oManager dbMngr;
- public AccountManager() {
+ public AccountManager() throws RemoteException {
try {
dbMngr = DB4oManager.getInstance();
} catch (Exception e) {
}
}
- public boolean addAccount(Account ac){
+ public boolean addAccount(Account ac) throws RemoteException {
if(this.dbMngr.addAccount(ac)){
try {
MailManager.getInstance().Send(ac.getOwner().getMailAccount(), "Entered into the system", "Congratulations");
} catch (MessagingException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
- public boolean removeAccount(Account ac){
+ public boolean removeAccount(Account ac)throws RemoteException {
if(this.dbMngr.removeAccount(ac))
return true;
return false;
package businessLogic;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;
+import common.AdminInterface;
+
import domain.Account;
import domain.Administrator;
import domain.RuralHouse;
-public class AdminManager {
- public AdminManager() {
+public class AdminManager extends UnicastRemoteObject implements AdminInterface {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+
+
+
+ public AdminManager() throws RemoteException {
}
- public Vector<RuralHouse> getAdditionRequests() {
+ public Vector<RuralHouse> getAdditionRequests() throws RemoteException {
return new Vector<RuralHouse>(Administrator.getInstance()
.getAddRequest());
}
- public Vector<RuralHouse> getDeletionRequests() {
+ public Vector<RuralHouse> getDeletionRequests() throws RemoteException {
return new Vector<RuralHouse>(Administrator.getInstance()
.getRemoveRequest());
}
- public Vector<Account> getOwnerAdditionReuests() {
+ public Vector<Account> getOwnerAdditionRequests() throws RemoteException {
return new Vector<Account>(Administrator.getInstance()
.getNewOwnerRequest());
}
- public void removeHouseAdditionRequests(RuralHouse house) {
+ public void removeHouseAdditionRequests(RuralHouse house) throws RemoteException {
Administrator.getInstance().getAddRequest().remove(house);
}
- public void removeHouseDeletionRequests(RuralHouse house) {
+ public void removeHouseDeletionRequests(RuralHouse house) throws RemoteException {
Administrator.getInstance().getRemoveRequest().remove(house);
}
- public void removeOwnerAdditionRequests(Account acc) {
+
+ public void removeOwnerAdditionRequests(Account acc) throws RemoteException {
Administrator.getInstance().getNewOwnerRequest().remove(acc);
}
- public boolean addAdditionRequest(RuralHouse rh) {
+
+ public boolean addAdditionRequest(RuralHouse rh) throws RemoteException {
if (this.getAdditionRequests().contains(rh)) {
return false;
}
return Administrator.getInstance().getAddRequest().add(rh);
+
}
- public boolean addDeletionRequest(RuralHouse rh) {
+ public boolean addDeletionRequest(RuralHouse rh) throws RemoteException {
if (this.getDeletionRequests().contains(rh))
return false;
+
return Administrator.getInstance().getRemoveRequest().add(rh);
+
}
- public boolean addAccount(Account acc) {
- if (this.getOwnerAdditionReuests().contains(acc)) {
+
+
+
+ public boolean addAccount(Account acc) throws RemoteException {
+ if (this.getOwnerAdditionRequests().contains(acc)) {
return false;
}
return Administrator.getInstance().getNewOwnerRequest().add(acc);
}
+ @Override
+ public void saveInstance() throws RemoteException {
+ Administrator.saveInstance();
+
+ }
+
+
+
// public boolean removeAccount(Account acc) {
// if (this.getDeletionRequests().contains(acc))
// return false;
package businessLogic;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
import java.util.Date;
import java.util.Vector;
-import javax.mail.MessagingException;
-
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
+import common.BookingInterface;
import dataAccess.DB4oManager;
import domain.Booking;
import domain.RuralHouse;
import exceptions.OfferCanNotBeBooked;
-public final class BookingManager {
+
+public final class BookingManager extends UnicastRemoteObject implements BookingInterface {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
private int bookingNumber = 0;
dataAccess.DB4oManager dbMngr;
private static BookingManager theBookingManager;
- public BookingManager() {
+ public BookingManager() throws RemoteException {
+ super();
try {
this.dbMngr = DB4oManager.getInstance();
} catch (Exception e) {
*
* @return the book number
*/
- public static int getNumber() {
- ObjectContainer db = DB4oManager.getContainer();
- BookingManager b = getInstance();
- b.bookingNumber++;
- db.store(b);
- db.commit();
- return b.bookingNumber;
- }
+ public int getNumber() throws RemoteException{
+ ObjectContainer db=DB4oManager.getContainer();
+ BookingManager b=getInstance();
+ b.bookingNumber++;
+ db.store(b);
+ db.commit();
+ return b.bookingNumber;
+ }
+
/**
* This method returns the instance of the BookingManager class
*
* @return the booking manager
+ * @throws RemoteException
*/
- public static BookingManager getInstance() {
- ObjectContainer db = DB4oManager.getContainer();
- BookingManager b = new BookingManager();
- ObjectSet<BookingManager> result = db.queryByExample(b);
- if (!result.hasNext()) {
- theBookingManager = new BookingManager();
- db.store(theBookingManager);
- db.commit();
- } else
- theBookingManager = (BookingManager) result.next();
+
+ public BookingManager getInstance() throws RemoteException {
+ ObjectContainer db=DB4oManager.getContainer();
+ BookingManager b = new BookingManager();
+ ObjectSet<BookingManager> result = db.queryByExample(b);
+ if (!result.hasNext()){
+ theBookingManager = new BookingManager();
+ db.store(theBookingManager);
+ db.commit();
+ } else theBookingManager=(BookingManager)result.next();
return theBookingManager;
}
- public void removeDenyBooking(Booking b){
+ public void removeDenyBooking(Booking b) throws RemoteException{
b.getOffer().getBookings().remove(b);
this.dbMngr.removeBooking(b);
}
- public void acceptBooking(Booking b){
+ public void acceptBooking(Booking b) throws RemoteException{
b.getOffer().setBooked(true);
for(Booking boo : b.getOffer().getBookings()){
if(!boo.equals(b))
b.getOffer().getBookings().remove(b);
}
this.dbMngr.acceptBooking(b.getOffer());
- try {
+ /*try {
MailManager.getInstance().Send(b.getClient().getMailAccount(), "Your booking has been accepted","Here should be the bill");
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- }
+ }*/
}
/**
*/
public Vector<Booking> createBooking(RuralHouse ruralHouse, Date firstDate,
Date lastDate, Client client)
- throws OfferCanNotBeBooked {
+ throws OfferCanNotBeBooked,RemoteException {
return dbMngr.createBooking(ruralHouse, firstDate, lastDate,
client);
package businessLogic;
import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;
+import common.HouseInterface;
+
import dataAccess.DB4oManager;
import domain.Owner;
import domain.RuralHouse;
-public class HouseManager implements HouseManagerInterface {
-
- private DB4oManager dbMngr;
- public HouseManager() {
+public class HouseManager extends UnicastRemoteObject implements HouseInterface {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ DB4oManager dbMngr;
+ public HouseManager() throws RemoteException {
+ super();
try {
dbMngr = DB4oManager.getInstance();
} catch (Exception e) {
package businessLogic;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;
+import common.LoginInterface;
+
import dataAccess.DB4oManager;
import domain.Account;
-public class LoginManager implements LoginManagerInterface {
+public class LoginManager extends UnicastRemoteObject implements LoginInterface {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
DB4oManager dbMngr;
- public LoginManager() {
-
+ public LoginManager() throws RemoteException {
+ super();
try {
dbMngr = DB4oManager.getInstance();
} catch (Exception e) {
+++ /dev/null
-package businessLogic;
-
-import domain.Account;
-
-public interface LoginManagerInterface {
-
- public Account checkCredentials(String usr, String pwd);
-
-
-
-
-}
package businessLogic;
import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
import java.sql.Date;
+import common.OfferInterface;
+
import dataAccess.DB4oManager;
import domain.Offer;
import domain.RuralHouse;
import exceptions.BadDates;
import exceptions.OverlappingOfferExists;
-public final class OfferManager {
+public final class OfferManager extends UnicastRemoteObject implements OfferInterface{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
private int offerNumber = 0;
dataAccess.DB4oManager dbMngr;
- public OfferManager() {
+ public OfferManager() throws RemoteException {
+ super();
try {
this.dbMngr = DB4oManager.getInstance();
} catch (Exception e) {
package businessLogic;
import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;
+import common.OwnerInterface;
+
import dataAccess.DB4oManager;
import domain.Owner;
-public class OwnerManager implements OwnerManagerInterface {
+public class OwnerManager extends UnicastRemoteObject implements OwnerInterface {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
DB4oManager dbMngr;
- public OwnerManager() {
+ public OwnerManager() throws RemoteException {
+ super();
try {
dbMngr = DB4oManager.getInstance();
} catch (Exception e) {
--- /dev/null
+package common;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import domain.Account;
+
+public interface AccountInterface extends Remote{
+
+
+ public boolean addAccount(Account ac) throws RemoteException;
+
+ public boolean removeAccount(Account ac) throws RemoteException;
+}
--- /dev/null
+package common;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.util.Vector;
+
+import domain.Account;
+import domain.RuralHouse;
+
+public interface AdminInterface extends Remote {
+
+
+ public Vector<RuralHouse> getAdditionRequests() throws RemoteException;
+
+ public Vector<RuralHouse> getDeletionRequests() throws RemoteException ;
+
+ public Vector<Account> getOwnerAdditionRequests() throws RemoteException ;
+
+ public void removeHouseAdditionRequests(RuralHouse house) throws RemoteException ;
+
+ public void removeHouseDeletionRequests(RuralHouse house) throws RemoteException ;
+
+ public void removeOwnerAdditionRequests(Account acc) throws RemoteException ;
+
+ public boolean addAdditionRequest(RuralHouse rh) throws RemoteException ;
+
+ public boolean addDeletionRequest(RuralHouse rh) throws RemoteException ;
+
+ public boolean addAccount(Account acc) throws RemoteException ;
+
+ public void saveInstance() throws RemoteException;
+
+
+}
--- /dev/null
+package common;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.util.Date;
+import java.util.Vector;
+
+import domain.Booking;
+import domain.Client;
+import domain.RuralHouse;
+import exceptions.OfferCanNotBeBooked;
+
+public interface BookingInterface extends Remote {
+
+
+ public int getNumber() throws RemoteException;
+
+
+ public void removeDenyBooking(Booking b) throws RemoteException;
+
+
+ public void acceptBooking(Booking b) throws RemoteException;
+
+ public Vector<Booking> createBooking(RuralHouse ruralHouse, Date firstDate,
+ Date lastDate, Client client)
+ throws OfferCanNotBeBooked,RemoteException ;
+
+}
\ No newline at end of file
--- /dev/null
+package common;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.util.Vector;
+
+import domain.Owner;
+import domain.RuralHouse;
+
+public interface HouseInterface extends Remote {
+
+ // For future implementation
+ // public void modifyHouse(int houseName, Owner owner,
+ // String description, String town, int nRooms, int nKitchens,
+ // int nBaths, int nLivings, int nParkings);
+
+ public void removeHouse(RuralHouse rh, Owner owner)throws RemoteException;
+
+ public Vector<RuralHouse> getHouses(String name,String town,int nBed , int nKit, int nBath, int nPark, int nLiv) throws RemoteException;
+
+ /**
+ * This method retrieves the existing rural houses
+ *
+ * @return a Set of rural houses
+ */
+ public Vector<RuralHouse> getAllRuralHouses()throws RemoteException,
+ Exception, RemoteException;
+
+ public boolean registerNewHouse(RuralHouse rh)throws RemoteException;
+
+}
--- /dev/null
+package common;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+import domain.Account;
+
+public interface LoginInterface extends Remote {
+
+ public Account checkCredentials(String usr, String pwd)throws RemoteException;
+
+
+
+
+}
--- /dev/null
+package common;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.sql.Date;
+
+import domain.Offer;
+import domain.RuralHouse;
+import exceptions.BadDates;
+import exceptions.OverlappingOfferExists;
+
+public interface OfferInterface extends Remote {
+
+ /**
+ * This method creates an offer with a house number, first day, last day and
+ * price
+ *
+ * @param House
+ * number, start day, last day and price
+ * @return the created offer, or null, or an exception
+ */
+ public Offer createOffer(RuralHouse ruralHouse, Date firstDay,
+ Date lastDay, float price) throws OverlappingOfferExists, BadDates,
+ RemoteException, Exception;
+
+ public void deleteOffer(RuralHouse rh, Offer o) throws RemoteException,
+ Exception;
+
+}
--- /dev/null
+package common;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.util.Vector;
+
+import domain.Owner;
+
+public interface OwnerInterface extends Remote {
+
+
+ public Vector<Owner> getOwners() throws RemoteException,
+ Exception;
+
+}
Account alfredoAcc = new Account("userAlfredo", "passAlfredo",
alfredo);
+
Account admin = new Account("admin", "admin", true);
db.store(Administrator.getInstance());
+
db.store(jonAcc);
db.store(alfredoAcc);
db.store(admin);
}
}
- public Administrator getAdminData() {
+
+
+ public Administrator getAdminData(){
if (c.isDatabaseLocal() == false)
openSDB();
else
try {
- List<Administrator> admL = db.query(new Predicate<Administrator>() {
- /**
- *
- */
+
+ List<Administrator> admL = db.query(new Predicate<Administrator>(){
private static final long serialVersionUID = 1L;
public boolean match(Administrator admin) {
}
});
+
+
return admL.get(0);
- } finally {
+ }
+ finally {
db.close();
}
}
public void storeAdmin() {
+
if (c.isDatabaseLocal() == false)
openSDB();
else
Administrator.getInstance().getRemoveRequest());
admL.get(0).setNewOwnerRequest(
Administrator.getInstance().getNewOwnerRequest());
+
db.commit();
} catch (Exception e) {
package domain;
+import java.io.Serializable;
import java.util.Arrays;
import businessLogic.SecurityManager;
-public class Account {
+public class Account implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
private byte[] username;
private byte[] password;
private byte[] salt;
+
private Owner owner;
private boolean admin = false;
package domain;
+import java.io.Serializable;
import java.util.LinkedList;
import configuration.ConfigXML;
import dataAccess.DB4oManager;
-public class Administrator {
+public class Administrator implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
private static Administrator admin = null;
private static LinkedList<RuralHouse> addRequest;
public void setRemoveRequest(LinkedList<RuralHouse> removeRequest) {
Administrator.removeRequest = removeRequest;
+
}
public LinkedList<Account> getNewOwnerRequest() {
import java.io.Serializable;
import java.util.Date;
-@SuppressWarnings("serial")
-public class Booking implements Serializable {
+public class Booking implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
private int bookingNumber;
private boolean isPaid;
private Date bookingDate;
package domain;
-public enum Districs {
+import java.io.Serializable;
+
+public enum Districs implements Serializable {
+
+ /**
+ *
+ */
BEA("Beatriz"), GUA("Guazate"), VEG("Vegas"), FAR("Farallón"), CED("Cedro"), MOT(
"Monte LLano"), RIN("Rincón"), PUE("Pueblo"), QUA("Quebrada Arriba"), QEB(
"Quebrada Abajo"), TOI("Toita"), MAB("Matón Abajo"), MAA(
"Matón Arriba"), PIE("Piedras"), PAV("Pasto Viejo"), PEA(
"PedroAvila"), SUM("Sumido"), LAP("Lapa"), CER("Cercadillo"), JAJ(
"JájomeAlto"), CUL("CulebrasAbajo");
+
+ private static final long serialVersionUID = 1L;
+
private final String longName;
Districs(String longName) {
package domain;
-public class HouseFeatures {
+import java.io.Serializable;
+public class HouseFeatures implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
private int nRooms;
private int nKitchens;
private int nBaths;
import java.io.Serializable;
import java.util.Vector;
-@SuppressWarnings("serial")
public class Owner implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
private String bankAccount = "";
private String name = "";
private String mailAccount = "";
--- /dev/null
+package launcher;
+
+import java.rmi.Naming;
+import java.rmi.RMISecurityManager;
+import java.rmi.Remote;
+
+import businessLogic.AdminManager;
+import businessLogic.BookingManager;
+import businessLogic.HouseManager;
+import businessLogic.LoginManager;
+import businessLogic.OfferManager;
+import businessLogic.OwnerManager;
+
+public class RMILauncher {
+
+ public static void main(String[] args) {
+ RMILauncher.startRegistry();
+ RMILauncher.initRemoteObject();
+ }
+
+ private static void startRegistry() {
+ System.setProperty("java.security.policy", "java.policy");
+ System.setSecurityManager(new RMISecurityManager());
+ try {
+ java.rmi.registry.LocateRegistry.createRegistry(9999);
+ } catch (Exception e) {
+ System.out.println(e.toString()
+ + "\nRMI registry was already created");
+ }
+
+ }
+
+ private static void initRemoteObject() {
+ boolean adm = runAdmin();
+ boolean bok = runBooking();
+ boolean hou = runHouse();
+ boolean off = runOffer();
+ boolean own = runOwner();
+ boolean log = runLogin();
+
+ System.out.println(" Admin: "+adm+
+ "\t Booking: "+bok+
+ "\t House: "+hou+
+ "\t Login: "+log+
+ "\t Offer: "+off+
+ "\t Owner: "+own);
+ }
+
+ private static boolean runAdmin() {
+ try {
+ Remote remoteObject = new AdminManager();
+ String authService = "rmi://localhost:9999//AdM";
+ Naming.rebind(authService, remoteObject);
+ return true;
+ } catch (Exception e) {
+ System.out.println(e.toString());
+ return false;
+ }
+ }
+
+
+ private static boolean runBooking() {
+ try {
+ Remote remoteBooking = new BookingManager();
+ String authService = "rmi://localhost:9999//BoM";
+ Naming.rebind(authService, remoteBooking);
+ return true;
+ } catch (Exception e) {
+ System.out.println(e.toString());
+ return false;
+ }
+ }
+
+
+ private static boolean runHouse() {
+ try {
+ Remote remoteHouse = new HouseManager();
+ String authService = "rmi://localhost:9999//HoM";
+ Naming.rebind(authService, remoteHouse);
+ return true;
+ } catch (Exception e) {
+ System.out.println(e.toString());
+ return false;
+ }
+ }
+
+
+ private static boolean runLogin() {
+ try {
+ Remote remoteLogin = new LoginManager();
+ String authService = "rmi://localhost:9999//LoM";
+ Naming.rebind(authService, remoteLogin);
+ return true;
+ } catch (Exception e) {
+ System.out.println(e.toString());
+ return false;
+ }
+ }
+
+
+ private static boolean runOffer() {
+ try {
+ Remote remoteOffer = new OfferManager();
+ String authService = "rmi://localhost:9999//OfM";
+ Naming.rebind(authService, remoteOffer);
+ return true;
+ } catch (Exception e) {
+ System.out.println(e.toString());
+ return false;
+ }
+ }
+
+
+ private static boolean runOwner() {
+ try {
+ Remote remoteOwner = new OwnerManager();
+ String authService = "rmi://localhost:9999//OwM";
+ Naming.rebind(authService, remoteOwner);
+ return true;
+ } catch (Exception e) {
+ System.out.println(e.toString());
+ return false;
+ }
+ }
+
+
+}