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.util.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25
26 import org.apache.torque.generator.configuration.controller.Loglevel;
27
28
29
30
31
32
33
34 public class Configuration
35 {
36
37
38
39 private List<UnitDescriptor> unitDescriptors
40 = new ArrayList<UnitDescriptor>();
41
42
43
44
45 private List<UnitConfiguration> unitConfigurations;
46
47
48
49
50 private ConfigurationHandlers configurationHandlers
51 = new ConfigurationHandlers();
52
53
54
55
56 private boolean read = false;
57
58
59
60
61
62
63
64
65
66
67
68 public void addUnit(UnitDescriptor unitDescriptor)
69 {
70 if (unitDescriptor == null)
71 {
72 throw new NullPointerException("unitDescriptor must not be null.");
73 }
74 if (read)
75 {
76 throw new IllegalStateException(
77 "Configuration has already been read.");
78 }
79 unitDescriptors.add(unitDescriptor);
80 }
81
82
83
84
85
86
87
88
89
90
91
92
93
94 public void addUnits(List<UnitDescriptor> unitDescriptors)
95 {
96 for (UnitDescriptor unitDescriptor : unitDescriptors)
97 {
98 addUnit(unitDescriptor);
99 }
100 }
101
102
103
104
105
106
107
108 public void read() throws ConfigurationException
109 {
110 if (read)
111 {
112 throw new IllegalStateException(
113 "Configuration has already been read.");
114 }
115 unitConfigurations = new ArrayList<UnitConfiguration>();
116 Loglevel oldLoglevel = Loglevel.getCurrentLoglevel();
117 for (UnitDescriptor unitDescriptor : unitDescriptors)
118 {
119 if (unitDescriptor.getLoglevel() != null)
120 {
121 unitDescriptor.getLoglevel().apply();
122 }
123 else
124 {
125 oldLoglevel.apply();
126 }
127 UnitConfigurationReader configurationReader
128 = new UnitConfigurationReader();
129
130 UnitConfiguration unitConfiguration
131 = configurationReader.read(
132 unitDescriptor,
133 configurationHandlers);
134 if (unitDescriptor.getLoglevel() != null)
135 {
136 unitConfiguration.setLoglevel(unitDescriptor.getLoglevel());
137 }
138 unitConfigurations.add(unitConfiguration);
139 }
140 read = true;
141 }
142
143
144
145
146
147
148
149
150 public List<UnitConfiguration> getUnitConfigurations()
151 {
152 if (!read)
153 {
154 throw new IllegalStateException("Configuration was not yet read");
155 }
156 return Collections.unmodifiableList(unitConfigurations);
157 }
158
159
160
161
162
163
164 public ConfigurationHandlers getConfigurationHandlers()
165 {
166 return configurationHandlers;
167 }
168
169
170
171
172
173
174
175 public void setConfigurationHandlers(
176 ConfigurationHandlers configurationHandlers)
177 {
178 if (configurationHandlers == null)
179 {
180 throw new NullPointerException(
181 "configurationHandlers must not be null");
182 }
183 this.configurationHandlers = configurationHandlers;
184 }
185 }