|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.qedeq.kernel.bo.load; |
|
19 |
| |
|
20 |
| import java.net.URL; |
|
21 |
| |
|
22 |
| import org.qedeq.kernel.bo.logic.ExistenceChecker; |
|
23 |
| import org.qedeq.kernel.bo.module.DependencyState; |
|
24 |
| import org.qedeq.kernel.bo.module.LoadingState; |
|
25 |
| import org.qedeq.kernel.bo.module.LogicalState; |
|
26 |
| import org.qedeq.kernel.bo.module.ModuleAddress; |
|
27 |
| import org.qedeq.kernel.bo.module.ModuleProperties; |
|
28 |
| import org.qedeq.kernel.bo.module.ModuleReferenceList; |
|
29 |
| import org.qedeq.kernel.bo.module.QedeqBo; |
|
30 |
| import org.qedeq.kernel.common.SourceFileExceptionList; |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| public class DefaultModuleProperties implements ModuleProperties { |
|
40 |
| |
|
41 |
| |
|
42 |
| private final ModuleAddress address; |
|
43 |
| |
|
44 |
| |
|
45 |
| private int loadingCompleteness; |
|
46 |
| |
|
47 |
| |
|
48 |
| private LoadingState loadingState; |
|
49 |
| |
|
50 |
| |
|
51 |
| private DependencyState dependencyState; |
|
52 |
| |
|
53 |
| |
|
54 |
| private LogicalState logicalState; |
|
55 |
| |
|
56 |
| |
|
57 |
| private QedeqBo module; |
|
58 |
| |
|
59 |
| |
|
60 |
| private SourceFileExceptionList exception; |
|
61 |
| |
|
62 |
| |
|
63 |
| private ModuleReferenceList required; |
|
64 |
| |
|
65 |
| |
|
66 |
| private ExistenceChecker checker; |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
333
| public DefaultModuleProperties(final ModuleAddress address) {
|
|
75 |
333
| this.address = address;
|
|
76 |
333
| loadingState = LoadingState.STATE_UNDEFINED;
|
|
77 |
333
| loadingCompleteness = 0;
|
|
78 |
333
| dependencyState = DependencyState.STATE_UNDEFINED;
|
|
79 |
333
| logicalState = LogicalState.STATE_UNCHECKED;
|
|
80 |
| } |
|
81 |
| |
|
82 |
132
| public final boolean hasFailures() {
|
|
83 |
132
| return loadingState.isFailure() || dependencyState.isFailure() || logicalState.isFailure();
|
|
84 |
| } |
|
85 |
| |
|
86 |
2281
| public final ModuleAddress getModuleAddress() {
|
|
87 |
2281
| return address;
|
|
88 |
| } |
|
89 |
| |
|
90 |
349
| public final void setLoadingCompleteness(final int completeness) {
|
|
91 |
349
| this.loadingCompleteness = completeness;
|
|
92 |
| } |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
627
| public final void setLoadingProgressState(final LoadingState state) {
|
|
98 |
627
| if (state == LoadingState.STATE_LOADED) {
|
|
99 |
0
| throw new IllegalArgumentException(
|
|
100 |
| "this state could only be set by calling method setLoaded"); |
|
101 |
| } |
|
102 |
627
| if (state.isFailure()) {
|
|
103 |
0
| throw new IllegalArgumentException(
|
|
104 |
| "this is a failure state, call setLoadingFailureState"); |
|
105 |
| } |
|
106 |
| |
|
107 |
627
| this.loadingState = state;
|
|
108 |
627
| this.module = null;
|
|
109 |
627
| this.dependencyState = DependencyState.STATE_UNDEFINED;
|
|
110 |
627
| this.logicalState = LogicalState.STATE_UNCHECKED;
|
|
111 |
627
| this.exception = null;
|
|
112 |
| } |
|
113 |
| |
|
114 |
19
| public final void setLoadingFailureState(final LoadingState state,
|
|
115 |
| final SourceFileExceptionList e) { |
|
116 |
19
| if (!state.isFailure()) {
|
|
117 |
0
| throw new IllegalArgumentException(
|
|
118 |
| "this is no failure state, call setLoadingProgressState"); |
|
119 |
| } |
|
120 |
| |
|
121 |
| |
|
122 |
19
| this.module = null;
|
|
123 |
19
| this.loadingState = state;
|
|
124 |
19
| this.dependencyState = DependencyState.STATE_UNDEFINED;
|
|
125 |
19
| this.logicalState = LogicalState.STATE_UNCHECKED;
|
|
126 |
19
| this.exception = e;
|
|
127 |
| } |
|
128 |
| |
|
129 |
3605
| public final LoadingState getLoadingState() {
|
|
130 |
3605
| return this.loadingState;
|
|
131 |
| } |
|
132 |
| |
|
133 |
2209
| public final boolean isLoaded() {
|
|
134 |
2209
| return loadingState == LoadingState.STATE_LOADED;
|
|
135 |
| } |
|
136 |
| |
|
137 |
316
| public final void setLoaded(final QedeqBo module) {
|
|
138 |
316
| loadingState = LoadingState.STATE_LOADED;
|
|
139 |
316
| this.module = module;
|
|
140 |
| } |
|
141 |
| |
|
142 |
335
| public final QedeqBo getModule() {
|
|
143 |
335
| if (loadingState != LoadingState.STATE_LOADED) {
|
|
144 |
0
| throw new IllegalStateException(
|
|
145 |
| "module exists only if state is \"" + LoadingState.STATE_LOADED.getText() |
|
146 |
| + "\""); |
|
147 |
| } |
|
148 |
335
| return this.module;
|
|
149 |
| } |
|
150 |
| |
|
151 |
69
| public final void setDependencyProgressState(final DependencyState state) {
|
|
152 |
69
| if (!isLoaded() && state != DependencyState.STATE_UNDEFINED) {
|
|
153 |
0
| throw new IllegalArgumentException("module is not yet loaded");
|
|
154 |
| } |
|
155 |
69
| if (state.isFailure()) {
|
|
156 |
0
| throw new IllegalArgumentException(
|
|
157 |
| "this is a failure state, call setDependencyFailureState"); |
|
158 |
| } |
|
159 |
69
| if (state == DependencyState.STATE_LOADED_REQUIRED_MODULES) {
|
|
160 |
0
| throw new IllegalArgumentException(
|
|
161 |
| "this state could only be set by calling method setLoadedRequiredModules"); |
|
162 |
| } |
|
163 |
69
| if (state != DependencyState.STATE_LOADED_REQUIRED_MODULES) {
|
|
164 |
| |
|
165 |
| |
|
166 |
69
| this.logicalState = LogicalState.STATE_UNCHECKED;
|
|
167 |
69
| this.required = null;
|
|
168 |
| } |
|
169 |
69
| this.exception = null;
|
|
170 |
69
| this.dependencyState = state;
|
|
171 |
| } |
|
172 |
| |
|
173 |
0
| public final void setDependencyFailureState(final DependencyState state,
|
|
174 |
| final SourceFileExceptionList e) { |
|
175 |
0
| if (!isLoaded()) {
|
|
176 |
0
| throw new IllegalArgumentException("module is not yet loaded");
|
|
177 |
| } |
|
178 |
0
| if (!state.isFailure()) {
|
|
179 |
0
| throw new IllegalArgumentException(
|
|
180 |
| "this is no failure state, call setLoadingProgressState"); |
|
181 |
| } |
|
182 |
| |
|
183 |
| |
|
184 |
0
| this.logicalState = LogicalState.STATE_UNCHECKED;
|
|
185 |
0
| this.dependencyState = state;
|
|
186 |
0
| this.exception = e;
|
|
187 |
| } |
|
188 |
| |
|
189 |
2240
| public final DependencyState getDependencyState() {
|
|
190 |
2240
| return this.dependencyState;
|
|
191 |
| } |
|
192 |
| |
|
193 |
84
| public final void setLoadedRequiredModules(final ModuleReferenceList list) {
|
|
194 |
84
| if (!isLoaded()) {
|
|
195 |
0
| throw new IllegalStateException(
|
|
196 |
| "Required modules can only be set if module is loaded." |
|
197 |
| + "\"\nCurrently the status for the module" |
|
198 |
| + "\"" + getName() + "\" is \"" + getLoadingState() + "\""); |
|
199 |
| } |
|
200 |
84
| dependencyState = DependencyState.STATE_LOADED_REQUIRED_MODULES;
|
|
201 |
84
| required = list;
|
|
202 |
| } |
|
203 |
| |
|
204 |
1243
| public final ModuleReferenceList getRequiredModules() {
|
|
205 |
1243
| if (!hasLoadedRequiredModules()) {
|
|
206 |
0
| throw new IllegalStateException(
|
|
207 |
| "module reference list exists only if state is \"" |
|
208 |
| + DependencyState.STATE_LOADED_REQUIRED_MODULES.getText() + "\""); |
|
209 |
| } |
|
210 |
1243
| return required;
|
|
211 |
| } |
|
212 |
| |
|
213 |
3890
| public final boolean hasLoadedRequiredModules() {
|
|
214 |
3890
| return loadingState == LoadingState.STATE_LOADED
|
|
215 |
| && dependencyState == DependencyState.STATE_LOADED_REQUIRED_MODULES; |
|
216 |
| } |
|
217 |
| |
|
218 |
38
| public final void setChecked(final ExistenceChecker checker) {
|
|
219 |
38
| if (!hasLoadedRequiredModules()) {
|
|
220 |
0
| throw new IllegalStateException(
|
|
221 |
| "Checked can only be set if all required modules are loaded." |
|
222 |
| + "\"\nCurrently the status for the module" |
|
223 |
| + "\"" + getName() + "\" is \"" + getLoadingState() + "\""); |
|
224 |
| } |
|
225 |
38
| logicalState = LogicalState.STATE_CHECKED;
|
|
226 |
38
| this.checker = checker;
|
|
227 |
| } |
|
228 |
| |
|
229 |
1898
| public final ExistenceChecker getExistenceChecker() {
|
|
230 |
1898
| if (!hasLoadedRequiredModules()) {
|
|
231 |
0
| throw new IllegalStateException(
|
|
232 |
| "existence checker exists only if state is \"" |
|
233 |
| + LogicalState.STATE_CHECKED.getText() + "\""); |
|
234 |
| } |
|
235 |
1898
| return checker;
|
|
236 |
| } |
|
237 |
| |
|
238 |
349
| public final boolean isChecked() {
|
|
239 |
349
| return loadingState == LoadingState.STATE_LOADED
|
|
240 |
| && dependencyState == DependencyState.STATE_LOADED_REQUIRED_MODULES |
|
241 |
| && logicalState == LogicalState.STATE_CHECKED; |
|
242 |
| } |
|
243 |
| |
|
244 |
| |
|
245 |
| |
|
246 |
| |
|
247 |
118
| public final void setLogicalProgressState(final LogicalState state) {
|
|
248 |
118
| if (dependencyState.getCode() < DependencyState.STATE_LOADED_REQUIRED_MODULES.getCode()
|
|
249 |
| && state != LogicalState.STATE_UNCHECKED) { |
|
250 |
0
| throw new IllegalArgumentException(
|
|
251 |
| "this state could only be set if all required modules are loaded "); |
|
252 |
| } |
|
253 |
118
| if (state.isFailure()) {
|
|
254 |
0
| throw new IllegalArgumentException(
|
|
255 |
| "this is a failure state, call setLogicalFailureState"); |
|
256 |
| } |
|
257 |
118
| if (state == LogicalState.STATE_CHECKED) {
|
|
258 |
0
| throw new IllegalArgumentException(
|
|
259 |
| "set with setChecked(ExistenceChecker)"); |
|
260 |
| } |
|
261 |
118
| this.exception = null;
|
|
262 |
118
| this.logicalState = state;
|
|
263 |
| } |
|
264 |
| |
|
265 |
21
| public final void setLogicalFailureState(final LogicalState state,
|
|
266 |
| final SourceFileExceptionList e) { |
|
267 |
21
| if ((!isLoaded() || !hasLoadedRequiredModules()) && state != LogicalState.STATE_UNCHECKED) {
|
|
268 |
0
| throw new IllegalArgumentException(
|
|
269 |
| "this state could only be set if all required modules are loaded "); |
|
270 |
| } |
|
271 |
21
| if (!state.isFailure()) {
|
|
272 |
0
| throw new IllegalArgumentException(
|
|
273 |
| "this is no failure state, call setLogicalProgressState"); |
|
274 |
| } |
|
275 |
21
| this.logicalState = state;
|
|
276 |
21
| this.exception = e;
|
|
277 |
| } |
|
278 |
| |
|
279 |
3007
| public final LogicalState getLogicalState() {
|
|
280 |
3007
| return this.logicalState;
|
|
281 |
| } |
|
282 |
| |
|
283 |
423
| public final SourceFileExceptionList getException() {
|
|
284 |
423
| return this.exception;
|
|
285 |
| } |
|
286 |
| |
|
287 |
1588
| public final String getStateDescription() {
|
|
288 |
1588
| if (loadingState == LoadingState.STATE_LOADING_FROM_WEB) {
|
|
289 |
34
| return loadingState.getText() + " (" + loadingCompleteness + "%)";
|
|
290 |
1554
| } else if (!isLoaded()) {
|
|
291 |
952
| return loadingState.getText();
|
|
292 |
602
| } else if (!hasLoadedRequiredModules()) {
|
|
293 |
352
| if (dependencyState == DependencyState.STATE_UNDEFINED) {
|
|
294 |
282
| return loadingState.getText();
|
|
295 |
| } |
|
296 |
70
| return dependencyState.getText();
|
|
297 |
250
| } else if (!isChecked()) {
|
|
298 |
210
| if (logicalState == LogicalState.STATE_UNCHECKED) {
|
|
299 |
69
| return dependencyState.getText();
|
|
300 |
| } |
|
301 |
141
| return logicalState.getText();
|
|
302 |
| } |
|
303 |
40
| return logicalState.getText();
|
|
304 |
| } |
|
305 |
| |
|
306 |
2248
| public final String getName() {
|
|
307 |
2248
| if (address == null) {
|
|
308 |
0
| return "null";
|
|
309 |
| } |
|
310 |
2248
| return address.getName();
|
|
311 |
| } |
|
312 |
| |
|
313 |
132
| public final String getRuleVersion() {
|
|
314 |
132
| if (address == null || module == null || module.getQedeq() == null
|
|
315 |
| || module.getQedeq().getHeader() == null |
|
316 |
| || module.getQedeq().getHeader().getSpecification() == null |
|
317 |
| || module.getQedeq().getHeader().getSpecification().getRuleVersion() == null) { |
|
318 |
117
| return "";
|
|
319 |
| } |
|
320 |
15
| return module.getQedeq().getHeader().getSpecification().getRuleVersion();
|
|
321 |
| } |
|
322 |
| |
|
323 |
3648
| public final URL getUrl() {
|
|
324 |
3648
| if (address == null) {
|
|
325 |
0
| return null;
|
|
326 |
| } |
|
327 |
3648
| return address.getURL();
|
|
328 |
| } |
|
329 |
| |
|
330 |
386
| public final String toString() {
|
|
331 |
386
| return super.toString() + ":" + address + ";" + loadingState;
|
|
332 |
| } |
|
333 |
| |
|
334 |
| } |