1 package org.wcb.model.bd;
2
3 import org.wcb.model.service.ILogbookService;
4 import org.wcb.model.vo.hibernate.AircraftBO;
5 import org.wcb.model.vo.hibernate.AircraftTypeBO;
6 import org.wcb.exception.ServiceException;
7
8 import java.util.List;
9 import java.util.ArrayList;
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 28, 2006 8:39:36 AM $ <br>
23 * </small>
24 *
25 * @author wbogaardt
26 * @version 1
27 * Date: Mar 28, 2006
28 * Time: 8:39:36 AM
29 */
30
31 public class AircraftDelegate {
32
33 private ILogbookService logbookService;
34
35 public ILogbookService getLogbookService() {
36 return logbookService;
37 }
38
39 public void setLogbookService(ILogbookService logbookService) {
40 this.logbookService = logbookService;
41 }
42
43 public List<AircraftBO> getAllAircraft() {
44 try
45 {
46 return getLogbookService().findAllAircraft();
47 }
48 catch (ServiceException se)
49 {
50 se.printStackTrace();
51 }
52 return null;
53 }
54
55 public boolean saveAircraftType(AircraftTypeBO type) {
56 try
57 {
58 getLogbookService().saveAircraftType(type);
59 return true;
60 }
61 catch (ServiceException se)
62 {
63 se.printStackTrace();
64 }
65 return false;
66 }
67
68 /**
69 * This gets a list of aircraft types from the database.
70 * @return list of aircraft types stored in the database.
71 */
72 public List<AircraftTypeBO> getAircraftTypes() {
73 try {
74 return getLogbookService().findAllAircraftType();
75 }
76 catch (ServiceException se)
77 {
78 ArrayList<AircraftTypeBO> list = new ArrayList<AircraftTypeBO>();
79 list.add(new AircraftTypeBO("Cessna", "150M", "C-150M", 0));
80 return list;
81 }
82 }
83
84 /**
85 * Get an aircraft type based on an interger value
86 * @param id integer value in the database
87 * @return AircraftTypeBO will default to Cessna 150 if no database found.
88 */
89 public AircraftTypeBO getAircraftType(Integer id) {
90 try
91 {
92 return getLogbookService().getAircraftTypeById(id);
93 }
94 catch (ServiceException se)
95 {
96 se.printStackTrace();
97 }
98 return new AircraftTypeBO("Cessna","150M","C-150M",0);
99 }
100
101 /**
102 * This saves an aircraft which is a registration number
103 * and an aircraft type.
104 * @param craft AircraftBO object which has an association to aircraft_type.
105 * @return True successfully saved, otherwise false indicates a problem saving the data.
106 */
107 public boolean saveAircraft(AircraftBO craft) {
108 try
109 {
110 getLogbookService().saveAircraft(craft);
111 }
112 catch (ServiceException se) {
113 return false;
114 }
115 return true;
116 }
117
118 /**
119 * This saves an aircraft which is a registration number
120 * and an aircraft type.
121 * @param craft AircraftBO object which has an association to aircraft_type.
122 * @return True successfully saved, otherwise false indicates a problem saving the data.
123 */
124 public boolean deleteAircraft(AircraftBO craft) {
125 try
126 {
127 getLogbookService().deleteAircraft(craft);
128 }
129 catch (ServiceException se) {
130 return false;
131 }
132 return true;
133 }
134 }