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