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