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