1 package org.apache.torque.generator.configuration;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.apache.torque.generator.configuration.controller.Loglevel;
30 import org.apache.torque.generator.configuration.controller.Output;
31 import org.apache.torque.generator.configuration.outlet.OutletConfiguration;
32 import org.apache.torque.generator.configuration.source.EntityReferences;
33 import org.apache.torque.generator.option.Options;
34 import org.apache.torque.generator.source.SourceProvider;
35
36
37
38
39
40
41 public class UnitConfiguration
42 {
43
44 private List<Output> outputList = new ArrayList<Output>();
45
46
47 private Options options;
48
49
50 private SourceProvider overrideSourceProvider;
51
52
53 private boolean overrideSourceProviderInitialized = false;
54
55
56 private OutletConfiguration outletConfiguration;
57
58
59 private EntityReferences entityReferences;
60
61
62 private ConfigurationHandlers configurationHandlers;
63
64
65
66
67
68 private Map<String, File> outputDirectoryMap = new HashMap<String, File>();
69
70
71
72
73 private File workDirectory;
74
75
76 private Loglevel loglevel = Loglevel.INFO;
77
78
79
80
81
82 private String defaultOutputEncoding = null;
83
84
85
86
87
88
89
90
91 public OutletConfiguration getOutletConfiguration()
92 {
93 if (outletConfiguration == null)
94 {
95 throw new IllegalStateException(
96 "outletConfiguration is not initialized");
97 }
98 return outletConfiguration;
99 }
100
101
102
103
104
105
106
107
108 public void setOutletConfiguration(
109 OutletConfiguration outletConfiguration)
110 {
111 if (outletConfiguration == null)
112 {
113 throw new NullPointerException(
114 "outletConfiguration cannot be null");
115 }
116 this.outletConfiguration = outletConfiguration;
117 }
118
119
120
121
122
123
124
125
126 public Options getOptions()
127 {
128 if (options == null)
129 {
130 throw new IllegalStateException(
131 "options are not initialized");
132 }
133 return options;
134 }
135
136
137
138
139
140
141
142
143 public void setOptions(Options options)
144 {
145 if (options == null)
146 {
147 throw new NullPointerException(
148 "options cannot be null");
149 }
150 this.options = options;
151 }
152
153
154
155
156
157
158
159
160
161
162
163
164
165 public File getOutputDirectory(String outputDirKey)
166 {
167 File result = outputDirectoryMap.get(outputDirKey);
168 if (result == null)
169 {
170 throw new IllegalStateException(
171 "The output directory for the key " + outputDirKey
172 + "is not set");
173 }
174 return result;
175 }
176
177
178
179
180
181
182
183
184
185
186
187 public Map<String, File> getOutputDirectoryMap()
188 {
189 if (outputDirectoryMap.get(null) == null)
190 {
191 throw new IllegalStateException(
192 "outputDirectoryMap does not contain a mapping"
193 + " for the key null");
194 }
195 return Collections.unmodifiableMap(outputDirectoryMap);
196 }
197
198
199
200
201
202
203
204
205
206
207
208 public void setOutputDirectoryMap(Map<String, File> outputDirectoryMap)
209 {
210 if (outputDirectoryMap == null)
211 {
212 throw new NullPointerException(
213 "outputDirectoryMap may not be null");
214 }
215 if (outputDirectoryMap.get(null) == null)
216 {
217 throw new IllegalArgumentException(
218 "outputDirectoryMap(null) may not be null");
219 }
220 this.outputDirectoryMap.clear();
221 this.outputDirectoryMap.putAll(outputDirectoryMap);
222 }
223
224
225
226
227
228
229
230
231
232 public File getWorkDirectory()
233 {
234 if (workDirectory == null)
235 {
236 throw new IllegalStateException(
237 "workDirectory is not initialized");
238 }
239 return workDirectory;
240 }
241
242
243
244
245
246
247
248
249 public void setWorkDirectory(File workDirectory)
250 {
251 if (workDirectory == null)
252 {
253 throw new NullPointerException("workDirectory cannot be null");
254 }
255 this.workDirectory = workDirectory;
256 }
257
258
259
260
261
262
263
264
265 public void setOutputList(List<Output> outputList)
266 {
267 if (outputList == null)
268 {
269 throw new NullPointerException(
270 "outputList cannot be null");
271 }
272 this.outputList = outputList;
273 }
274
275
276
277
278
279
280
281
282
283 public List<Output> getOutputList()
284 {
285 if (outputList == null)
286 {
287 throw new IllegalStateException(
288 "outputFiles are not initialized");
289 }
290 return Collections.unmodifiableList(outputList);
291 }
292
293
294
295
296
297
298
299
300 public Loglevel getLoglevel()
301 {
302 if (loglevel == null)
303 {
304 throw new IllegalStateException(
305 "loglevel is not initialized");
306 }
307 return loglevel;
308 }
309
310
311
312
313
314
315
316
317 public void setLoglevel(Loglevel loglevel)
318 {
319 if (loglevel == null)
320 {
321 throw new NullPointerException("loglevel is null");
322 }
323 this.loglevel = loglevel;
324 }
325
326
327
328
329
330
331
332
333
334 public ConfigurationHandlers getConfigurationHandlers()
335 {
336 if (configurationHandlers == null)
337 {
338 throw new IllegalStateException(
339 "configurationHandlers is not initialized");
340 }
341 return configurationHandlers;
342 }
343
344
345
346
347
348
349
350
351
352 public void setConfigurationHandlers(
353 ConfigurationHandlers configurationHandlers)
354 {
355 if (configurationHandlers == null)
356 {
357 throw new NullPointerException(
358 "configurationHandlers cannot be null");
359 }
360 this.configurationHandlers = configurationHandlers;
361 }
362
363
364
365
366
367
368
369
370
371
372 public SourceProvider getOverrideSourceProvider()
373 {
374 if (!overrideSourceProviderInitialized)
375 {
376 throw new IllegalStateException(
377 "overrideSourceProvider is not initialized");
378 }
379 return overrideSourceProvider;
380 }
381
382
383
384
385
386
387
388
389 public void setOverrideSourceProvider(
390 SourceProvider overrideSourceProvider)
391 {
392 this.overrideSourceProvider = overrideSourceProvider;
393 overrideSourceProviderInitialized = true;
394 }
395
396
397
398
399
400
401
402
403 public EntityReferences getEntityReferences()
404 {
405 if (entityReferences == null)
406 {
407 throw new IllegalStateException(
408 "entityReferences are not initialized");
409 }
410 return entityReferences;
411 }
412
413
414
415
416
417
418
419
420 public void setEntityReferences(EntityReferences entityReferences)
421 {
422 if (entityReferences == null)
423 {
424 throw new NullPointerException(
425 "entityReferences cannot be null");
426 }
427 this.entityReferences = entityReferences;
428 }
429
430
431
432
433
434
435
436
437 public String getDefaultOutputEncoding()
438 {
439 return defaultOutputEncoding;
440 }
441
442
443
444
445
446
447
448
449 public void setDefaultOutputEncoding(String defaultOutputEncoding)
450 {
451 this.defaultOutputEncoding = defaultOutputEncoding;
452 }
453
454
455
456
457
458
459
460 public boolean isInit()
461 {
462 if (outputList == null
463 || options == null
464 || outletConfiguration == null
465 || outputDirectoryMap.get(null) == null
466 || loglevel == null
467 || configurationHandlers == null
468 || entityReferences == null
469 || !overrideSourceProviderInitialized)
470 {
471 return false;
472 }
473 return true;
474 }
475
476 @Override
477 public String toString()
478 {
479 StringBuffer result = new StringBuffer();
480 result.append("(outputFiles=")
481 .append(outputList.toString())
482 .append(", options=")
483 .append(options)
484 .append(", outletConfiguration=")
485 .append(outletConfiguration)
486 .append(", outputDirectoryMap=")
487 .append(outputDirectoryMap)
488 .append(", loglevel=")
489 .append(loglevel)
490 .append(")");
491 return result.toString();
492 }
493 }