001 /**
002 * Copyright 2005-2013 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 */
016 package org.kuali.rice.krms.config;
017
018 import org.kuali.rice.core.api.config.module.RunMode;
019 import org.kuali.rice.core.api.config.property.ConfigContext;
020 import org.kuali.rice.core.framework.config.module.ModuleConfigurer;
021 import org.kuali.rice.krms.api.KrmsConstants;
022
023 import javax.sql.DataSource;
024 import java.util.ArrayList;
025 import java.util.Arrays;
026 import 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 */
034 public 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 List<String> springFileLocations = new ArrayList<String>();
067 if (RunMode.REMOTE == getRunMode()) {
068 springFileLocations.add(KRMS_SPRING_REMOTE_BEANS_PATH);
069 } else if (RunMode.LOCAL == getRunMode()) {
070 springFileLocations.add(KRMS_SPRING_LOCAL_BEANS_PATH);
071 }
072 return springFileLocations;
073 }
074 }