ingo@1091: package de.intevation.flys.artifacts.model; ingo@1091: ingo@1091: import java.io.IOException; ingo@1091: import java.io.File; ingo@1091: import java.io.FileOutputStream; ingo@1091: import java.io.OutputStreamWriter; ingo@1091: import java.io.PrintWriter; ingo@1106: import java.util.ArrayList; ingo@1106: import java.util.List; ingo@1091: ingo@1091: ingo@1091: public class WSPLGENJob { ingo@1091: ingo@1091: public static final String GEL_SPERRE = "SPERRE"; ingo@1091: public static final String GEL_NOSPERRE = "NOSPERRE"; ingo@1091: ingo@1091: ingo@1091: protected String dgm; ingo@1091: protected String pro; ingo@1091: protected String wsp; ingo@1091: protected String wspTag; ingo@1091: protected String axis; ingo@1091: protected String area; ingo@1091: protected String gel; ingo@1091: protected String outFile; ingo@1091: ingo@1106: protected List lin; ingo@1106: ingo@1091: protected int out; ingo@1091: ingo@1091: protected double start; ingo@1091: protected double end; ingo@1091: protected double from; ingo@1091: protected double to; ingo@1091: protected double diff; ingo@1091: protected double dist; ingo@1091: ingo@1091: ingo@1091: ingo@1091: public WSPLGENJob() { ingo@1106: out = -1; ingo@1106: start = Double.NaN; ingo@1106: end = Double.NaN; ingo@1106: from = Double.NaN; ingo@1106: to = Double.NaN; ingo@1106: diff = Double.NaN; ingo@1106: dist = Double.NaN; ingo@1106: lin = new ArrayList(2); ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void setWsp(String wsp) { ingo@1091: this.wsp = wsp; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public String getWsp() { ingo@1091: return wsp; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void setWspTag(String wspTag) { ingo@1091: this.wspTag = wspTag; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public String getWspTag() { ingo@1091: return wspTag; ingo@1091: } ingo@1091: ingo@1091: ingo@1106: public void addLin(String lin) { ingo@1106: this.lin.add(lin); ingo@1091: } ingo@1091: ingo@1091: ingo@1106: public List getLin() { ingo@1091: return lin; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void setAxis(String axis) { ingo@1091: this.axis = axis; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public String getAxis() { ingo@1091: return axis; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void setArea(String area) { ingo@1091: this.area = area; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public String getArea() { ingo@1091: return area; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void setOut(int out) { ingo@1091: this.out = out; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public int getOut() { ingo@1091: return out; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void setOutFile(String outFile) { ingo@1091: this.outFile = outFile; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public String getOutFile() { ingo@1091: return outFile; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void setStart(double start) { ingo@1091: this.start = start; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public double getStart() { ingo@1091: return start; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void setEnd(double end) { ingo@1091: this.end = end; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public double getEnd() { ingo@1091: return end; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void setPro(String pro) { ingo@1091: this.pro = pro; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public String getPro() { ingo@1091: return pro; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void setDgm(String dgm) { ingo@1091: this.dgm = dgm; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public String getDgm() { ingo@1091: return dgm; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void setFrom(double from) { ingo@1091: this.from = from; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public double getFrom() { ingo@1091: return from; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void setTo(double to) { ingo@1091: this.to = to; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public double getTo() { ingo@1091: return to; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void setDiff(double diff) { ingo@1091: this.diff = diff; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public double getDiff() { ingo@1091: return diff; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void setDist(double dist) { ingo@1091: this.dist = dist; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public double getDist() { ingo@1091: return dist; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void setGel(String gel) { ingo@1091: if (gel == null || gel.length() == 0) { ingo@1091: return; ingo@1091: } ingo@1091: ingo@1091: if (gel.equals(GEL_SPERRE) || gel.equals(GEL_NOSPERRE)) { ingo@1091: this.gel = gel; ingo@1091: } ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public String getGel() { ingo@1091: return gel; ingo@1091: } ingo@1091: ingo@1091: ingo@1091: public void toFile(File file) ingo@1091: throws IOException, IllegalArgumentException ingo@1091: { ingo@1091: PrintWriter writer = null; ingo@1091: ingo@1091: try { ingo@1091: writer = ingo@1091: new PrintWriter( ingo@1091: new OutputStreamWriter( ingo@1091: new FileOutputStream(file))); ingo@1091: ingo@1091: write(writer); ingo@1091: } ingo@1091: finally { ingo@1091: if (writer != null) { ingo@1091: writer.flush(); ingo@1091: writer.close(); ingo@1091: } ingo@1091: } ingo@1091: } ingo@1091: ingo@1091: ingo@1091: protected void write(PrintWriter writer) ingo@1091: throws IOException, IllegalArgumentException ingo@1091: { ingo@1110: writeWsp(writer); // required ingo@1110: writeWspTag(writer); // required ingo@1091: writeLin(writer); ingo@1091: writeAxis(writer); ingo@1091: writeArea(writer); ingo@1091: writeOut(writer); ingo@1091: writeOutFile(writer); ingo@1091: writeRange(writer); ingo@1091: writeDelta(writer); ingo@1091: writeGel(writer); ingo@1091: writeDist(writer); ingo@1091: writePro(writer); ingo@1110: writeDgm(writer); // required ingo@1091: } ingo@1091: ingo@1091: ingo@1091: protected void writeWsp(PrintWriter writer) ingo@1091: throws IllegalArgumentException ingo@1091: { ingo@1091: String wsp = getWsp(); ingo@1091: ingo@1091: if (wsp != null && wsp.length() > 0) { ingo@1091: writer.println("-WSP=\"" + wsp + "\""); ingo@1091: return; ingo@1091: } ingo@1091: ingo@1091: throw new IllegalArgumentException("Required WSP missing!"); ingo@1091: } ingo@1091: ingo@1091: protected void writeWspTag(PrintWriter writer) ingo@1091: throws IllegalArgumentException ingo@1091: { ingo@1091: String wspTag = getWspTag(); ingo@1091: ingo@1091: if (wspTag != null && wspTag.length() > 0) { ingo@1091: writer.println("-WSPTAG=\"" + wspTag + "\""); ingo@1091: return; ingo@1091: } ingo@1091: ingo@1091: throw new IllegalArgumentException("Required WSPTAG missing!"); ingo@1091: } ingo@1091: ingo@1091: protected void writeLin(PrintWriter writer) ingo@1091: throws IllegalArgumentException ingo@1091: { ingo@1106: List lins = getLin(); ingo@1091: ingo@1106: if (lins != null && !lins.isEmpty()) { ingo@1106: for (String lin: lins) { ingo@1106: writer.println("-LIN=\"" + lin + "\""); ingo@1106: } ingo@1091: } ingo@1091: } ingo@1091: ingo@1091: protected void writeAxis(PrintWriter writer) ingo@1091: throws IllegalArgumentException ingo@1091: { ingo@1091: String axis = getAxis(); ingo@1091: ingo@1091: if (axis != null && axis.length() > 0) { ingo@1091: writer.println("-ACHSE=\"" + axis + "\""); ingo@1091: } ingo@1091: } ingo@1091: ingo@1091: protected void writeGel(PrintWriter writer) ingo@1091: throws IllegalArgumentException ingo@1091: { ingo@1091: if (area != null && area.length() > 0) { ingo@1091: writer.println("-GEL=" + getGel()); ingo@1091: } ingo@1091: } ingo@1091: ingo@1091: protected void writeArea(PrintWriter writer) ingo@1091: throws IllegalArgumentException ingo@1091: { ingo@1091: String area = getArea(); ingo@1091: ingo@1091: if (area != null && area.length() > 0) { ingo@1091: writer.println("-GEBIET=\"" + area + "\""); ingo@1091: } ingo@1091: } ingo@1091: ingo@1091: ingo@1091: protected void writeOut(PrintWriter writer) ingo@1091: throws IllegalArgumentException ingo@1091: { ingo@1091: int out = getOut(); ingo@1091: ingo@1091: if (out >= 0) { ingo@1091: writer.println("-OUTPUT=" + String.valueOf(out)); ingo@1091: } ingo@1091: } ingo@1091: ingo@1091: protected void writeOutFile(PrintWriter writer) ingo@1091: throws IllegalArgumentException ingo@1091: { ingo@1091: String outFile = getOutFile(); ingo@1091: ingo@1091: if (outFile != null && outFile.length() > 0) { ingo@1091: writer.println("-AUSGABE=\""+ outFile + "\""); ingo@1091: } ingo@1091: } ingo@1091: ingo@1091: protected void writeRange(PrintWriter writer) ingo@1091: throws IllegalArgumentException ingo@1091: { ingo@1091: StringBuilder sb = new StringBuilder("-STRECKE="); ingo@1091: ingo@1091: double start = getStart(); ingo@1091: double end = getEnd(); ingo@1091: ingo@1091: if (Double.isNaN(start) && Double.isNaN(end)) { ingo@1091: return; ingo@1091: } ingo@1091: ingo@1091: if (! Double.isNaN(getStart())) { ingo@1091: sb.append(getStart()); ingo@1091: } ingo@1091: ingo@1091: sb.append(","); ingo@1091: ingo@1091: if (! Double.isNaN(getEnd())) { ingo@1091: sb.append(getEnd()); ingo@1091: } ingo@1091: ingo@1091: writer.println(sb.toString()); ingo@1091: } ingo@1091: ingo@1091: protected void writeDelta(PrintWriter writer) ingo@1091: throws IllegalArgumentException ingo@1091: { ingo@1091: StringBuilder sb = new StringBuilder("-DELTA="); ingo@1091: if (! Double.isNaN(from)) { ingo@1091: sb.append(from); ingo@1091: } ingo@1091: ingo@1091: sb.append(","); ingo@1091: ingo@1091: if (! Double.isNaN(to)) { ingo@1091: sb.append(to); ingo@1091: } ingo@1091: ingo@1091: sb.append(","); ingo@1091: ingo@1091: if (! Double.isNaN(diff)) { ingo@1091: sb.append(diff); ingo@1091: } ingo@1091: ingo@1091: writer.println(sb.toString()); ingo@1091: } ingo@1091: ingo@1091: protected void writeDist(PrintWriter writer) ingo@1091: throws IllegalArgumentException ingo@1091: { ingo@1091: if (! Double.isNaN(getDist())) { ingo@1091: writer.println("-DIST=" + String.valueOf(getDist())); ingo@1091: } ingo@1091: } ingo@1091: ingo@1091: protected void writePro(PrintWriter writer) ingo@1091: throws IllegalArgumentException ingo@1091: { ingo@1091: if (pro != null && pro.length() > 0) { ingo@1091: writer.println("-PRO=\"" + getPro() + "\""); ingo@1091: } ingo@1091: } ingo@1091: ingo@1091: protected void writeDgm(PrintWriter writer) ingo@1091: throws IllegalArgumentException ingo@1091: { ingo@1091: if (dgm != null && dgm.length() > 0) { ingo@1091: writer.println("-DGM=\"" + getDgm() + "\""); ingo@1091: return; ingo@1091: } ingo@1091: ingo@1091: throw new IllegalArgumentException("Required DGM missing!"); ingo@1091: } ingo@1091: } ingo@1091: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :