/*This code was generated using the UMPLE modeling language! Date of generation: 2008/07/30 10:46:15*/ /*This class drives: ItemOnBill, Booking*/ package hotel.core; import java.util.*; import java.sql.Time; import java.sql.Date; import hotel.*; import hotel.json.*; public class Booking { //Class datatypes private String startDate; private String endDate; private String startTime; private String endTime; private String bedroomsRequired; private String creditCardToBill; //Class association variables private List itemOnBills; private List subsidiaryBookings; private Booking booking; private List rentableSpaces; private Person person; //Registry of our system. HotelRegistry registry = HotelRegistry.getInstance(); //Constructor public Booking(String aStartDate, String aEndDate, String aStartTime, String aEndTime, String aBedroomsRequired, String aCreditCardToBill, Booking aBooking, Person aPerson) { startDate = aStartDate; endDate = aEndDate; startTime = aStartTime; endTime = aEndTime; bedroomsRequired = aBedroomsRequired; creditCardToBill = aCreditCardToBill; itemOnBills = new ArrayList(); registry.add(itemOnBills); subsidiaryBookings = new ArrayList(); registry.add(subsidiaryBookings); booking = aBooking; booking.addSubsidiaryBooking(this); rentableSpaces = new ArrayList(); registry.add(rentableSpaces); person = aPerson; person.addBooking(this); } public boolean setStartDate(String aStartDate) { startDate = aStartDate; return true; } public boolean setEndDate(String aEndDate) { endDate = aEndDate; return true; } public boolean setStartTime(String aStartTime) { startTime = aStartTime; return true; } public boolean setEndTime(String aEndTime) { endTime = aEndTime; return true; } public boolean setBedroomsRequired(String aBedroomsRequired) { bedroomsRequired = aBedroomsRequired; return true; } public boolean setCreditCardToBill(String aCreditCardToBill) { creditCardToBill = aCreditCardToBill; return true; } public String getStartDate() { return startDate; } public String getEndDate() { return endDate; } public String getStartTime() { return startTime; } public String getEndTime() { return endTime; } public String getBedroomsRequired() { return bedroomsRequired; } public String getCreditCardToBill() { return creditCardToBill; } public List getItemOnBills() { return itemOnBills; } public List getSubsidiaryBookings() { return subsidiaryBookings; } public Booking getBooking() { return booking; } public List getRentableSpaces() { return rentableSpaces; } public Person getPerson() { return person; } public ItemOnBill addItemOnBill(String aDescription, String aCharge, Booking aBooking) { ItemOnBill newItemOnBill; newItemOnBill = new ItemOnBill(aDescription, aCharge, this); if (!itemOnBills.contains(newItemOnBill)) { registry.add(newItemOnBill); itemOnBills.add(newItemOnBill); } return newItemOnBill; } public ItemOnBill addItemOnBill(ItemOnBill aItemOnBill) { if (!itemOnBills.contains(aItemOnBill)) itemOnBills.add(aItemOnBill); return aItemOnBill; } public Booking addSubsidiaryBooking(String aStartDate, String aEndDate, String aStartTime, String aEndTime, String aBedroomsRequired, String aCreditCardToBill, Booking aBooking, Person aPerson) { Booking newBooking; newBooking = new Booking(aStartDate, aEndDate, aStartTime, aEndTime, aBedroomsRequired, aCreditCardToBill, this, aPerson); if (!subsidiaryBookings.contains(newBooking)) { registry.add(newBooking); subsidiaryBookings.add(newBooking); } return newBooking; } public Booking addSubsidiaryBooking(Booking aSubsidiaryBooking) { if (!subsidiaryBookings.contains(aSubsidiaryBooking)) subsidiaryBookings.add(aSubsidiaryBooking); return aSubsidiaryBooking; } public RentableSpace addRentableSpace(String aCostPerDay, String aFloorArea, Hotel aHotel, Suite aSuite) { RentableSpace newRentableSpace; newRentableSpace = new RentableSpace(aCostPerDay, aFloorArea, aHotel, aSuite); if (!rentableSpaces.contains(newRentableSpace)) { registry.add(newRentableSpace); rentableSpaces.add(newRentableSpace); } return newRentableSpace; } public RentableSpace addRentableSpace(RentableSpace aRentableSpace) { if (!rentableSpaces.contains(aRentableSpace)) rentableSpaces.add(aRentableSpace); return aRentableSpace; } /* This class does not drive Booking and therefore sets the association unidirectionally.*/ public void setBooking(Booking aBooking) { booking = aBooking; } /* This class does not drive Person and therefore sets the association unidirectionally.*/ public void setPerson(Person aPerson) { person = aPerson; } public void delete() { //Delete all many ends first. for (ItemOnBill aItemOnBill : itemOnBills) { aItemOnBill.delete(); } itemOnBills.clear(); //Delete all many ends first. for (Booking aBooking : subsidiaryBookings) { aBooking.delete(); } subsidiaryBookings.clear(); //Delete all 1 ends. booking.deleteSubsidiaryBooking(this); person.deleteBooking(this); } public void deleteItemOnBill(ItemOnBill aItemOnBill) { if (itemOnBills.contains(aItemOnBill)) { itemOnBills.remove(aItemOnBill); //registry.removeObj(registry.getKey(aItemOnBill)); } else //Throw an UmpleException .. to be implemented. { } } public void deleteSubsidiaryBooking(Booking aBooking) { if (subsidiaryBookings.contains(aBooking)) { subsidiaryBookings.remove(aBooking); //registry.removeObj(registry.getKey(aBooking)); } else //Throw an UmpleException .. to be implemented. { } } public void deleteRentableSpace(RentableSpace aRentableSpace) { if (rentableSpaces.contains(aRentableSpace)) { rentableSpaces.remove(aRentableSpace); //registry.removeObj(registry.getKey(aRentableSpace)); } else //Throw an UmpleException .. to be implemented. { } } public boolean areManyEndsNull() { if (itemOnBills.size() == 0 && subsidiaryBookings.size() == 0) { return true; } else return false; } /*********************************** * Returns the attribute list along with the * class ID in JSON format. ***********************************/ public JSONObject getAttributes() throws JSONException { JSONObject obj = new JSONObject(); obj.put("CLASS_ID", registry.getKey(this)); obj.put("startDate", getStartDate()); obj.put("endDate", getEndDate()); obj.put("startTime", getStartTime()); obj.put("endTime", getEndTime()); obj.put("bedroomsRequired", getBedroomsRequired()); obj.put("creditCardToBill", getCreditCardToBill()); return obj; } }