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          List<String> springFileLocations = new ArrayList<String>();
53          if (RunMode.THIN == getRunMode()) {
54              springFileLocations.add(getDefaultConfigPackagePath() + "KimThinSpringBeans.xml");
55          } else if (RunMode.REMOTE == getRunMode()) {
56              springFileLocations.add(getDefaultConfigPackagePath() + "KimRemoteSpringBeans.xml");
57          } else if (RunMode.EMBEDDED == getRunMode()) {
58              springFileLocations.add(getDefaultConfigPackagePath() + "KimEmbeddedSpringBeans.xml");
59          } else if (RunMode.LOCAL == getRunMode()) {
60              springFileLocations.add(getDefaultConfigPackagePath() + "KimLocalSpringBeans.xml");
61          }
62  		return springFileLocations;
63  	}
64  
65      @Override
66      public void addAdditonalToConfig() {
67          configureDataSource();
68      }
69  
70      private void configureDataSource() {
71          if (getDataSource() != null) {
72              ConfigContext.getCurrentContextConfig().putObject(KIM_DATASOURCE_OBJ, getDataSource());
73          }
74      }
75  
76      public DataSource getDataSource() {
77          return dataSource;
78      }
79  
80      public void setDataSource(DataSource dataSource) {
81          this.dataSource = dataSource;
82      }
83      @Override
84      public boolean hasWebInterface() {
85          return true;
86      }
87  
88      @Override
89      protected WebModuleConfiguration loadWebModule() {
90          WebModuleConfiguration configuration = super.loadWebModule();
91          configuration.setWebSpringFiles(Arrays.asList(KIM_UI_SPRING_BEANS_PATH));
92          return configuration;
93      }
94  }