From: Eneko Pinzolas Murua Date: Mon, 9 Mar 2015 13:02:33 +0000 (+0100) Subject: deleted aplicationFacade and imported it's functions to specific business logics. X-Git-Url: https://xp-dev.com/git/RRRRHHHH_Code/commitdiff_plain/e168688434227fc59065555c0bb408fc17e2ebc2 deleted aplicationFacade and imported it's functions to specific business logics. --- diff --git a/ruralHouses/src/businessLogic/BookingManager.java b/ruralHouses/src/businessLogic/BookingManager.java index 18670e1..d4069fc 100644 --- a/ruralHouses/src/businessLogic/BookingManager.java +++ b/ruralHouses/src/businessLogic/BookingManager.java @@ -1,9 +1,14 @@ package businessLogic; +import java.sql.Date; + import com.db4o.ObjectContainer; import com.db4o.ObjectSet; import dataAccess.DB4oManager; +import domain.Booking; +import domain.RuralHouse; +import exceptions.OfferCanNotBeBooked; public final class BookingManager { @@ -13,7 +18,13 @@ public final class BookingManager { 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 @@ -46,4 +57,17 @@ public final class BookingManager { 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 diff --git a/ruralHouses/src/businessLogic/BusinessLogicServer.java b/ruralHouses/src/businessLogic/BusinessLogicServer.java deleted file mode 100644 index 4050bbb..0000000 --- a/ruralHouses/src/businessLogic/BusinessLogicServer.java +++ /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()); - } - - } - -} - diff --git a/ruralHouses/src/businessLogic/HouseManager.java b/ruralHouses/src/businessLogic/HouseManager.java index 1463ad5..e50f4bb 100644 --- a/ruralHouses/src/businessLogic/HouseManager.java +++ b/ruralHouses/src/businessLogic/HouseManager.java @@ -55,6 +55,15 @@ public class HouseManager implements HouseManagerInterface { return this.dbMngr.getRuralHousesByTown(town); } + + + @Override + public Vector 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, diff --git a/ruralHouses/src/businessLogic/HouseManagerInterface.java b/ruralHouses/src/businessLogic/HouseManagerInterface.java index ca99f40..fd5462f 100644 --- a/ruralHouses/src/businessLogic/HouseManagerInterface.java +++ b/ruralHouses/src/businessLogic/HouseManagerInterface.java @@ -25,4 +25,13 @@ public interface HouseManagerInterface { public Vector getHousesByTown(String town); + + /** + * This method retrieves the existing rural houses + * + * @return a Set of rural houses + */ + public Vector getAllRuralHouses()throws RemoteException, + Exception; + } diff --git a/ruralHouses/src/businessLogic/OfferManager.java b/ruralHouses/src/businessLogic/OfferManager.java index 3c00ca5..ea782a0 100644 --- a/ruralHouses/src/businessLogic/OfferManager.java +++ b/ruralHouses/src/businessLogic/OfferManager.java @@ -1,9 +1,18 @@ package businessLogic; +import java.rmi.RemoteException; +import java.sql.Date; + 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 { @@ -11,7 +20,13 @@ public final class OfferManager { 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(); @@ -38,4 +53,22 @@ public final class OfferManager { } 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 index 0000000..e48679b --- /dev/null +++ b/ruralHouses/src/businessLogic/OwnerManager.java @@ -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 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 index 0000000..ab45739 --- /dev/null +++ b/ruralHouses/src/businessLogic/OwnerManagerInterface.java @@ -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 getOwners() throws RemoteException, + Exception; + +} diff --git a/ruralHouses/src/businessLogic/RemoteServer.java b/ruralHouses/src/businessLogic/RemoteServer.java deleted file mode 100644 index 3e1f473..0000000 --- a/ruralHouses/src/businessLogic/RemoteServer.java +++ /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()); - } - } - -} diff --git a/ruralHouses/src/businessLogic/ApplicationFacadeInterface.java b/ruralHouses/src/businessLogic/__ApplicationFacadeInterface.java similarity index 81% rename from ruralHouses/src/businessLogic/ApplicationFacadeInterface.java rename to ruralHouses/src/businessLogic/__ApplicationFacadeInterface.java index 5cf74f5..341d190 100644 --- a/ruralHouses/src/businessLogic/ApplicationFacadeInterface.java +++ b/ruralHouses/src/businessLogic/__ApplicationFacadeInterface.java @@ -13,7 +13,7 @@ import domain.RuralHouse; import exceptions.OfferCanNotBeBooked; -public interface ApplicationFacadeInterface extends Remote { +public interface __ApplicationFacadeInterface extends Remote { /** @@ -48,13 +48,7 @@ public interface ApplicationFacadeInterface extends Remote { public Vector getOwners() throws RemoteException, Exception; - /** - * This method retrieves the existing rural houses - * - * @return a Set of rural houses - */ - public Vector getAllRuralHouses()throws RemoteException, - Exception; + public void close() throws RemoteException; diff --git a/ruralHouses/src/businessLogic/FacadeImplementation.java b/ruralHouses/src/businessLogic/__FacadeImplementation.java similarity index 94% rename from ruralHouses/src/businessLogic/FacadeImplementation.java rename to ruralHouses/src/businessLogic/__FacadeImplementation.java index b97613d..9cbf791 100644 --- a/ruralHouses/src/businessLogic/FacadeImplementation.java +++ b/ruralHouses/src/businessLogic/__FacadeImplementation.java @@ -21,7 +21,7 @@ import exceptions.OfferCanNotBeBooked; 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; - public FacadeImplementation() throws RemoteException, InstantiationException, + public __FacadeImplementation() throws RemoteException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, DB4oManagerCreationException { owners=null; ruralHouses=null; diff --git a/ruralHouses/src/dataAccess/DB4oManager.java b/ruralHouses/src/dataAccess/DB4oManager.java index 80bc080..15b2ad4 100644 --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@ -50,14 +50,12 @@ public class DB4oManager { 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 { - openObjectContainer(); + openSDB(); + System.out.println("Remote DataBase opened"); } 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.common().objectClass(Owner.class).cascadeOnDelete(true); db = Db4oEmbedded.openFile(configuration, c.getDb4oFilename()); } - private void openObjectContainer() { + private void openSDB() { configurationCS = Db4oClientServer.newClientConfiguration(); configurationCS.common().activationDepth(c.getActivationDepth()); @@ -127,7 +126,7 @@ public class DB4oManager { 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; + + if (c.isDatabaseLocal() == false) + openSDB(); + else + openDB(); + try { - if (c.isDatabaseLocal() == false) - openObjectContainer(); + RuralHouse proto = new RuralHouse(ruralHouse.getHouseNumber(), null, null, null, null); @@ -161,6 +165,11 @@ public class DB4oManager { public void deleteDB() { + if (c.isDatabaseLocal() == false) + openSDB(); + else + openDB(); + try { Owner proto = new Owner(null, null); ObjectSet result = db.queryByExample(proto); @@ -172,7 +181,7 @@ public class DB4oManager { } 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 { - + + if (c.isDatabaseLocal() == false) + openSDB(); + else + openDB(); + + Booking bok = null; + try { if (c.isDatabaseLocal() == false) - openObjectContainer(); + openSDB(); RuralHouse proto = new RuralHouse(ruralHouse.getHouseNumber(), null, ruralHouse.getDescription(), ruralHouse.getTown(), @@ -208,18 +224,17 @@ public class DB4oManager { // 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"); - return null; } catch (Exception exc) { exc.printStackTrace(); - return null; } + + return bok; } /** @@ -229,7 +244,9 @@ public class DB4oManager { public Vector getOwners() throws RemoteException, Exception { if (c.isDatabaseLocal() == false) - openObjectContainer(); + openSDB(); + else + openDB(); try { Owner proto = new Owner(null, null); @@ -239,14 +256,17 @@ public class DB4oManager { owners.add((Owner) result.next()); return owners; } finally { - // db.close(); + db.close(); } } public Vector getAllRuralHouses() throws RemoteException, Exception { + if (c.isDatabaseLocal() == false) - openObjectContainer(); + openSDB(); + else + openDB(); 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 { - // db.close(); + db.close(); } } public boolean existsOverlappingOffer(RuralHouse rh, Date firstDay, Date lastDay) throws RemoteException, OverlappingOfferExists { + + if (c.isDatabaseLocal() == false) + openSDB(); + else + openDB(); + try { - if (c.isDatabaseLocal() == false) - openObjectContainer(); + RuralHouse rhn = (RuralHouse) db .queryByExample( @@ -275,7 +300,7 @@ public class DB4oManager { else return false; } finally { - // db.close(); + db.close(); } } @@ -301,8 +326,12 @@ public class DB4oManager { */ public Vector getAccount(String usr, String pwd) throws RemoteException, Exception { + if (c.isDatabaseLocal() == false) - openObjectContainer(); + openSDB(); + else + openDB(); + try { Account proto = new Account(usr, pwd, new Owner(null, null)); ObjectSet result = db.queryByExample(proto); @@ -311,7 +340,7 @@ public class DB4oManager { 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) { -// DB4oManager.openDB(); + if (c.isDatabaseLocal() == false) - openObjectContainer(); + openSDB(); + else + openDB(); + boolean stored = false; RuralHouse house = new RuralHouse(rh.getHouseNumber(), null, null, null, null); @@ -333,15 +365,18 @@ public class DB4oManager { stored = true; } } finally { -// db.close(); + db.close(); } return stored; } public void removeHouse(int houseNumber) { -// DB4oManager.openDB(); + if (c.isDatabaseLocal() == false) - openObjectContainer(); + openSDB(); + else + openDB(); + RuralHouse house = new RuralHouse(houseNumber, null, null, null, null); try { ObjectSet result = db.queryByExample(house); @@ -353,15 +388,19 @@ public class DB4oManager { } catch (Exception exc) { exc.printStackTrace(); } finally { -// db.close(); + db.close(); } } public Vector getRuralHousesByTown(String town){ RuralHouse rh = new RuralHouse(0,null,null,town,null); + if (c.isDatabaseLocal() == false) - openObjectContainer(); + openSDB(); + else + openDB(); + try{ ObjectSet result = db.queryByExample(rh); Vector ruralHouses = new Vector(); @@ -369,7 +408,7 @@ public class DB4oManager { ruralHouses.add(result.next()); return ruralHouses; }finally{ - //db.close(); + db.close(); } } diff --git a/ruralHouses/src/gui/BookRuralHouseGUI.java b/ruralHouses/src/gui/BookRuralHouseGUI.java index 705b351..8e6d7b5 100644 --- a/ruralHouses/src/gui/BookRuralHouseGUI.java +++ b/ruralHouses/src/gui/BookRuralHouseGUI.java @@ -1,6 +1,7 @@ package gui; -import businessLogic.ApplicationFacadeInterface; +import businessLogic.BookingManager; +import businessLogic.HouseManager; 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:"); - ApplicationFacadeInterface facade=StartWindow.getBusinessLogic(); - ruralHouses=facade.getAllRuralHouses(); + HouseManager houseM = new HouseManager(); + ruralHouses=houseM.getAllRuralHouses(); jComboBox1 = new JComboBox(ruralHouses); @@ -159,9 +160,9 @@ public BookRuralHouseGUI() 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); diff --git a/ruralHouses/src/gui/DeleteHouseGUI.java b/ruralHouses/src/gui/DeleteHouseGUI.java index ce2b10b..b369391 100644 --- a/ruralHouses/src/gui/DeleteHouseGUI.java +++ b/ruralHouses/src/gui/DeleteHouseGUI.java @@ -14,7 +14,6 @@ import javax.swing.JComboBox; import javax.swing.JRadioButton; import javax.swing.JButton; -import businessLogic.FacadeImplementation; import businessLogic.HouseManager; import businessLogic.HouseManagerInterface; import domain.Owner; diff --git a/ruralHouses/src/gui/IntroduceOffer2GUI.java b/ruralHouses/src/gui/IntroduceOffer2GUI.java index 276dcfa..db1e2fe 100644 --- a/ruralHouses/src/gui/IntroduceOffer2GUI.java +++ b/ruralHouses/src/gui/IntroduceOffer2GUI.java @@ -10,7 +10,8 @@ import javax.swing.*; import java.awt.*; import java.awt.event.*; -import businessLogic.ApplicationFacadeInterface; + +import businessLogic.OfferManager; 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) - ApplicationFacadeInterface facade=StartWindow.getBusinessLogic(); + OfferManager offerM = new OfferManager(); - facade.createOffer(ruralHouse, firstDay, lastDay, price); + offerM.createOffer(ruralHouse, firstDay, lastDay, price); this.setVisible(false); } diff --git a/ruralHouses/src/gui/QueryAvailabilityGUI.java b/ruralHouses/src/gui/QueryAvailabilityGUI.java index cfad48a..287300b 100644 --- a/ruralHouses/src/gui/QueryAvailabilityGUI.java +++ b/ruralHouses/src/gui/QueryAvailabilityGUI.java @@ -1,10 +1,9 @@ package gui; -import businessLogic.ApplicationFacadeInterface; +import businessLogic.HouseManager; import com.toedter.calendar.JCalendar; -import configuration.ConfigXML; import domain.Offer; import domain.RuralHouse; @@ -48,8 +47,7 @@ private static final long serialVersionUID = 1L; }; - private static configuration.ConfigXML c; - + public QueryAvailabilityGUI() { @@ -66,9 +64,9 @@ private static final long serialVersionUID = 1L; private void jbInit() throws Exception { - ApplicationFacadeInterface facade=StartWindow.getBusinessLogic(); + HouseManager houseM = new HouseManager(); - Vector rhs=facade.getAllRuralHouses(); + Vector rhs=houseM.getAllRuralHouses(); 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(); - 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()); @@ -219,7 +217,6 @@ private static final long serialVersionUID = 1L; try { - ApplicationFacadeInterface facade=StartWindow.getBusinessLogic(); Vector 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()); - Vector row = new Vector(); + Vector row = new Vector(); row.add(of.getOfferNumber()); row.add(of.getRuralHouse().getHouseNumber()); diff --git a/ruralHouses/src/gui/SetAvailability2GUI.java b/ruralHouses/src/gui/SetAvailability2GUI.java index 86a1d29..9b40bbb 100644 --- a/ruralHouses/src/gui/SetAvailability2GUI.java +++ b/ruralHouses/src/gui/SetAvailability2GUI.java @@ -9,7 +9,8 @@ import javax.swing.*; import java.awt.*; import java.awt.event.*; -import businessLogic.ApplicationFacadeInterface; + +import businessLogic.OfferManager; import com.toedter.calendar.JCalendar; @@ -22,6 +23,7 @@ import exceptions.BadDates; public class SetAvailability2GUI extends JFrame { private static final long serialVersionUID = 1L; + 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) - 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()); - 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"); @@ -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 (NullPointerException e1){ + jLabel5.setText("Bad dates or there exists an overlapping offer"); } catch (Exception e1) { - + e1.printStackTrace(); - } + } } private void jButton2_actionPerformed(ActionEvent e) { diff --git a/ruralHouses/src/gui/SetAvailabilityGUI.java b/ruralHouses/src/gui/SetAvailabilityGUI.java index 92e44d9..b4d8ee1 100644 --- a/ruralHouses/src/gui/SetAvailabilityGUI.java +++ b/ruralHouses/src/gui/SetAvailabilityGUI.java @@ -11,7 +11,8 @@ import java.util.Vector; import javax.swing.JButton; -import businessLogic.ApplicationFacadeInterface; +import businessLogic.OwnerManager; +import businessLogic.OwnerManagerInterface; import domain.Owner; import domain.RuralHouse; import javax.swing.JLabel; @@ -73,12 +74,11 @@ public class SetAvailabilityGUI extends JFrame { if (jComboBox == null) { try { - ApplicationFacadeInterface facade=StartWindow.getBusinessLogic(); - Vector owners=facade.getOwners(); + OwnerManagerInterface ownerM = new OwnerManager(); + Vector owners=ownerM.getOwners(); jComboBox = new JComboBox(owners); jComboBox.setBounds(new Rectangle(136, 39, 175, 44)); } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); } diff --git a/ruralHouses/src/gui/StartWindow.java b/ruralHouses/src/gui/StartWindow.java index 3e538ca..ee3ab51 100644 --- a/ruralHouses/src/gui/StartWindow.java +++ b/ruralHouses/src/gui/StartWindow.java @@ -9,10 +9,6 @@ import gui.BookRuralHouseGUI; 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; @@ -37,7 +33,7 @@ public class StartWindow extends JFrame { 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) { @@ -56,8 +52,9 @@ public class StartWindow extends JFrame { 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(); @@ -66,11 +63,11 @@ public class StartWindow extends JFrame { // 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()); @@ -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()); - } 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()); @@ -102,22 +99,13 @@ public class StartWindow extends JFrame { 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); } - public static ApplicationFacadeInterface getBusinessLogic(){ - return facadeInterface; - } + /**