Coverage Report - de.jollyday.datasource.ConfigurationDataSourceManager
 
Classes in this File Line Coverage Branch Coverage Complexity
ConfigurationDataSourceManager
100%
12/12
100%
2/2
2,667
 
 1  
 /**
 2  
  * Copyright 2013 Sven Diedrichsen 
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License"); 
 5  
  * you may not use this file except in compliance with the License. 
 6  
  * You may obtain a copy of the License at 
 7  
  * 
 8  
  * http://www.apache.org/licenses/LICENSE-2.0 
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software 
 11  
  * distributed under the License is distributed on an 
 12  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
 13  
  * express or implied. See the License for the specific language 
 14  
  * governing permissions and limitations under the License. 
 15  
  */
 16  
 package de.jollyday.datasource;
 17  
 
 18  
 import de.jollyday.ManagerParameter;
 19  
 import de.jollyday.util.ClassLoadingUtil;
 20  
 
 21  
 /**
 22  
  * This manager is responsible for instantiating the configured configuration datasource
 23  
  * which is used to access the holiday data.
 24  
  * 
 25  
  * @author sdiedrichsen
 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  
 }