ingo@118: package de.intevation.flys.artifacts.services;
ingo@118:
ingo@133: import java.util.List;
ingo@133:
ingo@118: import org.apache.log4j.Logger;
ingo@118:
ingo@118: import org.w3c.dom.Document;
ingo@118: import org.w3c.dom.Element;
ingo@118:
ingo@118: import de.intevation.artifacts.CallMeta;
sascha@966: import de.intevation.artifacts.GlobalContext;
ingo@118:
ingo@118: import de.intevation.artifacts.common.ArtifactNamespaceContext;
ingo@118: import de.intevation.artifacts.common.utils.XMLUtils;
ingo@118:
ingo@118: import de.intevation.artifactdatabase.DefaultService;
ingo@118:
ingo@316: import de.intevation.flys.backend.SessionHolder;
ingo@133: import de.intevation.flys.model.River;
ingo@133:
ingo@133: import de.intevation.flys.artifacts.model.RiverFactory;
ingo@133:
sascha@314: import org.hibernate.Session;
ingo@118:
ingo@118: /**
ingo@118: * This service provides information about the supported rivers by this
ingo@118: * application.
ingo@118: *
ingo@118: * @author Ingo Weinzierl
ingo@118: */
ingo@118: public class RiverService extends DefaultService {
ingo@118:
ingo@118: /** The logger used in this service.*/
ingo@118: private static Logger logger = Logger.getLogger(RiverService.class);
ingo@118:
ingo@118:
ingo@118: /**
ingo@118: * The default constructor.
ingo@118: */
ingo@118: public RiverService() {
ingo@118: }
ingo@118:
ingo@118:
ingo@118: public Document process(
sascha@966: Document data,
sascha@966: GlobalContext globalContext,
sascha@966: CallMeta callMeta
sascha@966: ) {
ingo@118: logger.debug("RiverService.process");
ingo@118:
ingo@118: Document result = XMLUtils.newDocument();
ingo@118:
ingo@118: XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
ingo@118: result,
ingo@118: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@118: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@118:
sascha@314: Session session = SessionHolder.acquire();
sascha@314: try {
sascha@314: List allRivers = RiverFactory.getRivers();
ingo@118:
sascha@314: Element rivers = ec.create("rivers");
ingo@118:
sascha@314: for (River river: allRivers) {
sascha@314: Element r = ec.create("river");
sascha@314: ec.addAttr(r, "name", river.getName(), true);
sascha@314:
sascha@314: rivers.appendChild(r);
sascha@314: }
sascha@314:
sascha@314: result.appendChild(rivers);
ingo@133: }
sascha@314: finally {
sascha@314: session.close();
sascha@314: SessionHolder.release();
sascha@314: }
ingo@118:
ingo@118: return result;
ingo@118: }
ingo@118: }
ingo@118: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :