001/**
002 * Copyright 2005-2016 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    private DataSource dataSource;
031
032    public KENConfigurer() {
033        super(KenApiConstants.Namespaces.MODULE_NAME);
034        setValidRunModes(Arrays.asList(RunMode.REMOTE, RunMode.LOCAL));
035    }
036
037    @Override
038        public List<String> getPrimarySpringFiles() {
039        List<String> springFileLocations = new ArrayList<String>();
040        if (RunMode.REMOTE == getRunMode()) {
041            springFileLocations.add(getDefaultConfigPackagePath() + "KENRemoteSpringBeans.xml");
042        } else if (RunMode.LOCAL == getRunMode()) {
043            springFileLocations.add(getDefaultConfigPackagePath() + "KENLocalSpringBeans.xml");
044        }
045                return springFileLocations;
046        }
047
048    @Override
049    public void addAdditonalToConfig() {
050        configureDataSource();
051    }
052
053    private void configureDataSource() {
054        if (getDataSource() != null) {
055            ConfigContext.getCurrentContextConfig().putObject(KEN_DATASOURCE_OBJ, getDataSource());
056        }
057    }
058
059    public DataSource getDataSource() {
060        return dataSource;
061    }
062
063    public void setDataSource(DataSource dataSource) {
064        this.dataSource = dataSource;
065    }
066}