View Javadoc

1   /**
2    * Copyright 2005-2013 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      private DataSource dataSource;
31  
32      public KENConfigurer() {
33          super(KenApiConstants.Namespaces.MODULE_NAME);
34          setValidRunModes(Arrays.asList(RunMode.REMOTE, RunMode.LOCAL));
35      }
36  
37      @Override
38  	public List<String> getPrimarySpringFiles() {
39          List<String> springFileLocations = new ArrayList<String>();
40          if (RunMode.REMOTE == getRunMode()) {
41              springFileLocations.add(getDefaultConfigPackagePath() + "KENRemoteSpringBeans.xml");
42          } else if (RunMode.LOCAL == getRunMode()) {
43              springFileLocations.add(getDefaultConfigPackagePath() + "KENLocalSpringBeans.xml");
44          }
45  		return springFileLocations;
46  	}
47  
48      @Override
49      public void addAdditonalToConfig() {
50          configureDataSource();
51      }
52  
53      private void configureDataSource() {
54          if (getDataSource() != null) {
55              ConfigContext.getCurrentContextConfig().putObject(KEN_DATASOURCE_OBJ, getDataSource());
56          }
57      }
58  
59      public DataSource getDataSource() {
60          return dataSource;
61      }
62  
63      public void setDataSource(DataSource dataSource) {
64          this.dataSource = dataSource;
65      }
66  }