|
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.module.DependencyState; |
|
23 |
| import org.qedeq.kernel.bo.module.LoadingState; |
|
24 |
| import org.qedeq.kernel.bo.module.LogicalState; |
|
25 |
| import org.qedeq.kernel.bo.module.ModuleAddress; |
|
26 |
| import org.qedeq.kernel.bo.module.ModuleProperties; |
|
27 |
| import org.qedeq.kernel.bo.module.ModuleReferenceList; |
|
28 |
| import org.qedeq.kernel.bo.module.QedeqBo; |
|
29 |
| import org.qedeq.kernel.common.SourceFileExceptionList; |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| public class DefaultModuleProperties implements ModuleProperties { |
|
39 |
| |
|
40 |
| |
|
41 |
| private final ModuleAddress address; |
|
42 |
| |
|
43 |
| |
|
44 |
| private int loadingCompleteness; |
|
45 |
| |
|
46 |
| |
|
47 |
| private LoadingState loadingState; |
|
48 |
| |
|
49 |
| |
|
50 |
| private DependencyState dependencyState; |
|
51 |
| |
|
52 |
| |
|
53 |
| private LogicalState logicalState; |
|
54 |
| |
|
55 |
| |
|
56 |
| private QedeqBo module; |
|
57 |
| |
|
58 |
| |
|
59 |
| private SourceFileExceptionList exception; |
|
60 |
| |
|
61 |
| |
|
62 |
| private ModuleReferenceList required; |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
460
| public DefaultModuleProperties(final ModuleAddress address) {
|
|
71 |
460
| this.address = address;
|
|
72 |
460
| loadingState = LoadingState.STATE_UNDEFINED;
|
|
73 |
460
| loadingCompleteness = 0;
|
|
74 |
460
| dependencyState = DependencyState.STATE_UNDEFINED;
|
|
75 |
460
| logicalState = LogicalState.STATE_UNCHECKED;
|
|
76 |
| } |
|
77 |
| |
|
78 |
158
| public final boolean hasFailures() {
|
|
79 |
158
| return loadingState.isFailure() || dependencyState.isFailure() || logicalState.isFailure();
|
|
80 |
| } |
|
81 |
| |
|
82 |
2981
| public final String getAddress() {
|
|
83 |
2981
| if (address == null) {
|
|
84 |
0
| return "null";
|
|
85 |
| } |
|
86 |
2981
| return address.getAddress();
|
|
87 |
| } |
|
88 |
| |
|
89 |
1746
| public final ModuleAddress getModuleAddress() {
|
|
90 |
1746
| return address;
|
|
91 |
| } |
|
92 |
| |
|
93 |
410
| public final void setLoadingCompleteness(final int completeness) {
|
|
94 |
410
| this.loadingCompleteness = completeness;
|
|
95 |
| } |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
939
| public final void setLoadingProgressState(final LoadingState state) {
|
|
101 |
939
| if (state == LoadingState.STATE_LOADED) {
|
|
102 |
0
| throw new IllegalArgumentException(
|
|
103 |
| "this state could only be set by calling method setLoaded"); |
|
104 |
| } |
|
105 |
939
| if (state.isFailure()) {
|
|
106 |
0
| throw new IllegalArgumentException(
|
|
107 |
| "this is a failure state, call setLoadingFailureState"); |
|
108 |
| } |
|
109 |
| |
|
110 |
939
| this.loadingState = state;
|
|
111 |
939
| this.module = null;
|
|
112 |
939
| this.dependencyState = DependencyState.STATE_UNDEFINED;
|
|
113 |
939
| this.logicalState = LogicalState.STATE_UNCHECKED;
|
|
114 |
939
| this.exception = null;
|
|
115 |
| } |
|
116 |
| |
|
117 |
22
| public final void setLoadingFailureState(final LoadingState state,
|
|
118 |
| final SourceFileExceptionList e) { |
|
119 |
22
| if (!state.isFailure()) {
|
|
120 |
0
| throw new IllegalArgumentException(
|
|
121 |
| "this is no failure state, call setLoadingProgressState"); |
|
122 |
| } |
|
123 |
| |
|
124 |
| |
|
125 |
22
| this.module = null;
|
|
126 |
22
| this.loadingState = state;
|
|
127 |
22
| this.dependencyState = DependencyState.STATE_UNDEFINED;
|
|
128 |
22
| this.logicalState = LogicalState.STATE_UNCHECKED;
|
|
129 |
22
| this.exception = e;
|
|
130 |
| } |
|
131 |
| |
|
132 |
5158
| public final LoadingState getLoadingState() {
|
|
133 |
5158
| return this.loadingState;
|
|
134 |
| } |
|
135 |
| |
|
136 |
12262
| public final boolean isLoaded() {
|
|
137 |
12262
| return loadingState == LoadingState.STATE_LOADED;
|
|
138 |
| } |
|
139 |
| |
|
140 |
438
| public final void setLoaded(final QedeqBo module) {
|
|
141 |
438
| loadingState = LoadingState.STATE_LOADED;
|
|
142 |
438
| this.module = module;
|
|
143 |
| } |
|
144 |
| |
|
145 |
4983
| public final QedeqBo getModule() {
|
|
146 |
4983
| if (loadingState != LoadingState.STATE_LOADED) {
|
|
147 |
0
| throw new IllegalStateException(
|
|
148 |
| "module exists only if state is \"" + LoadingState.STATE_LOADED.getText() |
|
149 |
| + "\""); |
|
150 |
| } |
|
151 |
4983
| return this.module;
|
|
152 |
| } |
|
153 |
| |
|
154 |
2411
| public final void setDependencyProgressState(final DependencyState state) {
|
|
155 |
2411
| if (!isLoaded() && state != DependencyState.STATE_UNDEFINED) {
|
|
156 |
0
| throw new IllegalArgumentException("module is not yet loaded");
|
|
157 |
| } |
|
158 |
2411
| if (state.isFailure()) {
|
|
159 |
0
| throw new IllegalArgumentException(
|
|
160 |
| "this is a failure state, call setDependencyFailureState"); |
|
161 |
| } |
|
162 |
2411
| if (state == DependencyState.STATE_LOADED_REQUIRED_MODULES) {
|
|
163 |
0
| throw new IllegalArgumentException(
|
|
164 |
| "this state could only be set by calling method setLoadedRequiredModules"); |
|
165 |
| } |
|
166 |
2411
| if (state != DependencyState.STATE_LOADED_REQUIRED_MODULES) {
|
|
167 |
| |
|
168 |
| |
|
169 |
2411
| this.logicalState = LogicalState.STATE_UNCHECKED;
|
|
170 |
| } |
|
171 |
2411
| this.exception = null;
|
|
172 |
2411
| this.dependencyState = state;
|
|
173 |
| } |
|
174 |
| |
|
175 |
2354
| public final void setDependencyFailureState(final DependencyState state,
|
|
176 |
| final SourceFileExceptionList e) { |
|
177 |
2354
| if (!isLoaded()) {
|
|
178 |
0
| throw new IllegalArgumentException("module is not yet loaded");
|
|
179 |
| } |
|
180 |
2354
| if (!state.isFailure()) {
|
|
181 |
0
| throw new IllegalArgumentException(
|
|
182 |
| "this is no failure state, call setLoadingProgressState"); |
|
183 |
| } |
|
184 |
| |
|
185 |
| |
|
186 |
2354
| this.logicalState = LogicalState.STATE_UNCHECKED;
|
|
187 |
2354
| this.dependencyState = state;
|
|
188 |
2354
| this.exception = e;
|
|
189 |
| } |
|
190 |
| |
|
191 |
5826
| public final DependencyState getDependencyState() {
|
|
192 |
5826
| return this.dependencyState;
|
|
193 |
| } |
|
194 |
| |
|
195 |
53
| public final void setLoadedRequiredModules(final ModuleReferenceList list) {
|
|
196 |
53
| if (!isLoaded()) {
|
|
197 |
0
| throw new IllegalStateException(
|
|
198 |
| "Required modules can only be set if module is loaded." |
|
199 |
| + "\"\nCurrently the status for the module" |
|
200 |
| + "\"" + getName() + "\" is \"" + getLoadingState() + "\""); |
|
201 |
| } |
|
202 |
53
| dependencyState = DependencyState.STATE_LOADED_REQUIRED_MODULES;
|
|
203 |
53
| required = list;
|
|
204 |
| } |
|
205 |
| |
|
206 |
0
| public final ModuleReferenceList getRequiredModules() {
|
|
207 |
0
| if (!hasLoadedRequiredModules()) {
|
|
208 |
0
| throw new IllegalStateException(
|
|
209 |
| "module reference list exists only if state is \"" |
|
210 |
| + DependencyState.STATE_LOADED_REQUIRED_MODULES.getText() + "\""); |
|
211 |
| } |
|
212 |
0
| return required;
|
|
213 |
| } |
|
214 |
| |
|
215 |
659
| public final boolean hasLoadedRequiredModules() {
|
|
216 |
659
| return loadingState == LoadingState.STATE_LOADED
|
|
217 |
| && dependencyState == DependencyState.STATE_LOADED_REQUIRED_MODULES; |
|
218 |
| } |
|
219 |
| |
|
220 |
| |
|
221 |
| |
|
222 |
| |
|
223 |
48
| public final void setLogicalProgressState(final LogicalState state) {
|
|
224 |
48
| if (dependencyState.getCode() < DependencyState.STATE_LOADED_REQUIRED_MODULES.getCode()
|
|
225 |
| && state != LogicalState.STATE_UNCHECKED) { |
|
226 |
0
| throw new IllegalArgumentException(
|
|
227 |
| "this state could only be set if all required modules are loaded "); |
|
228 |
| } |
|
229 |
48
| if (state.isFailure()) {
|
|
230 |
0
| throw new IllegalArgumentException(
|
|
231 |
| "this is a failure state, call setLogicalFailureState"); |
|
232 |
| } |
|
233 |
48
| this.exception = null;
|
|
234 |
48
| this.logicalState = state;
|
|
235 |
| } |
|
236 |
| |
|
237 |
12
| public final void setLogicalFailureState(final LogicalState state,
|
|
238 |
| final SourceFileExceptionList e) { |
|
239 |
12
| if ((!isLoaded() || !hasLoadedRequiredModules()) && state != LogicalState.STATE_UNCHECKED) {
|
|
240 |
0
| throw new IllegalArgumentException(
|
|
241 |
| "this state could only be set if all required modules are loaded "); |
|
242 |
| } |
|
243 |
12
| if (!state.isFailure()) {
|
|
244 |
0
| throw new IllegalArgumentException(
|
|
245 |
| "this is no failure state, call setLogicalProgressState"); |
|
246 |
| } |
|
247 |
12
| this.logicalState = state;
|
|
248 |
12
| this.exception = e;
|
|
249 |
| } |
|
250 |
| |
|
251 |
4249
| public final LogicalState getLogicalState() {
|
|
252 |
4249
| return this.logicalState;
|
|
253 |
| } |
|
254 |
| |
|
255 |
396
| public final SourceFileExceptionList getException() {
|
|
256 |
396
| return this.exception;
|
|
257 |
| } |
|
258 |
| |
|
259 |
2099
| public final String getStateDescription() {
|
|
260 |
2099
| if (loadingState == LoadingState.STATE_LOADING_FROM_WEB) {
|
|
261 |
49
| return loadingState.getText() + " (" + loadingCompleteness + "%)";
|
|
262 |
2050
| } else if (!isLoaded()) {
|
|
263 |
1412
| return loadingState.getText();
|
|
264 |
638
| } else if (!hasLoadedRequiredModules()) {
|
|
265 |
514
| return dependencyState.getText();
|
|
266 |
| } else { |
|
267 |
124
| return logicalState.getText();
|
|
268 |
| } |
|
269 |
| } |
|
270 |
| |
|
271 |
3417
| public final String getName() {
|
|
272 |
3417
| if (address == null) {
|
|
273 |
0
| return "null";
|
|
274 |
| } |
|
275 |
3417
| return address.getName();
|
|
276 |
| } |
|
277 |
| |
|
278 |
158
| public final String getRuleVersion() {
|
|
279 |
158
| if (address == null || module == null || module.getQedeq() == null
|
|
280 |
| || module.getQedeq().getHeader() == null |
|
281 |
| || module.getQedeq().getHeader().getSpecification() == null |
|
282 |
| || module.getQedeq().getHeader().getSpecification().getRuleVersion() == null) { |
|
283 |
31
| return "";
|
|
284 |
| } |
|
285 |
127
| return module.getQedeq().getHeader().getSpecification().getRuleVersion();
|
|
286 |
| } |
|
287 |
| |
|
288 |
2086
| public final URL getUrl() {
|
|
289 |
2086
| if (address == null) {
|
|
290 |
0
| return null;
|
|
291 |
| } |
|
292 |
2086
| return address.getURL();
|
|
293 |
| } |
|
294 |
| |
|
295 |
1090
| public final String toString() {
|
|
296 |
1090
| return super.toString() + ":" + address + ";" + loadingState;
|
|
297 |
| } |
|
298 |
| |
|
299 |
| } |