Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/RiverService.java @ 1190:f514894ec2fd
merged flys-artifacts/2.5
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:17 +0200 |
parents | a63d79107289 |
children | 26e19cdaed5e |
comparison
equal
deleted
inserted
replaced
917:b48c36076e17 | 1190:f514894ec2fd |
---|---|
1 package de.intevation.flys.artifacts.services; | |
2 | |
3 import java.util.List; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.w3c.dom.Document; | |
8 import org.w3c.dom.Element; | |
9 | |
10 import de.intevation.artifacts.CallMeta; | |
11 import de.intevation.artifacts.GlobalContext; | |
12 | |
13 import de.intevation.artifacts.common.ArtifactNamespaceContext; | |
14 import de.intevation.artifacts.common.utils.XMLUtils; | |
15 | |
16 import de.intevation.artifactdatabase.DefaultService; | |
17 | |
18 import de.intevation.flys.backend.SessionHolder; | |
19 import de.intevation.flys.model.River; | |
20 | |
21 import de.intevation.flys.artifacts.model.RiverFactory; | |
22 | |
23 import org.hibernate.Session; | |
24 | |
25 /** | |
26 * This service provides information about the supported rivers by this | |
27 * application. | |
28 * | |
29 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
30 */ | |
31 public class RiverService extends DefaultService { | |
32 | |
33 /** The logger used in this service.*/ | |
34 private static Logger logger = Logger.getLogger(RiverService.class); | |
35 | |
36 | |
37 /** | |
38 * The default constructor. | |
39 */ | |
40 public RiverService() { | |
41 } | |
42 | |
43 | |
44 public Document process( | |
45 Document data, | |
46 GlobalContext globalContext, | |
47 CallMeta callMeta | |
48 ) { | |
49 logger.debug("RiverService.process"); | |
50 | |
51 Document result = XMLUtils.newDocument(); | |
52 | |
53 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
54 result, | |
55 ArtifactNamespaceContext.NAMESPACE_URI, | |
56 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
57 | |
58 Session session = SessionHolder.acquire(); | |
59 try { | |
60 List<River> allRivers = RiverFactory.getRivers(); | |
61 | |
62 Element rivers = ec.create("rivers"); | |
63 | |
64 for (River river: allRivers) { | |
65 Element r = ec.create("river"); | |
66 ec.addAttr(r, "name", river.getName(), true); | |
67 | |
68 rivers.appendChild(r); | |
69 } | |
70 | |
71 result.appendChild(rivers); | |
72 } | |
73 finally { | |
74 session.close(); | |
75 SessionHolder.release(); | |
76 } | |
77 | |
78 return result; | |
79 } | |
80 } | |
81 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |