View Javadoc

1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krms.config;
17  
18  import org.kuali.rice.core.api.config.module.RunMode;
19  import org.kuali.rice.core.api.config.property.ConfigContext;
20  import org.kuali.rice.core.framework.config.module.ModuleConfigurer;
21  import org.kuali.rice.krms.api.KrmsConstants;
22  
23  import javax.sql.DataSource;
24  import java.util.ArrayList;
25  import java.util.Arrays;
26  import java.util.List;
27  
28  /**
29   * This class handles the Spring based KRMS configuration that is part of the Rice Configurer that must 
30   * exist in all Rice based systems and clients. 
31   * 
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class KRMSConfigurer extends ModuleConfigurer {
35      public static final String KRMS_DATASOURCE_OBJ = "krms.datasource";
36      private static final String KRMS_SPRING_LOCAL_BEANS_PATH = "classpath:org/kuali/rice/krms/config/KRMSLocalSpringBeans.xml";
37      private static final String KRMS_SPRING_REMOTE_BEANS_PATH = "classpath:org/kuali/rice/krms/config/KRMSRemoteSpringBeans.xml";
38      private DataSource dataSource;
39  
40  	public KRMSConfigurer() {
41          super(KrmsConstants.Namespaces.MODULE_NAME);
42          setValidRunModes(Arrays.asList(RunMode.REMOTE, RunMode.LOCAL));
43      }
44  
45      @Override
46      public void addAdditonalToConfig() {
47          configureDataSource();
48      }
49  
50      private void configureDataSource() {
51          if (getDataSource() != null) {
52              ConfigContext.getCurrentContextConfig().putObject(KRMS_DATASOURCE_OBJ, getDataSource());
53          }
54      }
55  
56      public DataSource getDataSource() {
57          return dataSource;
58      }
59  
60      public void setDataSource(DataSource dataSource) {
61          this.dataSource = dataSource;
62      }
63  
64      @Override
65  	public List<String> getPrimarySpringFiles() {
66          List<String> springFileLocations = new ArrayList<String>();
67          if (RunMode.REMOTE == getRunMode()) {
68              springFileLocations.add(KRMS_SPRING_REMOTE_BEANS_PATH);
69          } else if (RunMode.LOCAL == getRunMode()) {
70              springFileLocations.add(KRMS_SPRING_LOCAL_BEANS_PATH);
71          }
72  		return springFileLocations;
73  	}
74  }