deleted aplicationFacade and imported it's functions to specific business logics.
authorEneko Pinzolas Murua <kelossus@localhost.localdomain>
Mon, 9 Mar 2015 13:02:33 +0000 (14:02 +0100)
committerEneko Pinzolas Murua <kelossus@localhost.localdomain>
Mon, 9 Mar 2015 13:02:33 +0000 (14:02 +0100)
18 files changed:
ruralHouses/src/businessLogic/BookingManager.java
ruralHouses/src/businessLogic/BusinessLogicServer.java [deleted file]
ruralHouses/src/businessLogic/HouseManager.java
ruralHouses/src/businessLogic/HouseManagerInterface.java
ruralHouses/src/businessLogic/OfferManager.java
ruralHouses/src/businessLogic/OwnerManager.java [new file with mode: 0644]
ruralHouses/src/businessLogic/OwnerManagerInterface.java [new file with mode: 0644]
ruralHouses/src/businessLogic/RemoteServer.java [deleted file]
ruralHouses/src/businessLogic/__ApplicationFacadeInterface.java [moved from ruralHouses/src/businessLogic/ApplicationFacadeInterface.java with 81% similarity]
ruralHouses/src/businessLogic/__FacadeImplementation.java [moved from ruralHouses/src/businessLogic/FacadeImplementation.java with 94% similarity]
ruralHouses/src/dataAccess/DB4oManager.java
ruralHouses/src/gui/BookRuralHouseGUI.java
ruralHouses/src/gui/DeleteHouseGUI.java
ruralHouses/src/gui/IntroduceOffer2GUI.java
ruralHouses/src/gui/QueryAvailabilityGUI.java
ruralHouses/src/gui/SetAvailability2GUI.java
ruralHouses/src/gui/SetAvailabilityGUI.java
ruralHouses/src/gui/StartWindow.java

index 18670e1..d4069fc 100644 (file)
@@ -1,9 +1,14 @@
 package businessLogic;
 
 package businessLogic;
 
+import java.sql.Date;
+
 import com.db4o.ObjectContainer;
 import com.db4o.ObjectSet;
 
 import dataAccess.DB4oManager;
 import com.db4o.ObjectContainer;
 import com.db4o.ObjectSet;
 
 import dataAccess.DB4oManager;
+import domain.Booking;
+import domain.RuralHouse;
+import exceptions.OfferCanNotBeBooked;
 
 
 public final class BookingManager {
 
 
 public final class BookingManager {
@@ -13,7 +18,13 @@ public final class BookingManager {
 
        private static BookingManager theBookingManager;
 
 
        private static BookingManager theBookingManager;
 
-       private BookingManager() {}
+       public BookingManager() {
+               try {
+                       this.dbMngr = DB4oManager.getInstance();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
        
        /**
         * This method returns the next Booking number 
        
        /**
         * This method returns the next Booking number 
@@ -46,4 +57,17 @@ public final class BookingManager {
                return theBookingManager;
        }
        
                return theBookingManager;
        }
        
+       /**
+        * This method creates a book with a corresponding parameters
+        * 
+        * @param First
+        *            day, last day, house number and telephone
+        * @return a book
+        */
+       public Booking createBooking(RuralHouse ruralHouse, Date firstDate, Date lastDate, String bookTelephoneNumber)
+                       throws OfferCanNotBeBooked {
+
+               return dbMngr.createBooking(ruralHouse,firstDate,lastDate,bookTelephoneNumber);
+       }
+       
 }
\ No newline at end of file
 }
\ No newline at end of file
diff --git a/ruralHouses/src/businessLogic/BusinessLogicServer.java b/ruralHouses/src/businessLogic/BusinessLogicServer.java
deleted file mode 100644 (file)
index 4050bbb..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-package businessLogic;
-
-import java.awt.BorderLayout;
-import java.awt.FlowLayout;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.rmi.Naming;
-import java.rmi.RMISecurityManager;
-import java.rmi.RemoteException;
-
-import javax.swing.JButton;
-import javax.swing.JDialog;
-import javax.swing.JPanel;
-import javax.swing.border.EmptyBorder;
-
-import configuration.ConfigXML;
-
-import javax.swing.JTextArea;
-
-import dataAccess.DB4oManager;
-
-import java.awt.event.ActionListener;
-import java.awt.event.ActionEvent;
-
-public class BusinessLogicServer extends JDialog {
-
-       private final JPanel contentPanel = new JPanel();
-       JTextArea textArea;
-       ApplicationFacadeInterface server;
-
-       /**
-        * Launch the application.
-        */
-       public static void main(String[] args) {
-               try {
-                       BusinessLogicServer dialog = new BusinessLogicServer();
-                       dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
-                       dialog.setVisible(true);
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-       }
-
-       /**
-        * Create the dialog.
-        */
-       public BusinessLogicServer() {
-               setTitle("BusinessLogicServer: running the business logic");
-               setBounds(100, 100, 486, 209);
-               getContentPane().setLayout(new BorderLayout());
-               contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
-               getContentPane().add(contentPanel, BorderLayout.CENTER);
-               contentPanel.setLayout(new BorderLayout(0, 0));
-               {
-                       textArea = new JTextArea();
-                       contentPanel.add(textArea);
-               }
-               {
-                       JPanel buttonPane = new JPanel();
-                       buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
-                       getContentPane().add(buttonPane, BorderLayout.SOUTH);
-                       {
-                               JButton okButton = new JButton("OK");
-                               okButton.addActionListener(new ActionListener() {
-                                       public void actionPerformed(ActionEvent e) {
-                                               textArea.append("\n\n\nClosing the server... ");
-                                           try {
-                                                       server.close();
-                                               } catch (RemoteException e1) {
-                                               }
-                                               System.exit(1);
-                                       }
-                               });
-                               okButton.setActionCommand("OK");
-                               buttonPane.add(okButton);
-                               getRootPane().setDefaultButton(okButton);
-                       }
-                       {
-                               JButton cancelButton = new JButton("Cancel");
-                               cancelButton.setActionCommand("Cancel");
-                               buttonPane.add(cancelButton);
-                       }
-               }
-               
-               ConfigXML c=ConfigXML.getInstance();
-
-                
-               System.setProperty("java.security.policy", c.getJavaPolicyPath());
-               
-               
-               System.setSecurityManager(new RMISecurityManager());
-               
-               try {
-                       java.rmi.registry.LocateRegistry.createRegistry(Integer.parseInt(c.getPortRMI()));
-                       // Create RMIREGISTRY
-               } catch (Exception e) {
-                       textArea.append(e.toString() + "Rmiregistry already running.");
-               }
-
-               try {
-
-                       try{
-                               server = new FacadeImplementation();
-                       }
-                       catch (com.db4o.ext.DatabaseFileLockedException e) {
-                               System.out.println("Error in BusinessLogicServer: "+e.toString());
-                               textArea.append("\nYou should have not launched DB4oManagerServer...\n");
-                               textArea.append("\n\nOr maybe there is a BusinessLogicServer already launched...\n");
-                               throw e;
-                       }
-                       
-
-                       String service= "//"+c.getBusinessLogicNode() +":"+ c.getPortRMI()+"/"+c.getServiceRMI();
-                       
-                       // Register the remote server
-                       Naming.rebind(service, server);
-                       textArea.append("Running service at:\n\t" + service);
-                       //This operation removes the actual database and initialize with predefined values
-                       
-                       textArea.append("\n\n\nPress button to exit this server... ");
-                       
-               } catch (Exception e) {
-                       textArea.append(e.toString());
-               }
-
-       }
-               
-}
-
index 1463ad5..e50f4bb 100644 (file)
@@ -55,6 +55,15 @@ public class HouseManager implements HouseManagerInterface {
                return this.dbMngr.getRuralHousesByTown(town);
        }
 
                return this.dbMngr.getRuralHousesByTown(town);
        }
 
+
+
+       @Override
+       public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
+                       Exception {
+               // TODO Auto-generated method stub
+               return dbMngr.getAllRuralHouses();
+       }
+
        // For future implementation
        // @Override
        // public void modifyHouse(int houseNumber, Owner owner, String description,
        // For future implementation
        // @Override
        // public void modifyHouse(int houseNumber, Owner owner, String description,
index ca99f40..fd5462f 100644 (file)
@@ -25,4 +25,13 @@ public interface HouseManagerInterface {
 
 
        public Vector<RuralHouse> getHousesByTown(String town);
 
 
        public Vector<RuralHouse> getHousesByTown(String town);
+       
+       /**
+        * This method retrieves the existing  rural houses 
+        * 
+        * @return a Set of rural houses
+        */
+       public Vector<RuralHouse> getAllRuralHouses()throws RemoteException,
+       Exception;
+       
 }
 }
index 3c00ca5..ea782a0 100644 (file)
@@ -1,9 +1,18 @@
 package businessLogic;
 
 package businessLogic;
 
+import java.rmi.RemoteException;
+import java.sql.Date;
+
 import com.db4o.ObjectContainer;
 import com.db4o.ObjectSet;
 
 import dataAccess.DB4oManager;
 import com.db4o.ObjectContainer;
 import com.db4o.ObjectSet;
 
 import dataAccess.DB4oManager;
+import domain.Booking;
+import domain.Offer;
+import domain.RuralHouse;
+import exceptions.BadDates;
+import exceptions.OfferCanNotBeBooked;
+import exceptions.OverlappingOfferExists;
 
 public final class OfferManager {
 
 
 public final class OfferManager {
 
@@ -11,7 +20,13 @@ public final class OfferManager {
        dataAccess.DB4oManager dbMngr;
        private static OfferManager theOfferManager;
 
        dataAccess.DB4oManager dbMngr;
        private static OfferManager theOfferManager;
 
-       private OfferManager() {}
+       public OfferManager() {
+               try {
+                       this.dbMngr = DB4oManager.getInstance();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
 
        public static int getNumber() {
                ObjectContainer db=DB4oManager.getContainer();
 
        public static int getNumber() {
                ObjectContainer db=DB4oManager.getContainer();
@@ -38,4 +53,22 @@ public final class OfferManager {
                } else theOfferManager=(OfferManager)result.next();
                return theOfferManager;
        }
                } else theOfferManager=(OfferManager)result.next();
                return theOfferManager;
        }
+       
+       /**
+        * 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 {
+               if (firstDay.compareTo(lastDay)>=0) throw new BadDates();
+
+               boolean b = dbMngr.existsOverlappingOffer(ruralHouse,firstDay,lastDay); // The ruralHouse object in the client may not be updated
+               if (!b) return dbMngr.createOffer(ruralHouse,firstDay,lastDay,price);                   
+               return null;
+       }
+
+       
 }
 }
diff --git a/ruralHouses/src/businessLogic/OwnerManager.java b/ruralHouses/src/businessLogic/OwnerManager.java
new file mode 100644 (file)
index 0000000..e48679b
--- /dev/null
@@ -0,0 +1,38 @@
+package businessLogic;
+
+import java.rmi.RemoteException;
+import java.util.Date;
+import java.util.Vector;
+
+import dataAccess.DB4oManager;
+import domain.Account;
+import domain.HouseFeatures;
+import domain.Offer;
+import domain.Owner;
+import domain.RuralHouse;
+
+public class OwnerManager implements OwnerManagerInterface {
+       DB4oManager dbMngr;
+
+       public OwnerManager() {
+               try {
+                       dbMngr = DB4oManager.getInstance();
+               } catch (Exception e) {
+
+                       e.printStackTrace();
+               }
+       }
+
+       /**
+        * This method existing  owners 
+        * 
+        */
+       public Vector<Owner> getOwners() throws RemoteException,
+                       Exception {
+               
+               
+               return dbMngr.getOwners();
+       }
+
+       
+}
diff --git a/ruralHouses/src/businessLogic/OwnerManagerInterface.java b/ruralHouses/src/businessLogic/OwnerManagerInterface.java
new file mode 100644 (file)
index 0000000..ab45739
--- /dev/null
@@ -0,0 +1,17 @@
+package businessLogic;
+
+import java.rmi.RemoteException;
+import java.util.Date;
+import java.util.Vector;
+
+import domain.Offer;
+import domain.Owner;
+import domain.RuralHouse;
+
+public interface OwnerManagerInterface {
+
+
+       public Vector<Owner> getOwners() throws RemoteException,
+       Exception;
+       
+}
diff --git a/ruralHouses/src/businessLogic/RemoteServer.java b/ruralHouses/src/businessLogic/RemoteServer.java
deleted file mode 100644 (file)
index 3e1f473..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-package businessLogic;
-
-import java.rmi.Naming;
-import java.rmi.RMISecurityManager;
-
-import configuration.Config;
-import dataAccess.DB4oManager;
-
-public class RemoteServer {
-
-       public static void main(String[] args) {
-               Config c=Config.getInstance();
-
-               System.setProperty("java.security.policy", c.getJavaPolicyPath());
-
-               //System.setSecurityManager(new RMISecurityManager());
-
-               try {
-                       java.rmi.registry.LocateRegistry.createRegistry(Integer.parseInt(c.getPortRMI()));
-                       // Create RMIREGISTRY
-               } catch (Exception e) {
-                       System.out.println(e.toString() + "RMIregistry already running.");
-               }
-
-               try {
-                       System.setProperty("java.security.policy", c.getJavaPolicyPath());
-
-                       ApplicationFacadeInterface server = new FacadeImplementation();
-
-                       String service= "//"+c.getServerRMI() +":"+ c.getPortRMI()+"/"+c.getServiceRMI();
-
-                       //Register the remote server
-                       Naming.rebind(service, server);
-                       System.out.println("Running service at:\n\t" + service);
-                       //This operation removes the actual database and initializes it with some predefined values
-
-               } catch (Exception e) {
-                       System.out.println(e.toString());
-               }
-       }
-       
-}
@@ -13,7 +13,7 @@ import domain.RuralHouse;
 import exceptions.OfferCanNotBeBooked; 
 
 
 import exceptions.OfferCanNotBeBooked; 
 
 
-public interface ApplicationFacadeInterface extends Remote {
+public interface __ApplicationFacadeInterface extends Remote {
        
 
        /**
        
 
        /**
@@ -48,13 +48,7 @@ public interface ApplicationFacadeInterface extends Remote {
        public Vector<Owner> getOwners() throws RemoteException,
                        Exception;
        
        public Vector<Owner> getOwners() throws RemoteException,
                        Exception;
        
-       /**
-        * This method retrieves the existing  rural houses 
-        * 
-        * @return a Set of rural houses
-        */
-       public Vector<RuralHouse> getAllRuralHouses()throws RemoteException,
-       Exception;
+       
        
        public void close() throws RemoteException;
 
        
        public void close() throws RemoteException;
 
@@ -21,7 +21,7 @@ import exceptions.OfferCanNotBeBooked;
 import exceptions.OverlappingOfferExists;
 
 
 import exceptions.OverlappingOfferExists;
 
 
-public class FacadeImplementation extends UnicastRemoteObject implements ApplicationFacadeInterface {
+public class __FacadeImplementation extends UnicastRemoteObject implements __ApplicationFacadeInterface {
 
        /**
         * 
 
        /**
         * 
@@ -33,7 +33,7 @@ public class FacadeImplementation extends UnicastRemoteObject implements Applica
        DB4oManager dB4oManager;
  
 
        DB4oManager dB4oManager;
  
 
-       public FacadeImplementation() throws RemoteException, InstantiationException,
+       public __FacadeImplementation() throws RemoteException, InstantiationException,
                        IllegalAccessException, ClassNotFoundException, SQLException, DB4oManagerCreationException {
                owners=null;
                ruralHouses=null;
                        IllegalAccessException, ClassNotFoundException, SQLException, DB4oManagerCreationException {
                owners=null;
                ruralHouses=null;
index 80bc080..15b2ad4 100644 (file)
@@ -50,14 +50,12 @@ public class DB4oManager {
                        new File(c.getDb4oFilename()).delete();
 
                if (c.isDatabaseLocal()) {
                        new File(c.getDb4oFilename()).delete();
 
                if (c.isDatabaseLocal()) {
-                       configuration = Db4oEmbedded.newConfiguration();
-                       configuration.common().activationDepth(c.getActivationDepth());
-                       configuration.common().updateDepth(c.getUpdateDepth());
-                       db = Db4oEmbedded.openFile(configuration, c.getDb4oFilename());
+                       openDB();
                        System.out.println("DataBase opened");
                } else // c.isDatabaseLocal==false
                {
                        System.out.println("DataBase opened");
                } else // c.isDatabaseLocal==false
                {
-                       openObjectContainer();
+                       openSDB();
+                       System.out.println("Remote DataBase opened");
                }
                if (c.getDataBaseOpenMode().equals("initialize")) {
                        initializeDB();
                }
                if (c.getDataBaseOpenMode().equals("initialize")) {
                        initializeDB();
@@ -76,10 +74,11 @@ public class DB4oManager {
                configuration = Db4oEmbedded.newConfiguration();
                configuration.common().activationDepth(c.getActivationDepth());
                configuration.common().updateDepth(c.getUpdateDepth());
                configuration = Db4oEmbedded.newConfiguration();
                configuration.common().activationDepth(c.getActivationDepth());
                configuration.common().updateDepth(c.getUpdateDepth());
+               configuration.common().objectClass(Owner.class).cascadeOnDelete(true);
                db = Db4oEmbedded.openFile(configuration, c.getDb4oFilename());
        }
 
                db = Db4oEmbedded.openFile(configuration, c.getDb4oFilename());
        }
 
-       private void openObjectContainer() {
+       private void openSDB() {
 
                configurationCS = Db4oClientServer.newClientConfiguration();
                configurationCS.common().activationDepth(c.getActivationDepth());
 
                configurationCS = Db4oClientServer.newClientConfiguration();
                configurationCS.common().activationDepth(c.getActivationDepth());
@@ -127,7 +126,7 @@ public class DB4oManager {
                        db.store(alfredoAcc);
                        db.commit();
                } finally {
                        db.store(alfredoAcc);
                        db.commit();
                } finally {
-                       // db.close();
+                       db.close();
                }
        }
 
                }
        }
 
@@ -135,10 +134,15 @@ public class DB4oManager {
        public Offer createOffer(RuralHouse ruralHouse, Date firstDay,
                        Date lastDay, float price) throws RemoteException, Exception {
                Offer o = null;
        public Offer createOffer(RuralHouse ruralHouse, Date firstDay,
                        Date lastDay, float price) throws RemoteException, Exception {
                Offer o = null;
+               
+               if (c.isDatabaseLocal() == false)
+                       openSDB();
+               else
+                       openDB();
+               
                try {
 
                try {
 
-                       if (c.isDatabaseLocal() == false)
-                               openObjectContainer();
+                       
 
                        RuralHouse proto = new RuralHouse(ruralHouse.getHouseNumber(),
                                        null, null, null, null);
 
                        RuralHouse proto = new RuralHouse(ruralHouse.getHouseNumber(),
                                        null, null, null, null);
@@ -161,6 +165,11 @@ public class DB4oManager {
 
        public void deleteDB() {
 
 
        public void deleteDB() {
 
+               if (c.isDatabaseLocal() == false)
+                       openSDB();
+               else
+                       openDB();
+               
                try {
                        Owner proto = new Owner(null, null);
                        ObjectSet result = db.queryByExample(proto);
                try {
                        Owner proto = new Owner(null, null);
                        ObjectSet result = db.queryByExample(proto);
@@ -172,7 +181,7 @@ public class DB4oManager {
                        }
                        db.commit();
                } finally {
                        }
                        db.commit();
                } finally {
-                       // db.close();
+                       db.close();
                }
        }
 
                }
        }
 
@@ -186,11 +195,18 @@ public class DB4oManager {
        public Booking createBooking(RuralHouse ruralHouse, Date firstDate,
                        Date lastDate, String bookTelephoneNumber)
                        throws OfferCanNotBeBooked {
        public Booking createBooking(RuralHouse ruralHouse, Date firstDate,
                        Date lastDate, String bookTelephoneNumber)
                        throws OfferCanNotBeBooked {
-
+               
+               if (c.isDatabaseLocal() == false)
+                       openSDB();
+               else
+                       openDB();
+               
+               Booking bok = null;
+               
                try {
 
                        if (c.isDatabaseLocal() == false)
                try {
 
                        if (c.isDatabaseLocal() == false)
-                               openObjectContainer();
+                               openSDB();
 
                        RuralHouse proto = new RuralHouse(ruralHouse.getHouseNumber(),
                                        null, ruralHouse.getDescription(), ruralHouse.getTown(),
 
                        RuralHouse proto = new RuralHouse(ruralHouse.getHouseNumber(),
                                        null, ruralHouse.getDescription(), ruralHouse.getTown(),
@@ -208,18 +224,17 @@ public class DB4oManager {
                                                                                                // bookingNumber
                                db.store(offer);
                                db.commit();
                                                                                                // bookingNumber
                                db.store(offer);
                                db.commit();
-                               return offer.getBooking();
+                               bok = offer.getBooking();
                        }
                        }
-                       return null;
 
                } catch (com.db4o.ext.ObjectNotStorableException e) {
                        System.out
                                        .println("Error: com.db4o.ext.ObjectNotStorableException in createBooking");
 
                } catch (com.db4o.ext.ObjectNotStorableException e) {
                        System.out
                                        .println("Error: com.db4o.ext.ObjectNotStorableException in createBooking");
-                       return null;
                } catch (Exception exc) {
                        exc.printStackTrace();
                } catch (Exception exc) {
                        exc.printStackTrace();
-                       return null;
                }
                }
+               
+               return bok;
        }
 
        /**
        }
 
        /**
@@ -229,7 +244,9 @@ public class DB4oManager {
        public Vector<Owner> getOwners() throws RemoteException, Exception {
 
                if (c.isDatabaseLocal() == false)
        public Vector<Owner> getOwners() throws RemoteException, Exception {
 
                if (c.isDatabaseLocal() == false)
-                       openObjectContainer();
+                       openSDB();
+               else
+                       openDB();
 
                try {
                        Owner proto = new Owner(null, null);
 
                try {
                        Owner proto = new Owner(null, null);
@@ -239,14 +256,17 @@ public class DB4oManager {
                                owners.add((Owner) result.next());
                        return owners;
                } finally {
                                owners.add((Owner) result.next());
                        return owners;
                } finally {
-                       // db.close();
+                       db.close();
                }
        }
 
        public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
                        Exception {
                }
        }
 
        public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
                        Exception {
+               
                if (c.isDatabaseLocal() == false)
                if (c.isDatabaseLocal() == false)
-                       openObjectContainer();
+                       openSDB();
+               else
+                       openDB();
 
                try {
                        RuralHouse proto = new RuralHouse(0, null, null, null, null);
 
                try {
                        RuralHouse proto = new RuralHouse(0, null, null, null, null);
@@ -256,15 +276,20 @@ public class DB4oManager {
                                ruralHouses.add((RuralHouse) result.next());
                        return ruralHouses;
                } finally {
                                ruralHouses.add((RuralHouse) result.next());
                        return ruralHouses;
                } finally {
-                       // db.close();
+                       db.close();
                }
        }
 
        public boolean existsOverlappingOffer(RuralHouse rh, Date firstDay,
                        Date lastDay) throws RemoteException, OverlappingOfferExists {
                }
        }
 
        public boolean existsOverlappingOffer(RuralHouse rh, Date firstDay,
                        Date lastDay) throws RemoteException, OverlappingOfferExists {
+               
+               if (c.isDatabaseLocal() == false)
+                       openSDB();
+               else
+                       openDB();
+               
                try {
                try {
-                       if (c.isDatabaseLocal() == false)
-                               openObjectContainer();
+                       
 
                        RuralHouse rhn = (RuralHouse) db
                                        .queryByExample(
 
                        RuralHouse rhn = (RuralHouse) db
                                        .queryByExample(
@@ -275,7 +300,7 @@ public class DB4oManager {
                        else
                                return false;
                } finally {
                        else
                                return false;
                } finally {
-                       // db.close();
+                       db.close();
                }
        }
 
                }
        }
 
@@ -301,8 +326,12 @@ public class DB4oManager {
         */
        public Vector<Account> getAccount(String usr, String pwd)
                        throws RemoteException, Exception {
         */
        public Vector<Account> getAccount(String usr, String pwd)
                        throws RemoteException, Exception {
+               
                if (c.isDatabaseLocal() == false)
                if (c.isDatabaseLocal() == false)
-                       openObjectContainer();
+                       openSDB();
+               else
+                       openDB();
+               
                try {
                        Account proto = new Account(usr, pwd, new Owner(null, null));
                        ObjectSet<Account> result = db.queryByExample(proto);
                try {
                        Account proto = new Account(usr, pwd, new Owner(null, null));
                        ObjectSet<Account> result = db.queryByExample(proto);
@@ -311,7 +340,7 @@ public class DB4oManager {
                                accounts.add((Account) result.next());
                        return accounts;
                } finally {
                                accounts.add((Account) result.next());
                        return accounts;
                } finally {
-                       // db.close();
+                       db.close();
                }
        }
 
                }
        }
 
@@ -319,9 +348,12 @@ public class DB4oManager {
         * @param rh
         */
        public boolean storeRuralHouses(RuralHouse rh) {
         * @param rh
         */
        public boolean storeRuralHouses(RuralHouse rh) {
-//             DB4oManager.openDB();
+
                if (c.isDatabaseLocal() == false)
                if (c.isDatabaseLocal() == false)
-                       openObjectContainer();
+                       openSDB();
+               else
+                       openDB();
+               
                boolean stored = false;
                RuralHouse house = new RuralHouse(rh.getHouseNumber(), null, null,
                                null, null);
                boolean stored = false;
                RuralHouse house = new RuralHouse(rh.getHouseNumber(), null, null,
                                null, null);
@@ -333,15 +365,18 @@ public class DB4oManager {
                                stored = true;
                        }
                } finally {
                                stored = true;
                        }
                } finally {
-//                     db.close();
+                       db.close();
                }
                return stored;
        }
 
        public void removeHouse(int houseNumber) {
                }
                return stored;
        }
 
        public void removeHouse(int houseNumber) {
-//             DB4oManager.openDB();
+
                if (c.isDatabaseLocal() == false)
                if (c.isDatabaseLocal() == false)
-                       openObjectContainer();
+                       openSDB();
+               else
+                       openDB();
+               
                RuralHouse house = new RuralHouse(houseNumber, null, null, null, null);
                try {
                        ObjectSet<RuralHouse> result = db.queryByExample(house);
                RuralHouse house = new RuralHouse(houseNumber, null, null, null, null);
                try {
                        ObjectSet<RuralHouse> result = db.queryByExample(house);
@@ -353,15 +388,19 @@ public class DB4oManager {
                } catch (Exception exc) {
                        exc.printStackTrace();
                } finally {
                } catch (Exception exc) {
                        exc.printStackTrace();
                } finally {
-//                     db.close();
+                       db.close();
                }
 
        }
        
        public Vector<RuralHouse> getRuralHousesByTown(String town){
                RuralHouse rh = new RuralHouse(0,null,null,town,null);
                }
 
        }
        
        public Vector<RuralHouse> getRuralHousesByTown(String town){
                RuralHouse rh = new RuralHouse(0,null,null,town,null);
+               
                if (c.isDatabaseLocal() == false)
                if (c.isDatabaseLocal() == false)
-                       openObjectContainer();
+                       openSDB();
+               else
+                       openDB();
+               
                try{
                        ObjectSet<RuralHouse> result = db.queryByExample(rh);
                        Vector<RuralHouse> ruralHouses = new Vector<RuralHouse>();
                try{
                        ObjectSet<RuralHouse> result = db.queryByExample(rh);
                        Vector<RuralHouse> ruralHouses = new Vector<RuralHouse>();
@@ -369,7 +408,7 @@ public class DB4oManager {
                                ruralHouses.add(result.next());
                        return ruralHouses;
                }finally{
                                ruralHouses.add(result.next());
                        return ruralHouses;
                }finally{
-                       //db.close();
+                       db.close();
                }
                
        }
                }
                
        }
index 705b351..8e6d7b5 100644 (file)
@@ -1,6 +1,7 @@
 package gui;
 
 package gui;
 
-import businessLogic.ApplicationFacadeInterface;
+import businessLogic.BookingManager;
+import businessLogic.HouseManager;
 
 import com.toedter.calendar.*;
 
 
 import com.toedter.calendar.*;
 
@@ -94,8 +95,8 @@ public BookRuralHouseGUI()
     this.setSize(new Dimension(410, 413));
     this.setTitle("Book Rural House");
     jLabel1.setText("Rural house:");
     this.setSize(new Dimension(410, 413));
     this.setTitle("Book Rural House");
     jLabel1.setText("Rural house:");
-    ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
-       ruralHouses=facade.getAllRuralHouses();
+    HouseManager houseM = new HouseManager();
+       ruralHouses=houseM.getAllRuralHouses();
 
        jComboBox1 = new JComboBox(ruralHouses);
 
 
        jComboBox1 = new JComboBox(ruralHouses);
 
@@ -159,9 +160,9 @@ public BookRuralHouseGUI()
                try {
                                
                        //Obtain the business logic from a StartWindow class (local or remote)
                try {
                                
                        //Obtain the business logic from a StartWindow class (local or remote)
-                       ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
+                       BookingManager bookingM = new BookingManager();
                                                
                                                
-                       Booking book=facade.createBooking(house, firstDay, lastDay, telephone);
+                       Booking book=bookingM.createBooking(house, firstDay, lastDay, telephone);
                                if (book!=null) {
                                BookRuralHouseConfirmationWindow confirmWindow=new BookRuralHouseConfirmationWindow(book);
                                confirmWindow.setVisible(true);
                                if (book!=null) {
                                BookRuralHouseConfirmationWindow confirmWindow=new BookRuralHouseConfirmationWindow(book);
                                confirmWindow.setVisible(true);
index ce2b10b..b369391 100644 (file)
@@ -14,7 +14,6 @@ import javax.swing.JComboBox;
 import javax.swing.JRadioButton;
 import javax.swing.JButton;
 
 import javax.swing.JRadioButton;
 import javax.swing.JButton;
 
-import businessLogic.FacadeImplementation;
 import businessLogic.HouseManager;
 import businessLogic.HouseManagerInterface;
 import domain.Owner;
 import businessLogic.HouseManager;
 import businessLogic.HouseManagerInterface;
 import domain.Owner;
index 276dcfa..db1e2fe 100644 (file)
@@ -10,7 +10,8 @@ import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
 
 import java.awt.*;
 import java.awt.event.*;
 
-import businessLogic.ApplicationFacadeInterface;
+
+import businessLogic.OfferManager;
 
 import com.toedter.calendar.JCalendar;
 
 
 import com.toedter.calendar.JCalendar;
 
@@ -153,9 +154,9 @@ public class IntroduceOffer2GUI extends JFrame  {
                float price= Float.parseFloat(jTextField3.getText());
                try {
                        //Obtain the business logic from a StartWindow class (local or remote)
                float price= Float.parseFloat(jTextField3.getText());
                try {
                        //Obtain the business logic from a StartWindow class (local or remote)
-                       ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
+                       OfferManager offerM = new OfferManager();
 
 
-                       facade.createOffer(ruralHouse, firstDay, lastDay, price); 
+                       offerM.createOffer(ruralHouse, firstDay, lastDay, price); 
 
                        this.setVisible(false);
                }
 
                        this.setVisible(false);
                }
index cfad48a..287300b 100644 (file)
@@ -1,10 +1,9 @@
 package gui;
 
 package gui;
 
-import businessLogic.ApplicationFacadeInterface;
+import businessLogic.HouseManager;
 
 import com.toedter.calendar.JCalendar;
 
 
 import com.toedter.calendar.JCalendar;
 
-import configuration.ConfigXML;
 import domain.Offer;
 import domain.RuralHouse;
 
 import domain.Offer;
 import domain.RuralHouse;
 
@@ -48,8 +47,7 @@ private static final long serialVersionUID = 1L;
        };
 
 
        };
 
 
-  private static configuration.ConfigXML c;
-       
+                                                                                                                                                                       
   public QueryAvailabilityGUI()
   {
        
   public QueryAvailabilityGUI()
   {
        
@@ -66,9 +64,9 @@ private static final long serialVersionUID = 1L;
 
   private void jbInit() throws Exception
   {
 
   private void jbInit() throws Exception
   {
-       ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
+       HouseManager houseM = new HouseManager();
                
                
-       Vector<RuralHouse> rhs=facade.getAllRuralHouses();
+       Vector<RuralHouse> rhs=houseM.getAllRuralHouses();
        
        comboBox = new JComboBox(rhs);
        //comboBox.setModel(new DefaultComboBoxModel(rhs));
        
        comboBox = new JComboBox(rhs);
        //comboBox.setModel(new DefaultComboBoxModel(rhs));
@@ -130,7 +128,7 @@ private static final long serialVersionUID = 1L;
        @Override
        public void mouseClicked(MouseEvent e) {
                int i=table.getSelectedRow();
        @Override
        public void mouseClicked(MouseEvent e) {
                int i=table.getSelectedRow();
-               int houseNumber = (int) tableModel.getValueAt(i,1);
+               int houseNumber = (Integer) tableModel.getValueAt(i,1);
                        Date firstDate=new Date(((java.util.Date)tableModel.getValueAt(i,2)).getTime());
                        Date lastDate=new Date(((java.util.Date)tableModel.getValueAt(i,3)).getTime());
        
                        Date firstDate=new Date(((java.util.Date)tableModel.getValueAt(i,2)).getTime());
                        Date lastDate=new Date(((java.util.Date)tableModel.getValueAt(i,3)).getTime());
        
@@ -219,7 +217,6 @@ private static final long serialVersionUID = 1L;
        
        try {
                
        
        try {
                
-               ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
 
                Vector<Offer> v=rh.getOffers(firstDay, lastDay);
   
 
                Vector<Offer> v=rh.getOffers(firstDay, lastDay);
   
@@ -234,7 +231,7 @@ private static final long serialVersionUID = 1L;
                                while (en.hasMoreElements()) {
                                        of=en.nextElement();
                                        System.out.println("Offer retrieved: "+of.toString());
                                while (en.hasMoreElements()) {
                                        of=en.nextElement();
                                        System.out.println("Offer retrieved: "+of.toString());
-                                       Vector row = new Vector();
+                                       Vector<Object> row = new Vector<Object>();
                                        row.add(of.getOfferNumber());
                                        row.add(of.getRuralHouse().getHouseNumber());
 
                                        row.add(of.getOfferNumber());
                                        row.add(of.getRuralHouse().getHouseNumber());
 
index 86a1d29..9b40bbb 100644 (file)
@@ -9,7 +9,8 @@ import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
 
 import java.awt.*;
 import java.awt.event.*;
 
-import businessLogic.ApplicationFacadeInterface;
+
+import businessLogic.OfferManager;
 
 import com.toedter.calendar.JCalendar;
 
 
 import com.toedter.calendar.JCalendar;
 
@@ -22,6 +23,7 @@ import exceptions.BadDates;
 
 public class SetAvailability2GUI extends JFrame  {
 private static final long serialVersionUID = 1L;
 
 public class SetAvailability2GUI extends JFrame  {
 private static final long serialVersionUID = 1L;
+
        
   private JComboBox jComboBox1;
   private JLabel jLabel1 = new JLabel();
        
   private JComboBox jComboBox1;
   private JLabel jLabel1 = new JLabel();
@@ -195,14 +197,12 @@ private static final long serialVersionUID = 1L;
                        float price= Float.parseFloat(jTextField3.getText());
 
                        //Obtain the business logic from a StartWindow class (local or remote)
                        float price= Float.parseFloat(jTextField3.getText());
 
                        //Obtain the business logic from a StartWindow class (local or remote)
-                       ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
+                       OfferManager offerM = new OfferManager();
 
 
-                       Offer o = facade.createOffer(ruralHouse, firstDay, lastDay, price); 
+                       Offer o = offerM.createOffer(ruralHouse, firstDay, lastDay, price); 
                        System.out.println("Offer created: "+o.toString());
 
                        System.out.println("Offer created: "+o.toString());
 
-                       if (o==null)
-                               jLabel5.setText("Bad dates or there exists an overlapping offer");
-                       else jLabel5.setText("Offer created");
+                       jLabel5.setText("Offer created");
 
                } catch (java.lang.NumberFormatException e1) {
                        jLabel5.setText(jTextField3.getText()+ " is not a valid price");
 
                } catch (java.lang.NumberFormatException e1) {
                        jLabel5.setText(jTextField3.getText()+ " is not a valid price");
@@ -211,10 +211,12 @@ private static final long serialVersionUID = 1L;
                }
                catch (BadDates e1) {
                        jLabel5.setText("Last day is before first day in the offer");
                }
                catch (BadDates e1) {
                        jLabel5.setText("Last day is before first day in the offer");
+               } catch (NullPointerException e1){
+                       jLabel5.setText("Bad dates or there exists an overlapping offer");
                } catch (Exception e1) {
                } catch (Exception e1) {
-
+               
                        e1.printStackTrace();
                        e1.printStackTrace();
-               }
+               } 
   }
   private void jButton2_actionPerformed(ActionEvent e)
   {
   }
   private void jButton2_actionPerformed(ActionEvent e)
   {
index 92e44d9..b4d8ee1 100644 (file)
@@ -11,7 +11,8 @@ import java.util.Vector;
 
 import javax.swing.JButton;
 
 
 import javax.swing.JButton;
 
-import businessLogic.ApplicationFacadeInterface;
+import businessLogic.OwnerManager;
+import businessLogic.OwnerManagerInterface;
 import domain.Owner;
 import domain.RuralHouse;
 import javax.swing.JLabel;
 import domain.Owner;
 import domain.RuralHouse;
 import javax.swing.JLabel;
@@ -73,12 +74,11 @@ public class SetAvailabilityGUI extends JFrame {
                
                if (jComboBox == null) {
                        try {
                
                if (jComboBox == null) {
                        try {
-                       ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
-                               Vector<Owner> owners=facade.getOwners();
+                       OwnerManagerInterface ownerM = new OwnerManager();
+                               Vector<Owner> owners=ownerM.getOwners();
                        jComboBox = new JComboBox(owners);
                        jComboBox.setBounds(new Rectangle(136, 39, 175, 44));
                        } catch (Exception e) {
                        jComboBox = new JComboBox(owners);
                        jComboBox.setBounds(new Rectangle(136, 39, 175, 44));
                        } catch (Exception e) {
-                               // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                        
                                e.printStackTrace();
                        }
                        
index 3e538ca..ee3ab51 100644 (file)
@@ -9,10 +9,6 @@ import gui.BookRuralHouseGUI;
 import javax.swing.*;
 
 import configuration.ConfigXML;
 import javax.swing.*;
 
 import configuration.ConfigXML;
-//import businessLogic.FacadeImplementation;
-import businessLogic.ApplicationFacadeInterface;
-import businessLogic.FacadeImplementation;
-
 import java.rmi.*;
 import java.awt.Color;
 import java.awt.Font;
 import java.rmi.*;
 import java.awt.Color;
 import java.awt.Font;
@@ -37,7 +33,7 @@ public class StartWindow extends JFrame {
        private JButton boton3 = null;
        private static configuration.ConfigXML c;
 
        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) {
        private JLabel lblNewLabel;
        
        public static void main(String[] args) {
@@ -56,8 +52,9 @@ public class StartWindow extends JFrame {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
 
                        c=configuration.ConfigXML.getInstance();
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
 
                        c=configuration.ConfigXML.getInstance();
-                       if (c.isBusinessLogicLocal())
-                               facadeInterface=new FacadeImplementation();
+                       if (c.isBusinessLogicLocal()){
+                               //facadeInterface=new FacadeImplementation();
+                       }
                        else {
                                
                                final String businessLogicNode = c.getBusinessLogicNode();
                        else {
                                
                                final String businessLogicNode = c.getBusinessLogicNode();
@@ -66,11 +63,11 @@ public class StartWindow extends JFrame {
                                // RMI server port number
                                int portNumber = Integer.parseInt(c.getPortRMI());
                                // RMI server host IP IP 
                                // RMI server port number
                                int portNumber = Integer.parseInt(c.getPortRMI());
                                // RMI server host IP IP 
-                               facadeInterface = (ApplicationFacadeInterface) Naming.lookup("rmi://"
-                                       + businessLogicNode + ":" + portNumber + serviceName);
+                               /*facadeInterface = (ApplicationFacadeInterface) Naming.lookup("rmi://"
+                                       + businessLogicNode + ":" + portNumber + serviceName);*/
                        } 
 
                        } 
 
-               } catch (java.rmi.ConnectException e) {
+               }/* catch (java.rmi.ConnectException e) {
                        a.lblNewLabel.setText("No business logic: Run BusinessLogicServer first!!");
                        a.lblNewLabel.setForeground(Color.RED);
                        System.out.println("Error in StartWindow: "+e.toString());
                        a.lblNewLabel.setText("No business logic: Run BusinessLogicServer first!!");
                        a.lblNewLabel.setForeground(Color.RED);
                        System.out.println("Error in StartWindow: "+e.toString());
@@ -78,7 +75,7 @@ public class StartWindow extends JFrame {
                        a.lblNewLabel.setText("No business logic: Maybe problems running BusinessLogicServer");
                        a.lblNewLabel.setForeground(Color.RED);
                        System.out.println("Error in StartWindow: "+e.toString());
                        a.lblNewLabel.setText("No business logic: Maybe problems running BusinessLogicServer");
                        a.lblNewLabel.setForeground(Color.RED);
                        System.out.println("Error in StartWindow: "+e.toString());
-               } catch (com.db4o.ext.DatabaseFileLockedException e) {
+               } */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());
                        a.lblNewLabel.setText("Database locked: Do not run BusinessLogicServer or BusinessLogicServer!!");
                        a.lblNewLabel.setForeground(Color.RED);         
                        System.out.println("Error in StartWindow: "+e.toString());
@@ -102,22 +99,13 @@ public class StartWindow extends JFrame {
                addWindowListener(new WindowAdapter() {
                        @Override
                        public void windowClosing(WindowEvent e) {
                addWindowListener(new WindowAdapter() {
                        @Override
                        public void windowClosing(WindowEvent e) {
-                               ApplicationFacadeInterface facade=StartWindow.facadeInterface;
-                               try {
-                                       if (c.isBusinessLogicLocal()) facade.close();
-                               } catch (Exception e1) {
-                                       // TODO Auto-generated catch block
-                                       System.out.println("Error: "+e1.toString()+" , probably problems with Business Logic or Database");
-                               }
                                System.exit(1);
                        }
                });
                initialize();
                //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
                                System.exit(1);
                        }
                });
                initialize();
                //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
-       public static ApplicationFacadeInterface getBusinessLogic(){
-               return facadeInterface;
-       }
+       
        
 
        /**
        
 
        /**