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.kim.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.core.framework.config.module.WebModuleConfiguration;
22  import org.kuali.rice.kim.api.KimApiConstants;
23  
24  import javax.sql.DataSource;
25  import java.util.ArrayList;
26  import java.util.Arrays;
27  import java.util.List;
28  
29  /**
30   * This class handles the Spring based KIM configuration that is part of the Rice Configurer that must
31   * exist in all Rice based systems and clients.
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  public class KIMConfigurer extends ModuleConfigurer {
36      public static final String KIM_DATASOURCE_OBJ = "kim.datasource";
37      private static final String KIM_UI_SPRING_BEANS_PATH = "classpath:org/kuali/rice/kim/impl/config/KimWebSpringBeans.xml";
38      private DataSource dataSource;
39  
40      public KIMConfigurer() {
41          super(KimApiConstants.Namespaces.MODULE_NAME);
42          setValidRunModes(Arrays.asList(RunMode.THIN, RunMode.REMOTE, RunMode.EMBEDDED, RunMode.LOCAL));
43      }
44  
45      @Override
46      protected String getDefaultConfigPackagePath() {
47          return "classpath:org/kuali/rice/kim/impl/config/";
48      }
49  
50      @Override
51      public List<String> getPrimarySpringFiles() {
52          LOG.info("KIMConfigurer:getPrimarySpringFiles: getRunMode => " + getRunMode());
53          List<String> springFileLocations = new ArrayList<String>();
54          if (RunMode.THIN == getRunMode()) {
55              springFileLocations.add(getDefaultConfigPackagePath() + "KimThinSpringBeans.xml");
56          } else if (RunMode.REMOTE == getRunMode()) {
57              springFileLocations.add(getDefaultConfigPackagePath() + "KimRemoteSpringBeans.xml");
58          } else if (RunMode.EMBEDDED == getRunMode()) {
59              springFileLocations.add(getDefaultConfigPackagePath() + "KimEmbeddedSpringBeans.xml");
60          } else if (RunMode.LOCAL == getRunMode()) {
61              springFileLocations.add(getDefaultConfigPackagePath() + "KimLocalSpringBeans.xml");
62          }
63          return springFileLocations;
64      }
65  
66      @Override
67      public void addAdditonalToConfig() {
68          configureDataSource();
69      }
70  
71      private void configureDataSource() {
72          if (getDataSource() != null) {
73              ConfigContext.getCurrentContextConfig().putObject(KIM_DATASOURCE_OBJ, getDataSource());
74          }
75      }
76  
77      public DataSource getDataSource() {
78          return dataSource;
79      }
80  
81      public void setDataSource(DataSource dataSource) {
82          this.dataSource = dataSource;
83      }
84  
85      @Override
86      public boolean hasWebInterface() {
87          return true;
88      }
89  
90      @Override
91      protected WebModuleConfiguration loadWebModule() {
92          WebModuleConfiguration configuration = super.loadWebModule();
93          configuration.setWebSpringFiles(Arrays.asList(KIM_UI_SPRING_BEANS_PATH));
94          return configuration;
95      }
96  }