comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java @ 804:9058c08eac3a

Added more Javadoc in some classes of state.profile. gnv-artifacts/trunk@886 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 08 Apr 2010 10:10:04 +0000
parents c4156275c1e1
children bb7afd783321
comparison
equal deleted inserted replaced
803:feae2f9d6c6f 804:9058c08eac3a
90 private static final long serialVersionUID = 3233620652465061860L; 90 private static final long serialVersionUID = 3233620652465061860L;
91 91
92 public static final boolean USE_INDEX_BUFFER = 92 public static final boolean USE_INDEX_BUFFER =
93 Boolean.getBoolean("gnv.horizontal.cross.section.mesh.index.buffer"); 93 Boolean.getBoolean("gnv.horizontal.cross.section.mesh.index.buffer");
94 94
95 /**
96 * Shapefile name for isolines.
97 */
95 public static final String ISOLINES_NAME = "isolines.shp"; 98 public static final String ISOLINES_NAME = "isolines.shp";
99
100 /**
101 * Shapefile name for polygons.
102 */
96 public static final String POLYGON_NAME = "polygons.shp"; 103 public static final String POLYGON_NAME = "polygons.shp";
104
97 public static final String LAYER_MODEL = "horizontalcrosssection"; 105 public static final String LAYER_MODEL = "horizontalcrosssection";
98 106
99 private String ijkQueryID; 107 private String ijkQueryID;
100 108
101 private Boolean shapeFileLock = new Boolean(true); 109 private Boolean shapeFileLock = new Boolean(true);
106 * Constructor 114 * Constructor
107 */ 115 */
108 public HorizontalCrossSectionMeshOutputState() { 116 public HorizontalCrossSectionMeshOutputState() {
109 } 117 }
110 118
119 @Override
111 public void initialize(String uuid, CallContext callContext) 120 public void initialize(String uuid, CallContext callContext)
112 throws StateException { 121 throws StateException {
113 super.initialize(uuid, callContext); 122 super.initialize(uuid, callContext);
114 if (log.isDebugEnabled()) { 123 if (log.isDebugEnabled()) {
115 log.debug("initialize output state " + uuid); 124 log.debug("initialize output state " + uuid);
116 } 125 }
117 // fill the cache 126 // fill the cache
118 getResult(uuid, callContext); 127 getResult(uuid, callContext);
119 } 128 }
120 129
130 /**
131 * Returns the shapefile directory path.
132 *
133 * @return the shapefile path.
134 */
121 public String getShapeFilePath() { 135 public String getShapeFilePath() {
122 synchronized (shapeFileLock) { 136 synchronized (shapeFileLock) {
123 return shapeFilePath; 137 return shapeFilePath;
124 } 138 }
125 } 139 }
126 140
141 /**
142 * Set the shapefile path.
143 *
144 * @param shapeFilePath Destination path to write shapefiles.
145 */
127 public void setShapeFilePath(String shapeFilePath) { 146 public void setShapeFilePath(String shapeFilePath) {
128 synchronized (shapeFileLock) { 147 synchronized (shapeFileLock) {
129 this.shapeFilePath = shapeFilePath; 148 this.shapeFilePath = shapeFilePath;
130 } 149 }
131 } 150 }
132 151
152 /**
153 * Method to reset the shapefile path.
154 *
155 * @return the old path.
156 */
133 public String resetShapeFilePath() { 157 public String resetShapeFilePath() {
134 synchronized (shapeFileLock) { 158 synchronized (shapeFileLock) {
135 String path = shapeFilePath; 159 String path = shapeFilePath;
136 shapeFilePath = null; 160 shapeFilePath = null;
137 return path; 161 return path;
138 } 162 }
139 } 163 }
140 164
165
166 /**
167 * This method removes all shapefiles which might have been written by this
168 * artifact and resets the shapefile path.
169 *
170 * @param globalContext CallContext
171 */
172 @Override
141 public void endOfLife(Object globalContext) { 173 public void endOfLife(Object globalContext) {
142 super.endOfLife(globalContext); 174 super.endOfLife(globalContext);
143 175
144 // do it in background 176 // do it in background
145 new Thread() { 177 new Thread() {
178 @Override
146 public void run() { 179 public void run() {
147 // TODO: Do the un-publishing WMS stuff. 180 // TODO: Do the un-publishing WMS stuff.
148 String path = resetShapeFilePath(); 181 String path = resetShapeFilePath();
149 182
150 if (path == null) { 183 if (path == null) {
169 log.error("failed to remove directory '" + path + "'"); 202 log.error("failed to remove directory '" + path + "'");
170 } // run 203 } // run
171 }.start(); 204 }.start();
172 } 205 }
173 206
207
208 /**
209 * This out target has two options:<br>
210 * <ol>
211 * <li>zip: Write the resulting data to shapefiles and export them as
212 * zip-archive.</li>
213 * <li>wms: Write the resulting data to shapefiles and feed a map service
214 * with a layer displaying these shapefiles.</li>
215 * </ol>
216 *
217 * @param format
218 * @param inputData
219 * @param outputStream
220 * @param uuid
221 * @param callContext
222 * @throws StateException
223 */
174 public void out( 224 public void out(
175 Document format, 225 Document format,
176 Collection<InputData> inputData, 226 Collection<InputData> inputData,
177 OutputStream outputStream, 227 OutputStream outputStream,
178 String uuid, 228 String uuid,
204 else { 254 else {
205 throw new StateException("unsupported output mode"); 255 throw new StateException("unsupported output mode");
206 } 256 }
207 } 257 }
208 258
259 /**
260 * Create a zip archive with the shapefiles of the given shapefiles path and
261 * write it to <code>output</code>.
262 *
263 * @param uuid The UUID of the current artifact.
264 * @param callContext The CallContext object.
265 * @param output The output stream.
266 * @throws StateException if an error occured while zipfile creation.
267 */
209 protected void writeZip( 268 protected void writeZip(
210 String uuid, 269 String uuid,
211 CallContext callContext, 270 CallContext callContext,
212 OutputStream output 271 OutputStream output
213 ) 272 )
234 catch (IOException ioe) { 293 catch (IOException ioe) {
235 log.error(ioe.getLocalizedMessage(), ioe); 294 log.error(ioe.getLocalizedMessage(), ioe);
236 } 295 }
237 } 296 }
238 297
298 /**
299 * Write data to shapefiles and feed a map service with information about
300 * these shapefiles. The map service can be queried for displaying
301 * corresponding layers as WMS.
302 *
303 * @param uuid The UUID of the current artifact.
304 * @param callContext The CallContext object.
305 * @param inputData A collection with some input data.
306 * @return a document with some meta information (shapefile path, geometry
307 * type, time to live of the current artifact, etc).
308 * @throws StateException if an error occured while shapefile writing.
309 */
239 protected Document getWMS( 310 protected Document getWMS(
240 String uuid, 311 String uuid,
241 CallContext callContext, 312 CallContext callContext,
242 Collection<InputData> inputData 313 Collection<InputData> inputData
243 ) 314 )
310 } 381 }
311 382
312 return document; 383 return document;
313 } 384 }
314 385
386 /**
387 * Find the parameter name which is used during mapfile creation in
388 * MapfileGenerator.
389 *
390 * @param callContext The CallContext object.
391 * @return the parameter name of the current parameterization.
392 */
315 protected String findParameterType(CallContext callContext) { 393 protected String findParameterType(CallContext callContext) {
316 InputData inputParam = inputData.get("parameterid"); 394 InputData inputParam = inputData.get("parameterid");
317 395
318 Map<Integer, PaletteManager> paletteManagers = getPalettes(callContext); 396 Map<Integer, PaletteManager> paletteManagers = getPalettes(callContext);
319 397
328 return LAYER_MODEL + "_" + paletteManager.getName(); 406 return LAYER_MODEL + "_" + paletteManager.getName();
329 } 407 }
330 } 408 }
331 409
332 410
411 /**
412 * Find the title for a wms layer specified by the user.
413 *
414 * @param inputData A collection with InputData objects.
415 * @return the title.
416 */
333 protected String getLayerTitle(Collection<InputData> inputData) { 417 protected String getLayerTitle(Collection<InputData> inputData) {
334 for (InputData data: inputData) { 418 for (InputData data: inputData) {
335 String name = data.getName(); 419 String name = data.getName();
336 if (name != null && name.equals("title")) { 420 if (name != null && name.equals("title")) {
337 return (String) data.getValue(); 421 return (String) data.getValue();
339 } 423 }
340 424
341 return null; 425 return null;
342 } 426 }
343 427
428 /**
429 * Write the resulting data to shapefiles.
430 *
431 * @param uuid The UUID of the current artifact.
432 * @param result The finalized data used for shapefile creation.
433 * @param callContext The CallContext object.
434 * @return the shapefile path.
435 */
344 protected String writeToShapeFile( 436 protected String writeToShapeFile(
345 String uuid, 437 String uuid,
346 AttributedPoint2ds result, 438 AttributedPoint2ds result,
347 CallContext callContext 439 CallContext callContext
348 ) { 440 ) {
409 } 501 }
410 } 502 }
411 } 503 }
412 504
413 505
506 /**
507 * Return the processed results ready for being written to shapefile.
508 *
509 * @param uuid The UUID of the current artifacts.
510 * @param callContext The CallContext object.
511 * @return the processed data.
512 * @throws StateException if an error occured while processing data.
513 */
414 protected AttributedPoint2ds getResult(String uuid, CallContext callContext) 514 protected AttributedPoint2ds getResult(String uuid, CallContext callContext)
415 throws StateException 515 throws StateException
416 { 516 {
417 CacheFactory cf = CacheFactory.getInstance(); 517 CacheFactory cf = CacheFactory.getInstance();
418 String key = getHash(); 518 String key = getHash();
431 } 531 }
432 532
433 return result; 533 return result;
434 } 534 }
435 535
536 /**
537 * Query the database for result data and turn it into a useful format to
538 * write this data into shapefiles.
539 *
540 * @param callContext The CallContext object.
541 * @return the processed data.
542 * @throws StateException if an error occured while processing data.
543 */
436 protected AttributedPoint2ds produceResult(CallContext callContext) 544 protected AttributedPoint2ds produceResult(CallContext callContext)
437 throws StateException 545 throws StateException
438 { 546 {
439 InputData meshPolygon = inputData.get("mesh_polygon"); 547 InputData meshPolygon = inputData.get("mesh_polygon");
440 InputData meshId = inputData.get("meshid"); 548 InputData meshId = inputData.get("meshid");
500 } 608 }
501 609
502 throw new StateException("no result produced"); 610 throw new StateException("no result produced");
503 } 611 }
504 612
613 /**
614 * First step of finalizing the data returned from database.
615 *
616 * @param results Resulting data from database.
617 * @return the pre-processed data which is still not useful for being
618 * written to shapefiles.
619 */
505 public AttributedPoint2ds preProcess(Collection<Result> results) { 620 public AttributedPoint2ds preProcess(Collection<Result> results) {
506 621
507 boolean debug = log.isDebugEnabled(); 622 boolean debug = log.isDebugEnabled();
508 623
509 if (debug) { 624 if (debug) {
565 ap2ds.setPoints(points); 680 ap2ds.setPoints(points);
566 681
567 return ap2ds; 682 return ap2ds;
568 } 683 }
569 684
685 /**
686 * The last step of finalizing the data. The returned data is useful for
687 * shapefile creation.
688 *
689 * @param boundingBox The bounding box.
690 * @param polygon A polygon.
691 * @param callContext CallContext.
692 * @param input The pre-processed data.
693 * @return the finalized data ready for shapefile creation.
694 */
570 public AttributedPoint2ds process( 695 public AttributedPoint2ds process(
571 Envelope boundingBox, 696 Envelope boundingBox,
572 Polygon polygon, 697 Polygon polygon,
573 CallContext callContext, 698 CallContext callContext,
574 AttributedPoint2ds input 699 AttributedPoint2ds input

http://dive4elements.wald.intevation.org