Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java @ 686:3dc61e00385e facets-slt
Merged with trunk and introduced hashing of computed values.
flys-artifacts/branches/facets-slt@2126 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 15 Jun 2011 15:28:54 +0000 |
parents | 02c0cce0e469 |
children | eab5e5089d77 |
comparison
equal
deleted
inserted
replaced
667:434146596838 | 686:3dc61e00385e |
---|---|
10 | 10 |
11 import de.intevation.artifacts.CallMeta; | 11 import de.intevation.artifacts.CallMeta; |
12 | 12 |
13 import de.intevation.artifacts.common.ArtifactNamespaceContext; | 13 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
14 import de.intevation.artifacts.common.utils.XMLUtils; | 14 import de.intevation.artifacts.common.utils.XMLUtils; |
15 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | |
16 | 15 |
17 import de.intevation.artifactdatabase.DefaultService; | 16 import de.intevation.artifactdatabase.DefaultService; |
18 | 17 |
19 import de.intevation.flys.backend.SessionHolder; | 18 import de.intevation.flys.backend.SessionHolder; |
20 import de.intevation.flys.model.Annotation; | 19 import de.intevation.flys.model.Annotation; |
21 import de.intevation.flys.model.Attribute; | 20 import de.intevation.flys.model.Attribute; |
22 import de.intevation.flys.model.Position; | 21 import de.intevation.flys.model.Position; |
23 import de.intevation.flys.model.Range; | 22 import de.intevation.flys.model.Range; |
23 import de.intevation.flys.model.Edge; | |
24 | 24 |
25 import de.intevation.flys.artifacts.model.AnnotationsFactory; | 25 import de.intevation.flys.artifacts.model.AnnotationsFactory; |
26 | 26 |
27 import org.hibernate.Session; | 27 import org.hibernate.Session; |
28 | 28 |
96 | 96 |
97 protected Document getUncached(String river) { | 97 protected Document getUncached(String river) { |
98 | 98 |
99 Document result = XMLUtils.newDocument(); | 99 Document result = XMLUtils.newDocument(); |
100 | 100 |
101 ElementCreator ec = new ElementCreator( | |
102 result, | |
103 ArtifactNamespaceContext.NAMESPACE_URI, | |
104 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
105 | |
106 Session session = SessionHolder.acquire(); | 101 Session session = SessionHolder.acquire(); |
107 | 102 |
108 try { | 103 try { |
109 Iterator<Annotation> iter = | 104 Iterator<Annotation> iter = |
110 AnnotationsFactory.getAnnotationsIterator(river); | 105 AnnotationsFactory.getAnnotationsIterator(river); |
111 | 106 |
112 Element all = ec.create("distances"); | 107 Element all = result.createElement("distances"); |
113 | 108 |
114 while (iter.hasNext()) { | 109 while (iter.hasNext()) { |
115 Annotation a = iter.next(); | 110 Annotation a = iter.next(); |
116 Element distance = buildDistanceNode(ec, a); | 111 Element distance = buildDistanceNode(result, a); |
117 all.appendChild(distance); | 112 all.appendChild(distance); |
118 } | 113 } |
119 | 114 |
120 result.appendChild(all); | 115 result.appendChild(all); |
121 } | 116 } |
134 * @param ec The ElementCreator. | 129 * @param ec The ElementCreator. |
135 * @param anno The Annotation that provides information about the distance. | 130 * @param anno The Annotation that provides information about the distance. |
136 * | 131 * |
137 * @return an Element that contains information about a distance. | 132 * @return an Element that contains information about a distance. |
138 */ | 133 */ |
139 protected static Element buildDistanceNode(ElementCreator ec, Annotation anno) { | 134 protected static Element buildDistanceNode( |
140 Position pos = anno.getPosition(); | 135 Document document, |
141 Range range = anno.getRange(); | 136 Annotation anno |
142 Attribute attr = anno.getAttribute(); | 137 ) { |
138 Position pos = anno.getPosition(); | |
139 Range range = anno.getRange(); | |
140 Attribute attr = anno.getAttribute(); | |
141 Edge edge = anno.getEdge(); | |
142 BigDecimal a = range.getA(); | |
143 BigDecimal b = range.getB(); | |
143 | 144 |
144 BigDecimal a = range.getA(); | 145 Element distance = document.createElement("distance"); |
145 BigDecimal b = range.getB(); | |
146 | 146 |
147 Element distance = ec.create("distance"); | 147 distance.setAttribute("description", pos.getValue()); |
148 ec.addAttr(distance, "description", pos.getValue(), true); | 148 |
149 ec.addAttr(distance, "from", a != null ? a.toString() : "", true); | 149 String riverSide = attr.getValue(); |
150 ec.addAttr(distance, "to", b != null ? b.toString() : "", true); | 150 |
151 ec.addAttr(distance, "riverside", attr.getValue(), true); | 151 if (riverSide != null && riverSide.length() > 0) { |
152 distance.setAttribute("riverside", riverSide); | |
153 } | |
154 | |
155 if (a != null) { | |
156 distance.setAttribute("from", a.toString()); | |
157 } | |
158 if (b != null) { | |
159 distance.setAttribute("to", b.toString()); | |
160 } | |
161 if (edge != null) { | |
162 BigDecimal bottom = edge.getBottom(); | |
163 BigDecimal top = edge.getTop(); | |
164 if (bottom != null) { | |
165 distance.setAttribute("bottom", bottom.toString()); | |
166 } | |
167 if (top != null) { | |
168 distance.setAttribute("top", top.toString()); | |
169 } | |
170 } | |
152 | 171 |
153 return distance; | 172 return distance; |
154 } | 173 } |
155 } | 174 } |
156 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 175 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |