Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENJob.java @ 1849:5d5dd44d613e
Refactored, move doMainValueAnnotations to XYChartGenerator.
flys-artifacts/trunk@3193 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 09 Nov 2011 13:06:08 +0000 |
parents | aaf8d32f85bd |
children | a78dafdd8590 |
line wrap: on
line source
package de.intevation.flys.artifacts.model; import java.io.IOException; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import de.intevation.artifacts.CallContext; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.wsplgen.FacetCreator; public class WSPLGENJob { public static final String GEL_SPERRE = "SPERRE"; public static final String GEL_NOSPERRE = "NOSPERRE"; protected FLYSArtifact artifact; protected CallContext callContext; protected WSPLGENCalculation calculation; protected FacetCreator facetCreator; protected File workingDir; protected String dgm; protected String pro; protected String wsp; protected String wspTag; protected String axis; protected String area; protected String gel; protected String outFile; protected List<String> lin; protected int out; protected double start; protected double end; protected double from; protected double to; protected double diff; protected double dist; public WSPLGENJob( FLYSArtifact flys, File workingDir, FacetCreator facetCreator, CallContext context, WSPLGENCalculation calculation) { this.artifact = flys; this.workingDir = workingDir; this.facetCreator = facetCreator; this.callContext = context; this.calculation = calculation; out = -1; start = Double.NaN; end = Double.NaN; from = Double.NaN; to = Double.NaN; diff = Double.NaN; dist = Double.NaN; lin = new ArrayList<String>(2); } public File getWorkingDir() { return workingDir; } public FLYSArtifact getArtifact() { return artifact; } public FacetCreator getFacetCreator() { return facetCreator; } public WSPLGENCalculation getCalculation() { return calculation; } public CallContext getCallContext() { return callContext; } public void setWsp(String wsp) { this.wsp = wsp; } public String getWsp() { return wsp; } public void setWspTag(String wspTag) { this.wspTag = wspTag; } public String getWspTag() { return wspTag; } public void addLin(String lin) { this.lin.add(lin); } public List<String> getLin() { return lin; } public void setAxis(String axis) { this.axis = axis; } public String getAxis() { return axis; } public void setArea(String area) { this.area = area; } public String getArea() { return area; } public void setOut(int out) { this.out = out; } public int getOut() { return out; } public void setOutFile(String outFile) { this.outFile = outFile; } public String getOutFile() { return outFile; } public void setStart(double start) { this.start = start; } public double getStart() { return start; } public void setEnd(double end) { this.end = end; } public double getEnd() { return end; } public void setPro(String pro) { this.pro = pro; } public String getPro() { return pro; } public void setDgm(String dgm) { this.dgm = dgm; } public String getDgm() { return dgm; } public void setFrom(double from) { this.from = from; } public double getFrom() { return from; } public void setTo(double to) { this.to = to; } public double getTo() { return to; } public void setDiff(double diff) { this.diff = diff; } public double getDiff() { return diff; } public void setDist(double dist) { this.dist = dist; } public double getDist() { return dist; } public void setGel(String gel) { if (gel == null || gel.length() == 0) { return; } if (gel.equals(GEL_SPERRE) || gel.equals(GEL_NOSPERRE)) { this.gel = gel; } } public String getGel() { return gel; } public void toFile(File file) throws IOException, IllegalArgumentException { PrintWriter writer = null; try { writer = new PrintWriter( new OutputStreamWriter( new FileOutputStream(file))); write(writer); } finally { if (writer != null) { writer.flush(); writer.close(); } } } protected void write(PrintWriter writer) throws IOException, IllegalArgumentException { writeWsp(writer); // required writeWspTag(writer); // required writeLin(writer); writeAxis(writer); writeArea(writer); writeOut(writer); writeOutFile(writer); writeRange(writer); writeDelta(writer); writeGel(writer); writeDist(writer); writePro(writer); writeDgm(writer); // required } protected void writeWsp(PrintWriter writer) throws IllegalArgumentException { String wsp = getWsp(); if (wsp != null && wsp.length() > 0) { writer.println("-WSP=\"" + wsp + "\""); return; } throw new IllegalArgumentException("Required WSP missing!"); } protected void writeWspTag(PrintWriter writer) throws IllegalArgumentException { String wspTag = getWspTag(); if (wspTag != null && wspTag.length() > 0) { writer.println("-WSPTAG=\"" + wspTag + "\""); return; } throw new IllegalArgumentException("Required WSPTAG missing!"); } protected void writeLin(PrintWriter writer) throws IllegalArgumentException { List<String> lins = getLin(); if (lins != null && !lins.isEmpty()) { for (String lin: lins) { writer.println("-LIN=\"" + lin + "\""); } } } protected void writeAxis(PrintWriter writer) throws IllegalArgumentException { String axis = getAxis(); if (axis != null && axis.length() > 0) { writer.println("-ACHSE=\"" + axis + "\""); } } protected void writeGel(PrintWriter writer) throws IllegalArgumentException { if (area != null && area.length() > 0) { writer.println("-GEL=" + getGel()); } } protected void writeArea(PrintWriter writer) throws IllegalArgumentException { String area = getArea(); if (area != null && area.length() > 0) { writer.println("-GEBIET=\"" + area + "\""); } } protected void writeOut(PrintWriter writer) throws IllegalArgumentException { int out = getOut(); if (out >= 0) { writer.println("-OUTPUT=" + String.valueOf(out)); } } protected void writeOutFile(PrintWriter writer) throws IllegalArgumentException { String outFile = getOutFile(); if (outFile != null && outFile.length() > 0) { writer.println("-AUSGABE=\""+ outFile + "\""); } } protected void writeRange(PrintWriter writer) throws IllegalArgumentException { StringBuilder sb = new StringBuilder("-STRECKE="); double start = getStart(); double end = getEnd(); if (Double.isNaN(start) && Double.isNaN(end)) { return; } if (! Double.isNaN(getStart())) { sb.append(getStart()); } sb.append(","); if (! Double.isNaN(getEnd())) { sb.append(getEnd()); } writer.println(sb.toString()); } protected void writeDelta(PrintWriter writer) throws IllegalArgumentException { StringBuilder sb = new StringBuilder("-DELTA="); if (! Double.isNaN(from)) { sb.append(from); } sb.append(","); if (! Double.isNaN(to)) { sb.append(to); } sb.append(","); if (! Double.isNaN(diff)) { sb.append(diff); } writer.println(sb.toString()); } protected void writeDist(PrintWriter writer) throws IllegalArgumentException { if (! Double.isNaN(getDist())) { writer.println("-DIST=" + String.valueOf(getDist())); } } protected void writePro(PrintWriter writer) throws IllegalArgumentException { if (pro != null && pro.length() > 0) { writer.println("-PRO=\"" + getPro() + "\""); } } protected void writeDgm(PrintWriter writer) throws IllegalArgumentException { if (dgm != null && dgm.length() > 0) { writer.println("-DGM=\"" + getDgm() + "\""); return; } throw new IllegalArgumentException("Required DGM missing!"); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :