1 | package jp.co.orkney.restlet.util; |
---|
2 | |
---|
3 | /** |
---|
4 | * Copyright (c) 2008 Orkney, Inc. <http://www.orkney.co.jp/> |
---|
5 | * |
---|
6 | * This program is free software: you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation, either version 3 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | */ |
---|
19 | |
---|
20 | import java.util.Vector; |
---|
21 | |
---|
22 | /** |
---|
23 | * <b>Service is a class which represents a service.</b> |
---|
24 | * <p> |
---|
25 | * A service is characterized by the following information: |
---|
26 | * <ul> |
---|
27 | * <li>A name</li> |
---|
28 | * <li>A data projection</li> |
---|
29 | * <li>An array of SQL queries</li> |
---|
30 | * <li>A boolean to enable or disable the service</li> |
---|
31 | * <li>A vector containing its parameters</li> |
---|
32 | * <li>A vector containing all formats available for this service</li> |
---|
33 | * <li>A database access configuration (DatabaseConfiguration object)</li> |
---|
34 | * </ul> |
---|
35 | * </p> |
---|
36 | * |
---|
37 | * @author Matthieu Bilbille - Orkney Inc. |
---|
38 | * @version 1.0 |
---|
39 | * @see DatabaseConfiguration |
---|
40 | */ |
---|
41 | public class Service |
---|
42 | { |
---|
43 | private static int nbr_query = 4; |
---|
44 | private String name; |
---|
45 | private String dataProjection; |
---|
46 | private String units; |
---|
47 | private String sqlQuery[]; |
---|
48 | private boolean isEnable; |
---|
49 | private Vector<Parameter> parameters; |
---|
50 | private Vector<Format> formats; |
---|
51 | private DatabaseConfiguration databaseConfiguration; |
---|
52 | private Limit limit; |
---|
53 | |
---|
54 | /** |
---|
55 | * Constructor Service. |
---|
56 | * <p> |
---|
57 | * Creates a new service with empty data (name,projection,...); "isEnable" |
---|
58 | * is initialized with FALSE value |
---|
59 | * </p> |
---|
60 | */ |
---|
61 | public Service() |
---|
62 | { |
---|
63 | name = ""; |
---|
64 | dataProjection = ""; |
---|
65 | sqlQuery = new String[nbr_query]; |
---|
66 | isEnable = false; |
---|
67 | parameters = new Vector<Parameter>(); |
---|
68 | formats = new Vector<Format>(); |
---|
69 | databaseConfiguration = new DatabaseConfiguration(); |
---|
70 | limit = new Limit(); |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | * Constructor Service |
---|
75 | * <p> |
---|
76 | * Makes a copy of an UnService object with new references. |
---|
77 | * </p> |
---|
78 | * |
---|
79 | * @param name |
---|
80 | * service name |
---|
81 | * @param dataProjection |
---|
82 | * service data projection code |
---|
83 | * @param sqlQuery |
---|
84 | * service SQL queries |
---|
85 | * @param isEnable |
---|
86 | * boolean to enable or disable the service |
---|
87 | * @param parameters |
---|
88 | * service parameters |
---|
89 | * @param formats |
---|
90 | * service formats |
---|
91 | * @param databaseConfiguration |
---|
92 | * service database configuratio * To do these steps, ShortestPath class calls some method in IOHelper and DatabaseConnectionn |
---|
93 | */ |
---|
94 | public Service(String name, String dataProjection, String[] sqlQuery, boolean isEnable, Vector<Parameter> parameters, Vector<Format> formats, |
---|
95 | DatabaseConfiguration databaseConfiguration, Limit limit) |
---|
96 | { |
---|
97 | this.name = name; |
---|
98 | this.dataProjection = dataProjection; |
---|
99 | this.sqlQuery = sqlQuery; |
---|
100 | this.isEnable = isEnable; |
---|
101 | this.parameters = new Vector<Parameter>(); |
---|
102 | Parameter tmpParameter = new Parameter(); |
---|
103 | if (parameters != null) |
---|
104 | { |
---|
105 | for (int i = 0; i < parameters.size(); i++) |
---|
106 | { |
---|
107 | tmpParameter = parameters.get(i); |
---|
108 | this.parameters.add(new Parameter(tmpParameter.getName(), tmpParameter.getType(), tmpParameter.getCodeName(), tmpParameter |
---|
109 | .isRequired(), tmpParameter.getDefaultValue())); |
---|
110 | } |
---|
111 | } |
---|
112 | //TODO why we can't just assign this.formats = formats ? |
---|
113 | this.formats = new Vector<Format>(); |
---|
114 | Format tmpFormat = new Format(); |
---|
115 | if (formats != null) |
---|
116 | { |
---|
117 | for (int i = 0; i < formats.size(); i++) |
---|
118 | { |
---|
119 | tmpFormat = formats.get(i); |
---|
120 | this.formats.add(new Format(tmpFormat.getName(), tmpFormat.getSrid(), tmpFormat.isEnableInput(), tmpFormat.isEnableOutput())); |
---|
121 | } |
---|
122 | } |
---|
123 | this.databaseConfiguration = new DatabaseConfiguration(databaseConfiguration.getDriver(), databaseConfiguration.getURL(), |
---|
124 | databaseConfiguration.getUser(), databaseConfiguration.getPassword()); |
---|
125 | this.limit = limit; |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | * Gets the name of the service |
---|
130 | * |
---|
131 | * @return this service's name |
---|
132 | */ |
---|
133 | public String getName() |
---|
134 | { |
---|
135 | return name; |
---|
136 | } |
---|
137 | |
---|
138 | /** |
---|
139 | * Sets the name of the service to the specified string. |
---|
140 | * |
---|
141 | * @param name |
---|
142 | * the string that is to be this service's name |
---|
143 | */ |
---|
144 | public void setName(String name) |
---|
145 | { |
---|
146 | this.name = name; |
---|
147 | } |
---|
148 | |
---|
149 | /** |
---|
150 | * Determines whether this service is enabled. A service may be enabled or |
---|
151 | * disabled by calling its setEnable method. |
---|
152 | * |
---|
153 | * @return true if the service is enabled, false otherwise |
---|
154 | */ |
---|
155 | public boolean isEnable() |
---|
156 | { |
---|
157 | return isEnable; |
---|
158 | } |
---|
159 | |
---|
160 | /** |
---|
161 | * Enables or disables this service. Services are disabled initially by |
---|
162 | * default. |
---|
163 | * |
---|
164 | * @param isEnable |
---|
165 | * if true, this service is enabled; otherwise this service is |
---|
166 | * disabled |
---|
167 | */ |
---|
168 | public void setEnable(boolean isEnable) |
---|
169 | { |
---|
170 | this.isEnable = isEnable; |
---|
171 | } |
---|
172 | |
---|
173 | /** |
---|
174 | * Gets the database configuration of the service |
---|
175 | * |
---|
176 | * @return this service's database configuration |
---|
177 | * @see DatabaseConfiguration |
---|
178 | */ |
---|
179 | public DatabaseConfiguration getDatabaseConfiguration() |
---|
180 | { |
---|
181 | return databaseConfiguration; |
---|
182 | } |
---|
183 | |
---|
184 | /** |
---|
185 | * Sets the database configuration of the service to the specified |
---|
186 | * DatabaseConfiguration object. |
---|
187 | * |
---|
188 | * @param databaseConfiguration |
---|
189 | * the databaseConfiguration that is to be this service's |
---|
190 | * database configuration |
---|
191 | * @see DatabaseConfiguration |
---|
192 | */ |
---|
193 | public void setDatabaseConfiguration(DatabaseConfiguration databaseConfiguration) |
---|
194 | { |
---|
195 | this.databaseConfiguration = databaseConfiguration; |
---|
196 | } |
---|
197 | |
---|
198 | /** |
---|
199 | * Gets the data projection code of the service |
---|
200 | * |
---|
201 | * @return this service's data projection code |
---|
202 | */ |
---|
203 | public String getDataProjection() |
---|
204 | { |
---|
205 | return dataProjection; |
---|
206 | } |
---|
207 | |
---|
208 | /** |
---|
209 | * Sets the data projection of the service to the specified string. |
---|
210 | * |
---|
211 | * @param dataProjection |
---|
212 | * the string that is to be this service's data projection |
---|
213 | */ |
---|
214 | public void setDataProjection(String dataProjection) |
---|
215 | { |
---|
216 | this.dataProjection = dataProjection; |
---|
217 | } |
---|
218 | |
---|
219 | /** |
---|
220 | * Gets the SQL query at the specified position among the SQL queries of the |
---|
221 | * service. |
---|
222 | * |
---|
223 | * @return this service's SQL query at the specified position |
---|
224 | */ |
---|
225 | public String getSQL(int index) |
---|
226 | { |
---|
227 | return sqlQuery[index]; |
---|
228 | } |
---|
229 | |
---|
230 | /** |
---|
231 | * Gets the SQL queries of the service |
---|
232 | * |
---|
233 | * @return this service's SQL queries |
---|
234 | */ |
---|
235 | public String[] getSQL() |
---|
236 | { |
---|
237 | return sqlQuery; |
---|
238 | } |
---|
239 | |
---|
240 | /** |
---|
241 | * Sets the query at the specified position to the specified string. |
---|
242 | * |
---|
243 | * @param sqlQuery |
---|
244 | * query to be stored at the specified position. |
---|
245 | * @param index |
---|
246 | * index of query to replace. |
---|
247 | */ |
---|
248 | public void setSQL(String sqlQuery, int index) |
---|
249 | { |
---|
250 | this.sqlQuery[index] = sqlQuery; |
---|
251 | } |
---|
252 | |
---|
253 | /** |
---|
254 | * Gets the parameters of the service |
---|
255 | * |
---|
256 | * @return this service's parameters |
---|
257 | * @see Parameter |
---|
258 | */ |
---|
259 | public Vector<Parameter> getParameters() |
---|
260 | { |
---|
261 | return parameters; |
---|
262 | } |
---|
263 | |
---|
264 | /** |
---|
265 | * Gets the parameter at the specified position among the parameters of the |
---|
266 | * service(Vector) |
---|
267 | * |
---|
268 | * @param index |
---|
269 | * index of parameter to return |
---|
270 | * @return parameter at the specified index |
---|
271 | * @see Parameter |
---|
272 | */ |
---|
273 | public Parameter getParameter(int index) |
---|
274 | { |
---|
275 | return parameters.get(index); |
---|
276 | } |
---|
277 | |
---|
278 | /** |
---|
279 | * Gets the first parameter with the specified name among the parameters of |
---|
280 | * the service(Vector) |
---|
281 | * |
---|
282 | * @param name |
---|
283 | * parameter name |
---|
284 | * @return this service's parameter with the same name (first one) |
---|
285 | * @see Parameter |
---|
286 | */ |
---|
287 | public Parameter getParameter(String name) |
---|
288 | { |
---|
289 | for (int i = 0; i < parameters.size(); i++) |
---|
290 | { |
---|
291 | if (parameters.get(i).getName().equals(name)) |
---|
292 | return parameters.get(i); |
---|
293 | } |
---|
294 | return null; |
---|
295 | } |
---|
296 | |
---|
297 | /** |
---|
298 | * Sets the parameters of the service to the specified vector<Parameter> |
---|
299 | * |
---|
300 | * @param parameters |
---|
301 | * the vector<Parameter> that is to be this service's parameters |
---|
302 | * @see Parameter |
---|
303 | */ |
---|
304 | public void setParameters(Vector<Parameter> parameters) |
---|
305 | { |
---|
306 | this.parameters = parameters; |
---|
307 | } |
---|
308 | |
---|
309 | /** |
---|
310 | * Sets a parameter of the service at the specified position to the |
---|
311 | * specified parameter. |
---|
312 | * |
---|
313 | * @param index |
---|
314 | * index of parameter to replace. |
---|
315 | * @param parameter |
---|
316 | * Parameter to be stored at the specified position. |
---|
317 | */ |
---|
318 | public void setParameter(int index, Parameter parameter) |
---|
319 | { |
---|
320 | parameters.set(index, parameter); |
---|
321 | } |
---|
322 | |
---|
323 | /** |
---|
324 | * Gets the formats of the service |
---|
325 | * |
---|
326 | * @return this service's formats |
---|
327 | * @see Format |
---|
328 | */ |
---|
329 | public Vector<Format> getFormats() |
---|
330 | { |
---|
331 | return formats; |
---|
332 | } |
---|
333 | |
---|
334 | /** |
---|
335 | * Sets the formats of the service to the specified vector<Format>. |
---|
336 | * |
---|
337 | * @param formats |
---|
338 | * the vector<Format> that is to be this service's formats |
---|
339 | */ |
---|
340 | public void setFormats(Vector<Format> formats) |
---|
341 | { |
---|
342 | this.formats = formats; |
---|
343 | } |
---|
344 | |
---|
345 | public Limit getLimit() |
---|
346 | { |
---|
347 | return limit; |
---|
348 | } |
---|
349 | |
---|
350 | public void setLimit(Limit limit) |
---|
351 | { |
---|
352 | this.limit = limit; |
---|
353 | } |
---|
354 | |
---|
355 | |
---|
356 | } |
---|