Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/Builder.java @ 6402:da1d1df9ab23
Datacage: Stop execution of dc:container-context earlier if there are nor results at all.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sat, 22 Jun 2013 00:13:52 +0200 |
parents | 10fe6758dfb0 |
children | 201d90f56d98 |
comparison
equal
deleted
inserted
replaced
6401:f369d69e3488 | 6402:da1d1df9ab23 |
---|---|
267 if (!(c instanceof Collection)) { | 267 if (!(c instanceof Collection)) { |
268 log.warn("dc:container-context: container is not a collection."); | 268 log.warn("dc:container-context: container is not a collection."); |
269 return; | 269 return; |
270 } | 270 } |
271 | 271 |
272 Collection<?> collection = (Collection<?>)c; | |
273 | |
274 // only descent if there are results | |
275 if (collection.isEmpty()) { | |
276 return; | |
277 } | |
278 | |
272 String [] columnNames = new String[properties.length]; | 279 String [] columnNames = new String[properties.length]; |
273 for (int i = 0; i < columnNames.length; ++i) { | 280 for (int i = 0; i < columnNames.length; ++i) { |
274 columnNames[i] = properties[i][1]; | 281 columnNames[i] = properties[i][1]; |
275 } | 282 } |
276 | 283 |
277 ResultData rd = new ResultData(columnNames); | 284 ResultData rd = new ResultData(columnNames); |
278 | 285 |
279 for (Object obj: (Collection<?>)c) { | 286 for (Object obj: collection) { |
280 Object [] row = new Object[properties.length]; | 287 Object [] row = new Object[properties.length]; |
281 for (int i = 0; i < properties.length; ++i) { | 288 for (int i = 0; i < properties.length; ++i) { |
282 row[i] = getProperty(obj, properties[i][0]); | 289 row[i] = getProperty(obj, properties[i][0]); |
283 } | 290 } |
284 rd.add(row); | 291 rd.add(row); |
285 } | 292 } |
286 | 293 |
287 // only descent if there are results | 294 // A bit of a fake because the data is not from a |
288 if (!rd.isEmpty()) { | 295 // real connection. |
289 // A bit of a fake because the data is not from a | 296 NamedConnection connection = connectionsStack.isEmpty() |
290 // real connection. | 297 ? connections.get(0) |
291 NamedConnection connection = connectionsStack.isEmpty() | 298 : connectionsStack.peek().getA(); |
292 ? connections.get(0) | 299 |
293 : connectionsStack.peek().getA(); | 300 connectionsStack.push( |
294 | 301 new Pair<NamedConnection, ResultData>(connection, rd)); |
295 connectionsStack.push( | 302 try { |
296 new Pair<NamedConnection, ResultData>(connection, rd)); | 303 for (int i = 0, S = subs.getLength(); i < S; ++i) { |
297 try { | 304 build(parent, subs.item(i)); |
298 for (int i = 0, S = subs.getLength(); i < S; ++i) { | 305 } |
299 build(parent, subs.item(i)); | 306 } |
300 } | 307 finally { |
301 } | 308 connectionsStack.pop(); |
302 finally { | |
303 connectionsStack.pop(); | |
304 } | |
305 } | 309 } |
306 } | 310 } |
307 | 311 |
308 /** Poor man's bean access. */ | 312 /** Poor man's bean access. */ |
309 private Object getProperty(Object obj, String name) { | 313 private Object getProperty(Object obj, String name) { |