Project

General

Profile

Download (1.56 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.database;
2

    
3
import java.util.HashMap;
4
import java.util.Map;
5

    
6
import org.apache.log4j.Logger;
7
import org.springframework.beans.factory.xml.XmlBeanFactory;
8
import org.springframework.core.io.FileSystemResource;
9

    
10
// @Component
11
public class DataSourceBeanLoader {
12

    
13
    private static final Logger logger = Logger.getLogger(DataSourceBeanLoader.class);
14

    
15
    private static final String DATASOURCE_BEANDEF_FILE = "datasources.xml";
16
    // see #8506 private static final String DATASOURCE_BEANDEF_PATH = ConfigFileUtil.getCdmHomeDir().getPath();
17

    
18
    private static String userdefinedBeanDefinitionFile = null;
19

    
20
    public void setBeanDefinitionFile(String filename){
21
        userdefinedBeanDefinitionFile = filename;
22
    }
23

    
24

    
25
    /**
26
     * @return
27
     */
28
    public static <T> Map<String, T> loadDataSources(final Class<T> requiredType) {
29

    
30
        Map<String, T> dataSources = new HashMap<String, T>();
31
        String path = ""; // commented to avoid compile problems see #8506// DATASOURCE_BEANDEF_PATH + (userdefinedBeanDefinitionFile == null ? DATASOURCE_BEANDEF_FILE : userdefinedBeanDefinitionFile);
32

    
33
        logger.info("loading DataSourceBeans from: " + path);
34
        FileSystemResource file = new FileSystemResource(path);
35
        XmlBeanFactory beanFactory  = new XmlBeanFactory(file);
36

    
37
        for(String beanName : beanFactory.getBeanDefinitionNames()){
38
            T datasource = beanFactory.getBean(beanName, requiredType);
39
            dataSources.put(beanName, datasource);
40
        }
41
        return dataSources;
42
    }
43

    
44
}
(5-5/22)