annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java @ 658:ed7c901ee712

If Artifact.feed() fails do not store invalid values in database. flys-artifacts/trunk@2062 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 07 Jun 2011 11:43:30 +0000
parents 02c0cce0e469
children bcd62609c936 3dc61e00385e
rev   line source
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.services;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import java.math.BigDecimal;
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
4 import java.util.Iterator;
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6 import org.apache.log4j.Logger;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8 import org.w3c.dom.Document;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import org.w3c.dom.Element;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import de.intevation.artifacts.CallMeta;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import de.intevation.artifacts.common.ArtifactNamespaceContext;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import de.intevation.artifacts.common.utils.XMLUtils;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import de.intevation.artifactdatabase.DefaultService;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18
316
4aa078e28cfd Bugfix: repaired broken imports of the session holder.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 314
diff changeset
19 import de.intevation.flys.backend.SessionHolder;
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 import de.intevation.flys.model.Annotation;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 import de.intevation.flys.model.Attribute;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 import de.intevation.flys.model.Position;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 import de.intevation.flys.model.Range;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 import de.intevation.flys.artifacts.model.AnnotationsFactory;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26
314
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
27 import org.hibernate.Session;
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
29 import de.intevation.flys.artifacts.cache.CacheFactory;
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
30
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
31 import net.sf.ehcache.Cache;
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
32
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 /**
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 * This service provides information about distances of a specified river.
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 *
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 */
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 public class DistanceInfoService extends DefaultService {
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 /** The logger used in this service.*/
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 private static Logger logger = Logger.getLogger(DistanceInfoService.class);
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
43 public static final String CACHE_NAME = "service-distanceinfo";
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
44
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
45 public static final String RIVER_XPATH = "/art:river/text()";
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
46
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 /**
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 * The default constructor.
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 */
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 public DistanceInfoService() {
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 }
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 public Document process(
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 Document data,
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 Object globalContext,
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 CallMeta callMeta)
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 {
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 logger.debug("DistanceInfoService.process");
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 String river = XMLUtils.xpathString(
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
63 data, RIVER_XPATH, ArtifactNamespaceContext.INSTANCE);
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
65 if (river == null || (river = river.trim()).length() == 0) {
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 logger.warn("No river specified. Cannot return distance info!");
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
67 return XMLUtils.newDocument();
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 }
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 logger.debug("Search distances for river: " + river);
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
72 Cache cache = CacheFactory.getCache(CACHE_NAME);
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
73
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
74 if (cache == null) {
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
75 logger.debug("no cache configured for distance info");
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
76 return getUncached(river);
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
77 }
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
78
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
79 net.sf.ehcache.Element element = cache.get(river);
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
80
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
81 if (element != null) {
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
82 logger.debug("distance info found in cache");
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
83 return (Document)element.getValue();
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
84 }
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
85
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
86 Document result = getUncached(river);
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
87
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
88 element = new net.sf.ehcache.Element(river, result);
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
89
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
90 logger.debug("store distance info found into cache");
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
91
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
92 cache.put(element);
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
93
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
94 return result;
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
95 }
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
96
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
97 protected Document getUncached(String river) {
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
98
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
99 Document result = XMLUtils.newDocument();
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
100
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 ElementCreator ec = new ElementCreator(
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 result,
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 ArtifactNamespaceContext.NAMESPACE_URI,
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 ArtifactNamespaceContext.NAMESPACE_PREFIX);
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105
314
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
106 Session session = SessionHolder.acquire();
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
108 try {
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
109 Iterator<Annotation> iter =
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
110 AnnotationsFactory.getAnnotationsIterator(river);
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111
314
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
112 Element all = ec.create("distances");
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
113
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
114 while (iter.hasNext()) {
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
115 Annotation a = iter.next();
314
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
116 Element distance = buildDistanceNode(ec, a);
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
117 all.appendChild(distance);
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 }
314
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
119
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
120 result.appendChild(all);
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 }
314
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
122 finally {
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
123 session.close();
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
124 SessionHolder.release();
aeeb9054b7cf Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
125 }
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 return result;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 }
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131 /**
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132 * This method build an Element for a distance info.
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 *
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 * @param ec The ElementCreator.
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135 * @param anno The Annotation that provides information about the distance.
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 *
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137 * @return an Element that contains information about a distance.
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 */
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 316
diff changeset
139 protected static Element buildDistanceNode(ElementCreator ec, Annotation anno) {
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140 Position pos = anno.getPosition();
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141 Range range = anno.getRange();
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 Attribute attr = anno.getAttribute();
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144 BigDecimal a = range.getA();
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 BigDecimal b = range.getB();
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147 Element distance = ec.create("distance");
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148 ec.addAttr(distance, "description", pos.getValue(), true);
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 ec.addAttr(distance, "from", a != null ? a.toString() : "", true);
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 ec.addAttr(distance, "to", b != null ? b.toString() : "", true);
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 ec.addAttr(distance, "riverside", attr.getValue(), true);
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 return distance;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154 }
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 }
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org