comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshVectorOutputState.java @ 1074:649f564a5184

Implemented a new output state and chart type for horizontal profiles using vector data. gnv-artifacts/trunk@1174 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 08 Jun 2010 13:00:58 +0000
parents
children dc9727a67d41
comparison
equal deleted inserted replaced
1073:902bcd837995 1074:649f564a5184
1 package de.intevation.gnv.state.profile.horizontal;
2
3 import de.intevation.artifacts.CallContext;
4
5 import de.intevation.gnv.artifacts.cache.CacheFactory;
6
7 import de.intevation.gnv.chart.Chart;
8 import de.intevation.gnv.chart.ChartLabels;
9 import de.intevation.gnv.chart.HorizontalProfileVectorChart;
10
11 import de.intevation.gnv.geobackend.base.Result;
12
13 import de.intevation.gnv.utils.VectorDataProcessor;
14
15 import java.util.Collection;
16 import java.util.Locale;
17
18 import net.sf.ehcache.Cache;
19
20 import org.apache.log4j.Logger;
21
22 import org.jfree.chart.ChartTheme;
23
24
25 /**
26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
27 */
28 public class HorizontalProfileMeshVectorOutputState
29 extends HorizontalProfileMeshOutputState
30 {
31 private static Logger logger =
32 Logger.getLogger(HorizontalProfileMeshVectorOutputState.class);
33
34 public static final String[] RESULT_COLUMNS = {
35 "YORDINATE", "SHAPE",
36 "GROUP1", "GROUP2", "GROUP3",
37 "IPOSITION", "JPOSITION",
38 "DATAID", "MESHID",
39 "SERIES"
40 };
41
42
43 @Override
44 protected Object getChartResult(String uuid, CallContext callContext) {
45 logger.debug("Fetch data for horizontalprofile chart with vector data");
46 CacheFactory factory = CacheFactory.getInstance();
47
48 if (factory.isInitialized()) {
49 // we use a cache
50 logger.info("Using cache.");
51 Cache cache = factory.getCache();
52 String key = "chart_" + getHash();
53
54 net.sf.ehcache.Element value = cache.get(key);
55 if (value != null) {
56 logger.debug("Found element in cache.");
57 return value.getObjectValue();
58 }
59 else {
60 logger.debug("Element not in cache, we ask the database");
61 Collection<Result> res = (Collection<Result>)getData(queryID);
62 res = VectorDataProcessor.process(res, RESULT_COLUMNS);
63 logger.debug("Got " + res.size() + " elements from database.");
64
65 cache.put(new net.sf.ehcache.Element(key, res));
66
67 return res;
68 }
69 }
70 else {
71 // we don't use a cache, so we have to query the database every
72 // single time
73 logger.info("Not using a cache.");
74 return VectorDataProcessor.process(
75 getData(queryID), RESULT_COLUMNS);
76 }
77 }
78
79
80 @Override
81 protected Chart getChart(
82 ChartLabels chartLables,
83 ChartTheme theme,
84 Collection parameters,
85 Collection measurements,
86 Collection dates,
87 Object result,
88 Locale locale,
89 String uuid,
90 boolean linesVisible,
91 boolean shapesVisible,
92 CallContext callContext
93 ) {
94 Chart chart = new HorizontalProfileVectorChart(
95 chartLables,
96 theme,
97 parameters,
98 measurements,
99 dates,
100 (Collection)result,
101 timeGapDefinitions,
102 locale,
103 linesVisible,
104 shapesVisible
105 );
106 chart.generateChart();
107
108 return chart;
109 }
110 }
111 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org