Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java @ 726:cbaa3ca86f2f
Added base class WQ for WQKms.
flys-artifacts/trunk@2216 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 23 Jun 2011 12:19:12 +0000 |
parents | eab5e5089d77 |
children | 95356252c309 |
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 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 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
|
17 |
316
4aa078e28cfd
Bugfix: repaired broken imports of the session holder.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
314
diff
changeset
|
18 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
|
19 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
|
20 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
|
21 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
|
22 import de.intevation.flys.model.Range; |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
23 import de.intevation.flys.model.Edge; |
301
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 |
314
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
101 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
|
102 |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
103 try { |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
104 Iterator<Annotation> iter = |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
105 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
|
106 |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
107 Element all = result.createElement("distances"); |
314
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
108 |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
109 while (iter.hasNext()) { |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
110 Annotation a = iter.next(); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
111 Element distance = buildDistanceNode(result, a); |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
112 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
|
113 } |
314
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
114 |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
115 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
|
116 } |
314
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
117 finally { |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
118 session.close(); |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
119 SessionHolder.release(); |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
120 } |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
121 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
122 return result; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
123 } |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
124 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
125 |
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 * 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
|
128 * |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
129 * @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
|
130 * @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
|
131 * |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
132 * @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
|
133 */ |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
134 protected static Element buildDistanceNode( |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
135 Document document, |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
136 Annotation anno |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
137 ) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
138 Position pos = anno.getPosition(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
139 Range range = anno.getRange(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
140 Attribute attr = anno.getAttribute(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
141 Edge edge = anno.getEdge(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
142 BigDecimal a = range.getA(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
143 BigDecimal b = range.getB(); |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
144 |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
145 Element distance = document.createElement("distance"); |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
146 |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
147 distance.setAttribute("description", pos.getValue()); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
148 |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
149 String riverSide = attr.getValue(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
150 |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
151 if (riverSide != null && riverSide.length() > 0) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
152 distance.setAttribute("riverside", riverSide); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
153 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
154 |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
155 if (a != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
156 distance.setAttribute("from", a.toString()); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
157 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
158 if (b != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
159 distance.setAttribute("to", b.toString()); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
160 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
161 if (edge != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
162 BigDecimal bottom = edge.getBottom(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
163 BigDecimal top = edge.getTop(); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
164 if (bottom != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
165 distance.setAttribute("bottom", bottom.toString()); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
166 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
167 if (top != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
168 distance.setAttribute("top", top.toString()); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
169 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
644
diff
changeset
|
170 } |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
171 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
172 return distance; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
173 } |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
174 } |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
175 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |