1 package org.wcb.model.manager.impl;
2
3 import org.wcb.exception.ManagerException;
4 import org.wcb.exception.InfrastructureException;
5 import org.wcb.model.dao.IAircraftDAO;
6 import org.wcb.model.vo.hibernate.AircraftBO;
7 import org.wcb.model.manager.IAircraftManager;
8
9 import java.util.List;
10
11 /**
12 * <small>
13 * Copyright (c) 2006 wbogaardt.
14 * Permission is granted to copy, distribute and/or modify this document
15 * under the terms of the GNU Free Documentation License, Version 1.2
16 * or any later version published by the Free Software Foundation;
17 * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
18 * Texts. A copy of the license is included in the section entitled "GNU
19 * Free Documentation License".
20 * <p/>
21 * $File: $ <br>
22 * $Change: $ submitted by $Author: wbogaardt $ at $DateTime: Mar 24, 2006 12:01:32 PM $ <br>
23 * </small>
24 *
25 * @author wbogaardt
26 * @version 1
27 * Date: Mar 24, 2006
28 * Time: 12:01:32 PM
29 */
30
31 public class AircraftManager extends BaseManager implements IAircraftManager {
32
33 private IAircraftDAO iDAO;
34
35 /**
36 * This is injected by Spring framework normally.
37 *
38 * @param oDAO AircraftDAO object injected by spring.
39 */
40 public void setDao(IAircraftDAO oDAO) {
41 this.iDAO = oDAO;
42 }
43
44 /**
45 * This is a bean enabled manager so we can get
46 * a reference to the DAO object this way.
47 * @return The interface to the AircraftDAO.
48 */
49 public IAircraftDAO getDao() {
50 return this.iDAO;
51 }
52
53 /**
54 * Gets all the aircraft in the database
55 * @return list of all registered aircraft
56 * @throws ManagerException
57 */
58 public List<AircraftBO> findAll() throws ManagerException {
59 try
60 {
61 return iDAO.findAll();
62 }
63 catch (InfrastructureException ie) {
64 throw new ManagerException("Could not find any aircraft");
65 }
66 }
67
68 /**
69 * Find a particular aircraft by their registration number
70 * @param registration Registration number to look for or N-number
71 * @return The aircraft if it is found.
72 * @throws ManagerException
73 */
74 public AircraftBO findByRegistry(String registration) throws ManagerException {
75 AircraftBO returnValue = new AircraftBO();
76 try
77 {
78 returnValue = iDAO.findAircraft(registration);
79 if (returnValue == null)
80 {
81 throw new ManagerException("Failed to find registration entry: " + registration);
82 }
83 }
84 catch (InfrastructureException ie)
85 {
86 throw new ManagerException("Failed to find registration entry due to InfrastructureException " + registration, ie);
87 }
88 catch (IndexOutOfBoundsException ioobe) {
89 throw new ManagerException("Failed to find registration entry in database");
90 }
91 return returnValue;
92 }
93
94 /**
95 * This saves the aircraft, special note is that aircraft type must be saved
96 * with the aircraft.
97 * @param craft AircraftBO to save into the database.
98 * @throws ManagerException
99 */
100 public void saveOrUpdateAircraft(AircraftBO craft) throws ManagerException {
101 try
102 {
103 iDAO.saveOrUpdateObject(craft);
104 }
105 catch (Exception ie) {
106 throw new ManagerException("Failed to save aircraft entry due to InfrastructureException ", ie);
107 }
108 }
109
110 /**
111 * This deletes the aircraft, from the database
112 * @param craft AircraftBO to delete from the database.
113 * @throws ManagerException
114 */
115 public void deleteAircraftEntry(AircraftBO craft) throws ManagerException {
116 try
117 {
118 iDAO.deleteAircraft(craft);
119 }
120 catch (InfrastructureException ie) {
121 throw new ManagerException("Failed to delete aircraft entry due to InfrastructureException ", ie);
122 }
123 }
124 }