2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.database
;
11 import java
.util
.HashMap
;
14 import org
.apache
.logging
.log4j
.LogManager
;
15 import org
.apache
.logging
.log4j
.Logger
;
16 import org
.springframework
.beans
.factory
.xml
.XmlBeanFactory
;
17 import org
.springframework
.core
.io
.FileSystemResource
;
20 public class DataSourceBeanLoader
{
22 private static final Logger logger
= LogManager
.getLogger();
24 private static final String DATASOURCE_BEANDEF_FILE
= "datasources.xml";
25 // see #8506 private static final String DATASOURCE_BEANDEF_PATH = ConfigFileUtil.getCdmHomeDir().getPath();
27 private static String userdefinedBeanDefinitionFile
= null;
29 public void setBeanDefinitionFile(String filename
){
30 userdefinedBeanDefinitionFile
= filename
;
33 public static <T
> Map
<String
, T
> loadDataSources(final Class
<T
> requiredType
) {
35 Map
<String
, T
> dataSources
= new HashMap
<>();
36 String path
= ""; // commented to avoid compile problems see #8506// DATASOURCE_BEANDEF_PATH + (userdefinedBeanDefinitionFile == null ? DATASOURCE_BEANDEF_FILE : userdefinedBeanDefinitionFile);
38 logger
.info("loading DataSourceBeans from: " + path
);
39 FileSystemResource file
= new FileSystemResource(path
);
40 XmlBeanFactory beanFactory
= new XmlBeanFactory(file
);
42 for(String beanName
: beanFactory
.getBeanDefinitionNames()){
43 T datasource
= beanFactory
.getBean(beanName
, requiredType
);
44 dataSources
.put(beanName
, datasource
);