View Javadoc
1   /**
2    * Copyright 2005-2016 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.ken.impl.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.ken.api.KenApiConstants;
22  
23  import javax.sql.DataSource;
24  import java.util.ArrayList;
25  import java.util.Arrays;
26  import java.util.List;
27  
28  public class KENConfigurer extends ModuleConfigurer {
29      public static final String KEN_DATASOURCE_OBJ = "ken.datasource";
30      public static final String KCB_DATASOURCE_OBJ = "kcb.datasource";
31  
32      private DataSource dataSource;
33  
34      public KENConfigurer() {
35          super(KenApiConstants.Namespaces.MODULE_NAME);
36          setValidRunModes(Arrays.asList(RunMode.REMOTE, RunMode.LOCAL));
37      }
38  
39      @Override
40      public List<String> getPrimarySpringFiles() {
41          LOG.info("KENConfigurer:getPrimarySpringFiles: getRunMode => " + getRunMode());
42          List<String> springFileLocations = new ArrayList<String>();
43          if (RunMode.REMOTE == getRunMode()) {
44              springFileLocations.add(getDefaultConfigPackagePath() + "KENRemoteSpringBeans.xml");
45          } else if (RunMode.LOCAL == getRunMode()) {
46              springFileLocations.add(getDefaultConfigPackagePath() + "KENLocalSpringBeans.xml");
47          }
48          return springFileLocations;
49      }
50  
51      @Override
52      public void addAdditonalToConfig() {
53          configureDataSource();
54      }
55  
56      private void configureDataSource() {
57          if (getDataSource() != null) {
58              ConfigContext.getCurrentContextConfig().putObject(KEN_DATASOURCE_OBJ, getDataSource());
59              ConfigContext.getCurrentContextConfig().putObject(KCB_DATASOURCE_OBJ, getDataSource());
60          }
61      }
62  
63      public DataSource getDataSource() {
64          return dataSource;
65      }
66  
67      public void setDataSource(DataSource dataSource) {
68          this.dataSource = dataSource;
69      }
70  }