|
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.LoadingState; |
|
23 |
| import org.qedeq.kernel.bo.module.LogicalState; |
|
24 |
| import org.qedeq.kernel.bo.module.ModuleAddress; |
|
25 |
| import org.qedeq.kernel.bo.module.ModuleProperties; |
|
26 |
| import org.qedeq.kernel.bo.module.QedeqBo; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| public class DefaultModuleProperties implements ModuleProperties { |
|
36 |
| |
|
37 |
| |
|
38 |
| private final ModuleAddress address; |
|
39 |
| |
|
40 |
| |
|
41 |
| private int loadingCompleteness; |
|
42 |
| |
|
43 |
| |
|
44 |
| private LoadingState loadingState; |
|
45 |
| |
|
46 |
| |
|
47 |
| private LogicalState logicalState; |
|
48 |
| |
|
49 |
| |
|
50 |
| private QedeqBo module; |
|
51 |
| |
|
52 |
| |
|
53 |
| private Exception exception; |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
19
| public DefaultModuleProperties(final ModuleAddress address) {
|
|
62 |
19
| this.address = address;
|
|
63 |
19
| this.loadingState = LoadingState.STATE_UNDEFINED;
|
|
64 |
19
| this.loadingCompleteness = 0;
|
|
65 |
19
| this.logicalState = LogicalState.STATE_UNCHECKED;
|
|
66 |
| } |
|
67 |
| |
|
68 |
0
| public final boolean hasFailures() {
|
|
69 |
0
| return this.loadingState.isFailure();
|
|
70 |
| } |
|
71 |
| |
|
72 |
86
| public final String getAddress() {
|
|
73 |
86
| if (address == null) {
|
|
74 |
0
| return "null";
|
|
75 |
| } |
|
76 |
86
| return address.getAddress();
|
|
77 |
| } |
|
78 |
| |
|
79 |
19
| public final ModuleAddress getModuleAddress() {
|
|
80 |
19
| return address;
|
|
81 |
| } |
|
82 |
| |
|
83 |
0
| public final void setLoadingCompleteness(final int completeness) {
|
|
84 |
0
| this.loadingCompleteness = completeness;
|
|
85 |
| } |
|
86 |
| |
|
87 |
34
| public final void setLoadingProgressState(final LoadingState state) {
|
|
88 |
34
| if (state == LoadingState.STATE_LOADED) {
|
|
89 |
0
| throw new IllegalArgumentException(
|
|
90 |
| "this state could only be set by calling method setCheckedAndLoaded"); |
|
91 |
| } |
|
92 |
34
| if (this.loadingState == LoadingState.STATE_LOADED) {
|
|
93 |
0
| this.module = null;
|
|
94 |
| } |
|
95 |
34
| if (state.isFailure()) {
|
|
96 |
0
| throw new IllegalArgumentException(
|
|
97 |
| "this is a failure state, call setLoadingFailureState"); |
|
98 |
| } |
|
99 |
34
| this.exception = null;
|
|
100 |
34
| this.loadingState = state;
|
|
101 |
| } |
|
102 |
| |
|
103 |
10
| public final void setLoadingFailureState(final LoadingState state, final Exception e) {
|
|
104 |
10
| if (!state.isFailure()) {
|
|
105 |
0
| throw new IllegalArgumentException(
|
|
106 |
| "this is no failure state, call setProgressState"); |
|
107 |
| } |
|
108 |
10
| if (this.loadingState == LoadingState.STATE_LOADED) {
|
|
109 |
0
| this.module = null;
|
|
110 |
| } |
|
111 |
10
| this.loadingState = state;
|
|
112 |
10
| this.exception = e;
|
|
113 |
| } |
|
114 |
| |
|
115 |
181
| public final LoadingState getLoadingState() {
|
|
116 |
181
| return this.loadingState;
|
|
117 |
| } |
|
118 |
| |
|
119 |
0
| public final void setLogicalProgressState(final LogicalState state) {
|
|
120 |
0
| if (state != LogicalState.STATE_UNCHECKED && loadingState != LoadingState.STATE_LOADED) {
|
|
121 |
0
| throw new IllegalArgumentException(
|
|
122 |
| "this state could only be set for loaded modules"); |
|
123 |
| } |
|
124 |
0
| if (state.isFailure()) {
|
|
125 |
0
| throw new IllegalArgumentException(
|
|
126 |
| "this is a failure state, call setLogicalFailureState"); |
|
127 |
| } |
|
128 |
0
| this.exception = null;
|
|
129 |
0
| this.logicalState = state;
|
|
130 |
| } |
|
131 |
| |
|
132 |
0
| public final void setLogicalFailureState(final LogicalState state, final Exception e) {
|
|
133 |
0
| if (state != LogicalState.STATE_UNCHECKED && loadingState != LoadingState.STATE_LOADED) {
|
|
134 |
0
| throw new IllegalArgumentException(
|
|
135 |
| "this state could only be set for loaded modules"); |
|
136 |
| } |
|
137 |
0
| if (!state.isFailure()) {
|
|
138 |
0
| throw new IllegalArgumentException(
|
|
139 |
| "this is no failure state, call setProgressState"); |
|
140 |
| } |
|
141 |
0
| this.logicalState = state;
|
|
142 |
0
| this.exception = e;
|
|
143 |
| } |
|
144 |
| |
|
145 |
64
| public final LogicalState getLogicalState() {
|
|
146 |
64
| return this.logicalState;
|
|
147 |
| } |
|
148 |
| |
|
149 |
10
| public final Exception getException() {
|
|
150 |
10
| return this.exception;
|
|
151 |
| } |
|
152 |
| |
|
153 |
92
| public final String getStateDescription() {
|
|
154 |
92
| if (this.loadingState == LoadingState.STATE_LOADING_FROM_WEB) {
|
|
155 |
0
| return this.loadingState.getText() + " (" + this.loadingCompleteness + "%)";
|
|
156 |
| } else { |
|
157 |
92
| return this.loadingState.getText();
|
|
158 |
| } |
|
159 |
| } |
|
160 |
| |
|
161 |
109
| public final String getName() {
|
|
162 |
109
| if (address == null) {
|
|
163 |
0
| return "null";
|
|
164 |
| } |
|
165 |
109
| return address.getName();
|
|
166 |
| } |
|
167 |
| |
|
168 |
0
| public final String getRuleVersion() {
|
|
169 |
0
| if (address == null || module == null || module.getHeader() == null
|
|
170 |
| || module.getHeader().getSpecification() == null |
|
171 |
| || module.getHeader().getSpecification().getRuleVersion() == null) { |
|
172 |
0
| return "";
|
|
173 |
| } |
|
174 |
0
| return module.getHeader().getSpecification().getRuleVersion();
|
|
175 |
| } |
|
176 |
| |
|
177 |
66
| public final URL getUrl() {
|
|
178 |
66
| if (address == null) {
|
|
179 |
0
| return null;
|
|
180 |
| } |
|
181 |
66
| return address.getURL();
|
|
182 |
| } |
|
183 |
| |
|
184 |
32
| public final boolean isLoaded() {
|
|
185 |
32
| return (this.loadingState == LoadingState.STATE_LOADED);
|
|
186 |
| } |
|
187 |
| |
|
188 |
9
| public final void setLoaded(final QedeqBo module) {
|
|
189 |
9
| this.loadingState = LoadingState.STATE_LOADED;
|
|
190 |
9
| this.module = module;
|
|
191 |
| } |
|
192 |
| |
|
193 |
13
| public final QedeqBo getModule() {
|
|
194 |
13
| if (this.loadingState != LoadingState.STATE_LOADED) {
|
|
195 |
0
| throw new IllegalStateException(
|
|
196 |
| "module could only be set if state is \"" + LoadingState.STATE_LOADED.getText() |
|
197 |
| + "\""); |
|
198 |
| } |
|
199 |
13
| return this.module;
|
|
200 |
| } |
|
201 |
| |
|
202 |
513
| public final String toString() {
|
|
203 |
513
| return super.toString() + ":" + address + ";" + loadingState;
|
|
204 |
| } |
|
205 |
| |
|
206 |
| } |