Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MetaDataService.java @ 372:fc3cf0ef777e
Added meta data service.
flys-artifacts/trunk@1781 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 29 Apr 2011 15:10:44 +0000 |
parents | |
children | 7c018f466d6d |
comparison
equal
deleted
inserted
replaced
371:dfbb3d50b0bd | 372:fc3cf0ef777e |
---|---|
1 package de.intevation.flys.artifacts.services; | |
2 | |
3 import java.io.InputStream; | |
4 import java.io.IOException; | |
5 | |
6 import java.sql.Connection; | |
7 import java.sql.SQLException; | |
8 | |
9 import org.w3c.dom.Document; | |
10 | |
11 import org.apache.log4j.Logger; | |
12 | |
13 import de.intevation.artifacts.CallMeta; | |
14 import de.intevation.artifacts.ServiceFactory; | |
15 | |
16 import de.intevation.artifactdatabase.DefaultService; | |
17 | |
18 import de.intevation.artifacts.common.utils.XMLUtils; | |
19 | |
20 import de.intevation.flys.artifacts.services.meta.Builder; | |
21 | |
22 import de.intevation.flys.backend.SessionHolder; | |
23 | |
24 import org.hibernate.Session; | |
25 | |
26 import org.hibernate.jdbc.Work; | |
27 | |
28 public class MetaDataService | |
29 extends DefaultService | |
30 { | |
31 private static Logger log = Logger.getLogger(MetaDataService.class); | |
32 | |
33 public static final String META_DATA_TEMPLATE = "/metadata/template.xml"; | |
34 | |
35 protected Builder builder; | |
36 | |
37 public MetaDataService() { | |
38 } | |
39 | |
40 @Override | |
41 public Document process( | |
42 Document data, | |
43 Object globalContext, | |
44 CallMeta callMeta | |
45 ) { | |
46 log.debug("MetaDataService.process"); | |
47 | |
48 final Document result = XMLUtils.newDocument(); | |
49 | |
50 if (builder == null) { | |
51 log.error("MetaDataService is not setup properly."); | |
52 return result; | |
53 } | |
54 | |
55 Session session = SessionHolder.acquire(); | |
56 try { | |
57 session.doWork(new Work() { | |
58 @Override | |
59 public void execute(Connection connection) | |
60 throws SQLException | |
61 { | |
62 log.debug("MetaDataService.execute"); | |
63 builder.build(connection, result); | |
64 } | |
65 }); | |
66 } | |
67 finally { | |
68 session.close(); | |
69 SessionHolder.release(); | |
70 } | |
71 | |
72 return result; | |
73 } | |
74 | |
75 @Override | |
76 public void setup(ServiceFactory factory, Object globalContext) { | |
77 log.debug("MetaDataService.setup"); | |
78 | |
79 InputStream in = getClass().getResourceAsStream(META_DATA_TEMPLATE); | |
80 | |
81 if (in == null) { | |
82 log.error("cannot get template resource"); | |
83 return; | |
84 } | |
85 | |
86 try { | |
87 Document template = XMLUtils.parseDocument(in); | |
88 if (template == null) { | |
89 log.error("cannot parse meta data template"); | |
90 } | |
91 else { | |
92 builder = new Builder(template); | |
93 } | |
94 } | |
95 finally { | |
96 try { | |
97 in.close(); | |
98 } | |
99 catch (IOException ioe) { | |
100 log.error(ioe); | |
101 } | |
102 } | |
103 } | |
104 } | |
105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |