Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/RiverService.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 | 4aa078e28cfd |
children | a63d79107289 |
rev | line source |
---|---|
118
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.services; |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
133
d6197a05a87c
The 'rivers' service retrieves the rivers from backend now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
118
diff
changeset
|
3 import java.util.List; |
d6197a05a87c
The 'rivers' service retrieves the rivers from backend now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
118
diff
changeset
|
4 |
118
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import org.apache.log4j.Logger; |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import org.w3c.dom.Document; |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import org.w3c.dom.Element; |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.artifacts.CallMeta; |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.artifacts.common.utils.XMLUtils; |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.artifactdatabase.DefaultService; |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 |
316
4aa078e28cfd
Bugfix: repaired broken imports of the session holder.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
314
diff
changeset
|
17 import de.intevation.flys.backend.SessionHolder; |
133
d6197a05a87c
The 'rivers' service retrieves the rivers from backend now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
118
diff
changeset
|
18 import de.intevation.flys.model.River; |
d6197a05a87c
The 'rivers' service retrieves the rivers from backend now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
118
diff
changeset
|
19 |
d6197a05a87c
The 'rivers' service retrieves the rivers from backend now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
118
diff
changeset
|
20 import de.intevation.flys.artifacts.model.RiverFactory; |
d6197a05a87c
The 'rivers' service retrieves the rivers from backend now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
118
diff
changeset
|
21 |
314
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
22 import org.hibernate.Session; |
118
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 /** |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 * This service provides information about the supported rivers by this |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 * application. |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 * |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 */ |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 public class RiverService extends DefaultService { |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 /** The logger used in this service.*/ |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 private static Logger logger = Logger.getLogger(RiverService.class); |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 /** |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 * The default constructor. |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 */ |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 public RiverService() { |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 } |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 public Document process( |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 Document data, |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 Object globalContext, |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 CallMeta callMeta) |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 { |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 logger.debug("RiverService.process"); |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 Document result = XMLUtils.newDocument(); |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 result, |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 ArtifactNamespaceContext.NAMESPACE_URI, |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 |
314
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
57 Session session = SessionHolder.acquire(); |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
58 try { |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
59 List<River> allRivers = RiverFactory.getRivers(); |
118
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 |
314
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
61 Element rivers = ec.create("rivers"); |
118
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 |
314
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
63 for (River river: allRivers) { |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
64 Element r = ec.create("river"); |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
65 ec.addAttr(r, "name", river.getName(), true); |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
66 |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
67 rivers.appendChild(r); |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
68 } |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
69 |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
70 result.appendChild(rivers); |
133
d6197a05a87c
The 'rivers' service retrieves the rivers from backend now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
118
diff
changeset
|
71 } |
314
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
72 finally { |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
73 session.close(); |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
74 SessionHolder.release(); |
aeeb9054b7cf
Acquire/release sessions in services to avoid db connection leaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
75 } |
118
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 return result; |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 } |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 } |
888e3b1dcdd9
Added a RiverService (/service/rivers) that retrieves a list of provided rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |