diff gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java @ 52:4d6a82b96059

First Implementation of the GNV-Artifacts gnv-artifacts/trunk@32 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 07 Sep 2009 15:29:24 +0000
parents
children bb45c5097cb6
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java	Mon Sep 07 15:29:24 2009 +0000
@@ -0,0 +1,86 @@
+/**
+ *
+ */
+package de.intevation.gnv.artifacts.context;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Document;
+
+import de.intevation.artifactdatabase.Config;
+import de.intevation.artifacts.ArtifactContextFactory;
+import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPoolFactory;
+import de.intevation.gnv.geobackend.base.query.container.QueryContainerFactory;
+import de.intevation.gnv.geobackend.base.query.container.exception.QueryContainerException;
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class GNVArtifactContextFactory implements ArtifactContextFactory {
+    /**
+     * the logger, used to log exceptions and additonaly information
+     */
+    private static Logger log = Logger.getLogger(GNVArtifactContext.class);
+    
+    public static final String XPATH_GEOBACKEND_CONFIGURATION= "artifact-database/geo-backend/backend-configuration";
+    
+    public static final String XPATH_GEOBACKEND_QUERYCONFIGURATION= "artifact-database/geo-backend/query-configuration";
+    
+    /**
+     * Constructor
+     */
+    public GNVArtifactContextFactory() {
+        super();
+        log.debug("GNVArtifactContextFactory.Constructor");
+    }
+
+    /**
+     * @see de.intevation.artifacts.ArtifactContextFactory#createArtifactContext(org.w3c.dom.Document)
+     */
+    public Object createArtifactContext(Document config) {
+        Object returnValue = null;
+        try {
+            log.debug("GNVArtifactContextFactory.createArtifactContext");
+            log.info("Initialisation of the Geo-BackendConnectionPool");
+            String backendConfigurationFile = Config.getStringXPath(config, XPATH_GEOBACKEND_CONFIGURATION);
+            Properties properties = getProperties(backendConfigurationFile);
+            ConnectionPoolFactory cpf = ConnectionPoolFactory.getInstance();
+            cpf.initializeConnectionPool(properties);
+            
+            log.info("Initialisation of the QueryContainer");
+            String queryConfigurationFile = Config.getStringXPath(config, XPATH_GEOBACKEND_QUERYCONFIGURATION);
+            Properties queryProperties = getProperties(queryConfigurationFile);
+            QueryContainerFactory qcf = QueryContainerFactory.getInstance();
+            qcf.initializeQueryContainer(queryProperties);
+            
+            returnValue = new GNVArtifactContext(config);
+        } catch (FileNotFoundException e) {
+            log.error(e,e);
+        } catch (IOException e) {
+            log.error(e,e);
+        } catch (QueryContainerException e){
+            log.error(e,e);
+        }
+        return returnValue;
+    }
+
+    /**
+     * @param filePath
+     * @return
+     * @throws FileNotFoundException
+     * @throws IOException
+     */
+    private Properties getProperties(String filePath)
+            throws FileNotFoundException, IOException {
+        InputStream inputStream = new FileInputStream(filePath);
+        Properties properties = new Properties();
+        properties.load(inputStream);
+        return properties;
+    }
+}

http://dive4elements.wald.intevation.org