comparison 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
comparison
equal deleted inserted replaced
51:71788b63b146 52:4d6a82b96059
1 /**
2 *
3 */
4 package de.intevation.gnv.artifacts.context;
5
6 import java.io.FileInputStream;
7 import java.io.FileNotFoundException;
8 import java.io.IOException;
9 import java.io.InputStream;
10 import java.util.Properties;
11
12 import org.apache.log4j.Logger;
13 import org.w3c.dom.Document;
14
15 import de.intevation.artifactdatabase.Config;
16 import de.intevation.artifacts.ArtifactContextFactory;
17 import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPoolFactory;
18 import de.intevation.gnv.geobackend.base.query.container.QueryContainerFactory;
19 import de.intevation.gnv.geobackend.base.query.container.exception.QueryContainerException;
20
21 /**
22 * @author Tim Englich <tim.englich@intevation.de>
23 *
24 */
25 public class GNVArtifactContextFactory implements ArtifactContextFactory {
26 /**
27 * the logger, used to log exceptions and additonaly information
28 */
29 private static Logger log = Logger.getLogger(GNVArtifactContext.class);
30
31 public static final String XPATH_GEOBACKEND_CONFIGURATION= "artifact-database/geo-backend/backend-configuration";
32
33 public static final String XPATH_GEOBACKEND_QUERYCONFIGURATION= "artifact-database/geo-backend/query-configuration";
34
35 /**
36 * Constructor
37 */
38 public GNVArtifactContextFactory() {
39 super();
40 log.debug("GNVArtifactContextFactory.Constructor");
41 }
42
43 /**
44 * @see de.intevation.artifacts.ArtifactContextFactory#createArtifactContext(org.w3c.dom.Document)
45 */
46 public Object createArtifactContext(Document config) {
47 Object returnValue = null;
48 try {
49 log.debug("GNVArtifactContextFactory.createArtifactContext");
50 log.info("Initialisation of the Geo-BackendConnectionPool");
51 String backendConfigurationFile = Config.getStringXPath(config, XPATH_GEOBACKEND_CONFIGURATION);
52 Properties properties = getProperties(backendConfigurationFile);
53 ConnectionPoolFactory cpf = ConnectionPoolFactory.getInstance();
54 cpf.initializeConnectionPool(properties);
55
56 log.info("Initialisation of the QueryContainer");
57 String queryConfigurationFile = Config.getStringXPath(config, XPATH_GEOBACKEND_QUERYCONFIGURATION);
58 Properties queryProperties = getProperties(queryConfigurationFile);
59 QueryContainerFactory qcf = QueryContainerFactory.getInstance();
60 qcf.initializeQueryContainer(queryProperties);
61
62 returnValue = new GNVArtifactContext(config);
63 } catch (FileNotFoundException e) {
64 log.error(e,e);
65 } catch (IOException e) {
66 log.error(e,e);
67 } catch (QueryContainerException e){
68 log.error(e,e);
69 }
70 return returnValue;
71 }
72
73 /**
74 * @param filePath
75 * @return
76 * @throws FileNotFoundException
77 * @throws IOException
78 */
79 private Properties getProperties(String filePath)
80 throws FileNotFoundException, IOException {
81 InputStream inputStream = new FileInputStream(filePath);
82 Properties properties = new Properties();
83 properties.load(inputStream);
84 return properties;
85 }
86 }

http://dive4elements.wald.intevation.org