1 package info.ejava.examples.ejb.ejbjpa.bl; 2 3 import java.util.List; 4 5 import info.ejava.examples.ejb.ejbjpa.bo.Floor; 6 import info.ejava.examples.ejb.ejbjpa.bo.Guest; 7 import info.ejava.examples.ejb.ejbjpa.bo.Room; 8 import info.ejava.examples.ejb.ejbjpa.dao.HotelDAO; 9 10 public class HotelMgmtImpl implements HotelMgmt { 11 private HotelDAO dao; 12 13 public void setHotelDao(HotelDAO dao) { 14 this.dao = dao; 15 } 16 17 @Override 18 public Room getRoom(int number) { 19 return dao.getRoom(number); 20 } 21 22 @Override 23 public Floor getFloor(int level) { 24 return dao.getFloor(level); 25 } 26 27 @Override 28 public List<Floor> getFloors(int offset, int limit) { 29 return dao.getFloors(offset, limit); 30 } 31 32 @Override 33 public List<Room> getAvailableRooms(Integer level, int offset, int limit) { 34 return dao.getAvailableRooms(level, offset, limit); 35 } 36 37 @Override 38 public Guest checkIn(Guest guest, Room room) throws RoomUnavailableExcepton { 39 if (room==null) { 40 throw new RoomUnavailableExcepton("no room supplied"); 41 } 42 43 Room hotelRoom = dao.getRoom(room.getNumber()); 44 if (hotelRoom==null) { 45 throw new RoomUnavailableExcepton(String.format("room [%d] does not exist", room.getNumber())); 46 } 47 48 if (hotelRoom.getOccupant()!=null) { 49 throw new RoomUnavailableExcepton(String.format("room is occupied by %s", hotelRoom.getOccupant())); 50 } 51 52 dao.addGuest(guest); 53 hotelRoom.setOccupant(guest); 54 return guest; 55 } 56 57 @Override 58 public int checkout(Guest guest) { 59 Room room=dao.findRoomByGuest(guest); 60 if (room!=null) { 61 room.setOccupant(null); 62 return 1; 63 } 64 return 0; 65 } 66 }