Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MetaDataService.java @ 401:34de11dcf355
Small bugfix in the adapted WQ state and further i18n strings.
flys-artifacts/trunk@1836 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 05 May 2011 12:34:53 +0000 |
parents | fc3cf0ef777e |
children | 7c018f466d6d |
line wrap: on
line source
package de.intevation.flys.artifacts.services; import java.io.InputStream; import java.io.IOException; import java.sql.Connection; import java.sql.SQLException; import org.w3c.dom.Document; import org.apache.log4j.Logger; import de.intevation.artifacts.CallMeta; import de.intevation.artifacts.ServiceFactory; import de.intevation.artifactdatabase.DefaultService; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.flys.artifacts.services.meta.Builder; import de.intevation.flys.backend.SessionHolder; import org.hibernate.Session; import org.hibernate.jdbc.Work; public class MetaDataService extends DefaultService { private static Logger log = Logger.getLogger(MetaDataService.class); public static final String META_DATA_TEMPLATE = "/metadata/template.xml"; protected Builder builder; public MetaDataService() { } @Override public Document process( Document data, Object globalContext, CallMeta callMeta ) { log.debug("MetaDataService.process"); final Document result = XMLUtils.newDocument(); if (builder == null) { log.error("MetaDataService is not setup properly."); return result; } Session session = SessionHolder.acquire(); try { session.doWork(new Work() { @Override public void execute(Connection connection) throws SQLException { log.debug("MetaDataService.execute"); builder.build(connection, result); } }); } finally { session.close(); SessionHolder.release(); } return result; } @Override public void setup(ServiceFactory factory, Object globalContext) { log.debug("MetaDataService.setup"); InputStream in = getClass().getResourceAsStream(META_DATA_TEMPLATE); if (in == null) { log.error("cannot get template resource"); return; } try { Document template = XMLUtils.parseDocument(in); if (template == null) { log.error("cannot parse meta data template"); } else { builder = new Builder(template); } } finally { try { in.close(); } catch (IOException ioe) { log.error(ioe); } } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :