Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java @ 2144:a4bdf7d8527e
Use FastAnnotations for LocationProvider.
flys-artifacts/trunk@3723 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 19 Jan 2012 13:43:58 +0000 |
parents | 2d0b22602fc2 |
children | 5642a83420f2 |
comparison
equal
deleted
inserted
replaced
2143:c5d24e0587ce | 2144:a4bdf7d8527e |
---|---|
5 | 5 |
6 import org.w3c.dom.Document; | 6 import org.w3c.dom.Document; |
7 import org.w3c.dom.Element; | 7 import org.w3c.dom.Element; |
8 | 8 |
9 import org.apache.log4j.Logger; | 9 import org.apache.log4j.Logger; |
10 | |
11 import net.sf.ehcache.Cache; | |
12 | 10 |
13 import de.intevation.artifacts.Artifact; | 11 import de.intevation.artifacts.Artifact; |
14 import de.intevation.artifacts.ArtifactNamespaceContext; | 12 import de.intevation.artifacts.ArtifactNamespaceContext; |
15 import de.intevation.artifacts.CallContext; | 13 import de.intevation.artifacts.CallContext; |
16 import de.intevation.artifacts.CallMeta; | 14 import de.intevation.artifacts.CallMeta; |
22 import de.intevation.artifactdatabase.state.StateEngine; | 20 import de.intevation.artifactdatabase.state.StateEngine; |
23 | 21 |
24 import de.intevation.artifacts.common.utils.XMLUtils; | 22 import de.intevation.artifacts.common.utils.XMLUtils; |
25 | 23 |
26 import de.intevation.flys.artifacts.states.DefaultState; | 24 import de.intevation.flys.artifacts.states.DefaultState; |
27 import de.intevation.flys.artifacts.cache.CacheFactory; | |
28 import de.intevation.flys.artifacts.context.FLYSContext; | 25 import de.intevation.flys.artifacts.context.FLYSContext; |
29 import de.intevation.flys.artifacts.model.AnnotationsFactory; | |
30 | |
31 import de.intevation.flys.model.Annotation; | |
32 | 26 |
33 import de.intevation.flys.utils.FLYSUtils; | 27 import de.intevation.flys.utils.FLYSUtils; |
34 | 28 |
35 /** | 29 /** |
36 * Artifact to access names of Points Of Interest along a segment of a river. | 30 * Artifact to access names of Points Of Interest along a segment of a river. |
40 /** The logger for this class. */ | 34 /** The logger for this class. */ |
41 private static Logger logger = Logger.getLogger(AnnotationArtifact.class); | 35 private static Logger logger = Logger.getLogger(AnnotationArtifact.class); |
42 | 36 |
43 /** The name of the artifact. */ | 37 /** The name of the artifact. */ |
44 public static final String ARTIFACT_NAME = "annotation"; | 38 public static final String ARTIFACT_NAME = "annotation"; |
45 | |
46 /** Name of cache. */ | |
47 public static final String CACHE_NAME = "annotations"; | |
48 | 39 |
49 /** Get river, setup Facets. */ | 40 /** Get river, setup Facets. */ |
50 @Override | 41 @Override |
51 protected void initialize(Artifact artifact, Object context, | 42 protected void initialize(Artifact artifact, Object context, |
52 CallMeta meta) { | 43 CallMeta meta) { |
216 } | 207 } |
217 catch (IllegalArgumentException iae) { | 208 catch (IllegalArgumentException iae) { |
218 // state is not valid, so we do not append its outputs. | 209 // state is not valid, so we do not append its outputs. |
219 } | 210 } |
220 } | 211 } |
221 | |
222 | |
223 /** | |
224 * Get Annotations for Points (opposed to segments) in river in range. | |
225 * | |
226 * @return list of Annotations. | |
227 */ | |
228 public List<Annotation> getAnnotations() { | |
229 String river = FLYSUtils.getRiver(this).getName(); | |
230 logger.debug("Search annotations for river: " + river); | |
231 | |
232 Cache cache = CacheFactory.getCache(CACHE_NAME); | |
233 String key = river; | |
234 Object old = null; | |
235 | |
236 if (cache != null) { | |
237 logger.debug("We are using a cache for annotations."); | |
238 | |
239 net.sf.ehcache.Element element = cache.get(key); | |
240 if (element != null) { | |
241 logger.info("Fetched annotations from cache."); | |
242 old = element.getValue(); | |
243 } | |
244 } | |
245 | |
246 if (old == null) { | |
247 old = getAnnotationsUncached(river); | |
248 } | |
249 | |
250 if (cache != null && old != null) { | |
251 cache.put(new net.sf.ehcache.Element(key, old)); | |
252 } | |
253 | |
254 return old != null | |
255 ? (List<Annotation>) old | |
256 : new ArrayList<Annotation>(); | |
257 } | |
258 | |
259 | |
260 /** | |
261 * Gets Annotations from Session/Database. | |
262 * | |
263 * @return List of Annotations fetched fresh from session/database. | |
264 * @see DistanceInfoService to access cached documents. | |
265 */ | |
266 protected List<Annotation> getAnnotationsUncached(String river) { | |
267 logger.info("Fetch annotations from database."); | |
268 | |
269 List<Annotation> annotations = new ArrayList<Annotation>(); | |
270 annotations = AnnotationsFactory.getPointAnnotations(river); | |
271 | |
272 return annotations; | |
273 } | |
274 } | 212 } |
275 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 213 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |