View Javadoc
1   package ejava.projects.edmv.blimpl;
2   
3   import java.util.List;
4   
5   import org.slf4j.Logger;
6   import org.slf4j.LoggerFactory;
7   
8   import ejava.projects.edmv.bl.EDmvException;
9   import ejava.projects.edmv.bl.PersonMgmt;
10  import ejava.projects.edmv.bl.VehicleMgmt;
11  import ejava.projects.edmv.bo.Person;
12  import ejava.projects.edmv.bo.VehicleRegistration;
13  import ejava.projects.edmv.dao.DAOException;
14  import ejava.projects.edmv.dao.PersonDAO;
15  import ejava.projects.edmv.dao.VehicleDAO;
16  
17  /**
18   * This class provides a simple example of both the person and registration
19   * management implementation. They were combined into a single implementation
20   * class here for simplicity. They could easily be broken out into separate
21   * classes as their implementation gets more complex.
22   */
23  public class EDmvMgmtImpl implements PersonMgmt, VehicleMgmt {
24      private Logger log = LoggerFactory.getLogger(EDmvMgmtImpl.class); 
25  	private PersonDAO personDAO;
26  	private VehicleDAO vehicleDAO;
27  	
28  	public void setPersonDAO(PersonDAO personDAO) {
29  		this.personDAO = personDAO;
30  	}
31  	public void setVehicleDAO(VehicleDAO vehicleDAO) {
32  	    this.vehicleDAO = vehicleDAO;
33  	}	
34  
35      public List<Person> getPeople(int index, int count) throws EDmvException {
36          if (count < 0) {
37              throw new EDmvException("count must be >= 0");
38          }
39          
40          try {
41              return personDAO.getPeople(index, count);
42          }
43          catch (DAOException ex) {
44              log.error("error getting people", ex);
45              throw new EDmvException("error getting people:" + ex);
46          }
47      }
48      
49      public List<VehicleRegistration> getRegistrations(int index, int count)
50              throws EDmvException {
51          if (count < 0) {
52              throw new EDmvException("count must be >= 0");
53          }
54          
55          try {
56              return vehicleDAO.getRegistrations(index, count);
57          }
58          catch (DAOException ex) {
59              log.error("error getting registrations", ex);
60              throw new EDmvException("error getting registrations:" + ex);
61          }
62      }
63  }