comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENJob.java @ 1190:f514894ec2fd

merged flys-artifacts/2.5
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:17 +0200
parents 64b465699a24
children aaf8d32f85bd
comparison
equal deleted inserted replaced
917:b48c36076e17 1190:f514894ec2fd
1 package de.intevation.flys.artifacts.model;
2
3 import java.io.IOException;
4 import java.io.File;
5 import java.io.FileOutputStream;
6 import java.io.OutputStreamWriter;
7 import java.io.PrintWriter;
8 import java.util.ArrayList;
9 import java.util.List;
10
11 import de.intevation.artifacts.CallContext;
12
13 import de.intevation.flys.artifacts.FLYSArtifact;
14
15
16 public class WSPLGENJob {
17
18 public static final String GEL_SPERRE = "SPERRE";
19 public static final String GEL_NOSPERRE = "NOSPERRE";
20
21
22 protected FLYSArtifact artifact;
23
24 protected CallContext callContext;
25
26 protected WSPLGENCalculation calculation;
27
28 protected File workingDir;
29
30 protected String dgm;
31 protected String pro;
32 protected String wsp;
33 protected String wspTag;
34 protected String axis;
35 protected String area;
36 protected String gel;
37 protected String outFile;
38
39 protected List<String> lin;
40
41 protected int out;
42
43 protected double start;
44 protected double end;
45 protected double from;
46 protected double to;
47 protected double diff;
48 protected double dist;
49
50
51
52 public WSPLGENJob(
53 FLYSArtifact flys,
54 File workingDir,
55 CallContext context,
56 WSPLGENCalculation calculation)
57 {
58 this.artifact = flys;
59 this.workingDir = workingDir;
60 this.callContext = context;
61 this.calculation = calculation;
62
63 out = -1;
64 start = Double.NaN;
65 end = Double.NaN;
66 from = Double.NaN;
67 to = Double.NaN;
68 diff = Double.NaN;
69 dist = Double.NaN;
70 lin = new ArrayList<String>(2);
71 }
72
73
74 public File getWorkingDir() {
75 return workingDir;
76 }
77
78
79 public FLYSArtifact getArtifact() {
80 return artifact;
81 }
82
83
84 public WSPLGENCalculation getCalculation() {
85 return calculation;
86 }
87
88
89 public CallContext getCallContext() {
90 return callContext;
91 }
92
93
94 public void setWsp(String wsp) {
95 this.wsp = wsp;
96 }
97
98
99 public String getWsp() {
100 return wsp;
101 }
102
103
104 public void setWspTag(String wspTag) {
105 this.wspTag = wspTag;
106 }
107
108
109 public String getWspTag() {
110 return wspTag;
111 }
112
113
114 public void addLin(String lin) {
115 this.lin.add(lin);
116 }
117
118
119 public List<String> getLin() {
120 return lin;
121 }
122
123
124 public void setAxis(String axis) {
125 this.axis = axis;
126 }
127
128
129 public String getAxis() {
130 return axis;
131 }
132
133
134 public void setArea(String area) {
135 this.area = area;
136 }
137
138
139 public String getArea() {
140 return area;
141 }
142
143
144 public void setOut(int out) {
145 this.out = out;
146 }
147
148
149 public int getOut() {
150 return out;
151 }
152
153
154 public void setOutFile(String outFile) {
155 this.outFile = outFile;
156 }
157
158
159 public String getOutFile() {
160 return outFile;
161 }
162
163
164 public void setStart(double start) {
165 this.start = start;
166 }
167
168
169 public double getStart() {
170 return start;
171 }
172
173
174 public void setEnd(double end) {
175 this.end = end;
176 }
177
178
179 public double getEnd() {
180 return end;
181 }
182
183
184 public void setPro(String pro) {
185 this.pro = pro;
186 }
187
188
189 public String getPro() {
190 return pro;
191 }
192
193
194 public void setDgm(String dgm) {
195 this.dgm = dgm;
196 }
197
198
199 public String getDgm() {
200 return dgm;
201 }
202
203
204 public void setFrom(double from) {
205 this.from = from;
206 }
207
208
209 public double getFrom() {
210 return from;
211 }
212
213
214 public void setTo(double to) {
215 this.to = to;
216 }
217
218
219 public double getTo() {
220 return to;
221 }
222
223
224 public void setDiff(double diff) {
225 this.diff = diff;
226 }
227
228
229 public double getDiff() {
230 return diff;
231 }
232
233
234 public void setDist(double dist) {
235 this.dist = dist;
236 }
237
238
239 public double getDist() {
240 return dist;
241 }
242
243
244 public void setGel(String gel) {
245 if (gel == null || gel.length() == 0) {
246 return;
247 }
248
249 if (gel.equals(GEL_SPERRE) || gel.equals(GEL_NOSPERRE)) {
250 this.gel = gel;
251 }
252 }
253
254
255 public String getGel() {
256 return gel;
257 }
258
259
260 public void toFile(File file)
261 throws IOException, IllegalArgumentException
262 {
263 PrintWriter writer = null;
264
265 try {
266 writer =
267 new PrintWriter(
268 new OutputStreamWriter(
269 new FileOutputStream(file)));
270
271 write(writer);
272 }
273 finally {
274 if (writer != null) {
275 writer.flush();
276 writer.close();
277 }
278 }
279 }
280
281
282 protected void write(PrintWriter writer)
283 throws IOException, IllegalArgumentException
284 {
285 writeWsp(writer); // required
286 writeWspTag(writer); // required
287 writeLin(writer);
288 writeAxis(writer);
289 writeArea(writer);
290 writeOut(writer);
291 writeOutFile(writer);
292 writeRange(writer);
293 writeDelta(writer);
294 writeGel(writer);
295 writeDist(writer);
296 writePro(writer);
297 writeDgm(writer); // required
298 }
299
300
301 protected void writeWsp(PrintWriter writer)
302 throws IllegalArgumentException
303 {
304 String wsp = getWsp();
305
306 if (wsp != null && wsp.length() > 0) {
307 writer.println("-WSP=\"" + wsp + "\"");
308 return;
309 }
310
311 throw new IllegalArgumentException("Required WSP missing!");
312 }
313
314 protected void writeWspTag(PrintWriter writer)
315 throws IllegalArgumentException
316 {
317 String wspTag = getWspTag();
318
319 if (wspTag != null && wspTag.length() > 0) {
320 writer.println("-WSPTAG=\"" + wspTag + "\"");
321 return;
322 }
323
324 throw new IllegalArgumentException("Required WSPTAG missing!");
325 }
326
327 protected void writeLin(PrintWriter writer)
328 throws IllegalArgumentException
329 {
330 List<String> lins = getLin();
331
332 if (lins != null && !lins.isEmpty()) {
333 for (String lin: lins) {
334 writer.println("-LIN=\"" + lin + "\"");
335 }
336 }
337 }
338
339 protected void writeAxis(PrintWriter writer)
340 throws IllegalArgumentException
341 {
342 String axis = getAxis();
343
344 if (axis != null && axis.length() > 0) {
345 writer.println("-ACHSE=\"" + axis + "\"");
346 }
347 }
348
349 protected void writeGel(PrintWriter writer)
350 throws IllegalArgumentException
351 {
352 if (area != null && area.length() > 0) {
353 writer.println("-GEL=" + getGel());
354 }
355 }
356
357 protected void writeArea(PrintWriter writer)
358 throws IllegalArgumentException
359 {
360 String area = getArea();
361
362 if (area != null && area.length() > 0) {
363 writer.println("-GEBIET=\"" + area + "\"");
364 }
365 }
366
367
368 protected void writeOut(PrintWriter writer)
369 throws IllegalArgumentException
370 {
371 int out = getOut();
372
373 if (out >= 0) {
374 writer.println("-OUTPUT=" + String.valueOf(out));
375 }
376 }
377
378 protected void writeOutFile(PrintWriter writer)
379 throws IllegalArgumentException
380 {
381 String outFile = getOutFile();
382
383 if (outFile != null && outFile.length() > 0) {
384 writer.println("-AUSGABE=\""+ outFile + "\"");
385 }
386 }
387
388 protected void writeRange(PrintWriter writer)
389 throws IllegalArgumentException
390 {
391 StringBuilder sb = new StringBuilder("-STRECKE=");
392
393 double start = getStart();
394 double end = getEnd();
395
396 if (Double.isNaN(start) && Double.isNaN(end)) {
397 return;
398 }
399
400 if (! Double.isNaN(getStart())) {
401 sb.append(getStart());
402 }
403
404 sb.append(",");
405
406 if (! Double.isNaN(getEnd())) {
407 sb.append(getEnd());
408 }
409
410 writer.println(sb.toString());
411 }
412
413 protected void writeDelta(PrintWriter writer)
414 throws IllegalArgumentException
415 {
416 StringBuilder sb = new StringBuilder("-DELTA=");
417 if (! Double.isNaN(from)) {
418 sb.append(from);
419 }
420
421 sb.append(",");
422
423 if (! Double.isNaN(to)) {
424 sb.append(to);
425 }
426
427 sb.append(",");
428
429 if (! Double.isNaN(diff)) {
430 sb.append(diff);
431 }
432
433 writer.println(sb.toString());
434 }
435
436 protected void writeDist(PrintWriter writer)
437 throws IllegalArgumentException
438 {
439 if (! Double.isNaN(getDist())) {
440 writer.println("-DIST=" + String.valueOf(getDist()));
441 }
442 }
443
444 protected void writePro(PrintWriter writer)
445 throws IllegalArgumentException
446 {
447 if (pro != null && pro.length() > 0) {
448 writer.println("-PRO=\"" + getPro() + "\"");
449 }
450 }
451
452 protected void writeDgm(PrintWriter writer)
453 throws IllegalArgumentException
454 {
455 if (dgm != null && dgm.length() > 0) {
456 writer.println("-DGM=\"" + getDgm() + "\"");
457 return;
458 }
459
460 throw new IllegalArgumentException("Required DGM missing!");
461 }
462 }
463 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org