| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package de.jollyday.datasource; |
| 17 | |
|
| 18 | |
import de.jollyday.ManagerParameter; |
| 19 | |
import de.jollyday.util.ClassLoadingUtil; |
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | 1264 | public class ConfigurationDataSourceManager { |
| 28 | |
|
| 29 | 1267 | private ClassLoadingUtil classLoadingUtil = new ClassLoadingUtil(); |
| 30 | |
|
| 31 | |
public ConfigurationDataSource getConfigurationDataSource(ManagerParameter parameter){ |
| 32 | 80 | validateConfiguration(parameter); |
| 33 | 79 | String dataSourceClassName = parameter.getProperty(ManagerParameter.CONFIGURATION_DATASOURCE_IMPL_CLASS); |
| 34 | 79 | return instantiateDataSource(dataSourceClassName); |
| 35 | |
} |
| 36 | |
|
| 37 | |
private ConfigurationDataSource instantiateDataSource( |
| 38 | |
String dataSourceClassName) { |
| 39 | |
try{ |
| 40 | 79 | Class<?> dataSourceClass = classLoadingUtil.getClassloader().loadClass(dataSourceClassName); |
| 41 | 78 | return ConfigurationDataSource.class.cast(dataSourceClass.newInstance()); |
| 42 | 2 | }catch(Exception e){ |
| 43 | 2 | throw new IllegalStateException("Cannot instantiate datasource instance of "+dataSourceClassName,e); |
| 44 | |
} |
| 45 | |
} |
| 46 | |
|
| 47 | |
private void validateConfiguration(ManagerParameter parameter) { |
| 48 | 80 | if(parameter.getProperty(ManagerParameter.CONFIGURATION_DATASOURCE_IMPL_CLASS) == null){ |
| 49 | 1 | throw new IllegalStateException("Missing holiday configuration datasource implementation class under config key "+ManagerParameter.CONFIGURATION_DATASOURCE_IMPL_CLASS); |
| 50 | |
} |
| 51 | 79 | } |
| 52 | |
|
| 53 | |
} |