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.krms.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.krms.api.KrmsConstants;
022
023import javax.sql.DataSource;
024import java.util.ArrayList;
025import java.util.Arrays;
026import java.util.List;
027
028/**
029 * This class handles the Spring based KRMS configuration that is part of the Rice Configurer that must
030 * exist in all Rice based systems and clients.
031 *
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 */
034public class KRMSConfigurer extends ModuleConfigurer {
035    public static final String KRMS_DATASOURCE_OBJ = "krms.datasource";
036    private static final String KRMS_SPRING_LOCAL_BEANS_PATH = "classpath:org/kuali/rice/krms/config/KRMSLocalSpringBeans.xml";
037    private static final String KRMS_SPRING_REMOTE_BEANS_PATH = "classpath:org/kuali/rice/krms/config/KRMSRemoteSpringBeans.xml";
038    private DataSource dataSource;
039
040    public KRMSConfigurer() {
041        super(KrmsConstants.Namespaces.MODULE_NAME);
042        setValidRunModes(Arrays.asList(RunMode.REMOTE, RunMode.LOCAL));
043    }
044
045    @Override
046    public void addAdditonalToConfig() {
047        configureDataSource();
048    }
049
050    private void configureDataSource() {
051        if (getDataSource() != null) {
052            ConfigContext.getCurrentContextConfig().putObject(KRMS_DATASOURCE_OBJ, getDataSource());
053        }
054    }
055
056    public DataSource getDataSource() {
057        return dataSource;
058    }
059
060    public void setDataSource(DataSource dataSource) {
061        this.dataSource = dataSource;
062    }
063
064    @Override
065    public List<String> getPrimarySpringFiles() {
066        LOG.info("KRMSConfigurer:getPrimarySpringFiles: getRunMode => " + getRunMode());
067        List<String> springFileLocations = new ArrayList<String>();
068        if (RunMode.REMOTE == getRunMode()) {
069            springFileLocations.add(KRMS_SPRING_REMOTE_BEANS_PATH);
070        } else if (RunMode.LOCAL == getRunMode()) {
071            springFileLocations.add(KRMS_SPRING_LOCAL_BEANS_PATH);
072        }
073        return springFileLocations;
074    }
075}