001/** 002 * Copyright 2005-2017 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.ken.impl.config; 017 018import org.kuali.rice.core.api.config.module.RunMode; 019import org.kuali.rice.core.api.config.property.ConfigContext; 020import org.kuali.rice.core.framework.config.module.ModuleConfigurer; 021import org.kuali.rice.ken.api.KenApiConstants; 022 023import javax.sql.DataSource; 024import java.util.ArrayList; 025import java.util.Arrays; 026import java.util.List; 027 028public class KENConfigurer extends ModuleConfigurer { 029 public static final String KEN_DATASOURCE_OBJ = "ken.datasource"; 030 public static final String KCB_DATASOURCE_OBJ = "kcb.datasource"; 031 032 private DataSource dataSource; 033 034 public KENConfigurer() { 035 super(KenApiConstants.Namespaces.MODULE_NAME); 036 setValidRunModes(Arrays.asList(RunMode.REMOTE, RunMode.LOCAL)); 037 } 038 039 @Override 040 public List<String> getPrimarySpringFiles() { 041 LOG.info("KENConfigurer:getPrimarySpringFiles: getRunMode => " + getRunMode()); 042 List<String> springFileLocations = new ArrayList<String>(); 043 if (RunMode.REMOTE == getRunMode()) { 044 springFileLocations.add(getDefaultConfigPackagePath() + "KENRemoteSpringBeans.xml"); 045 } else if (RunMode.LOCAL == getRunMode()) { 046 springFileLocations.add(getDefaultConfigPackagePath() + "KENLocalSpringBeans.xml"); 047 } 048 return springFileLocations; 049 } 050 051 @Override 052 public void addAdditonalToConfig() { 053 configureDataSource(); 054 } 055 056 private void configureDataSource() { 057 if (getDataSource() != null) { 058 ConfigContext.getCurrentContextConfig().putObject(KEN_DATASOURCE_OBJ, getDataSource()); 059 ConfigContext.getCurrentContextConfig().putObject(KCB_DATASOURCE_OBJ, getDataSource()); 060 } 061 } 062 063 public DataSource getDataSource() { 064 return dataSource; 065 } 066 067 public void setDataSource(DataSource dataSource) { 068 this.dataSource = dataSource; 069 } 070}