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.kew.config;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.config.module.RunMode;
20  import org.kuali.rice.core.api.config.property.ConfigContext;
21  import org.kuali.rice.core.api.lifecycle.Lifecycle;
22  import org.kuali.rice.core.api.resourceloader.ResourceLoader;
23  import org.kuali.rice.core.framework.config.module.ModuleConfigurer;
24  import org.kuali.rice.core.framework.config.module.WebModuleConfiguration;
25  import org.kuali.rice.kew.api.KewApiConstants;
26  import org.kuali.rice.kew.lifecycle.StandaloneLifeCycle;
27  import org.kuali.rice.kew.plugin.PluginRegistry;
28  import org.kuali.rice.kew.plugin.PluginRegistryFactory;
29  
30  import javax.sql.DataSource;
31  import java.util.ArrayList;
32  import java.util.Arrays;
33  import java.util.Collection;
34  import java.util.LinkedList;
35  import java.util.List;
36  
37  
38  /**
39   * Configures the KEW Rice module.  KEW module initiation proceeds as follows:
40   *
41   * <ol>
42   *   <li>Parse and load configuration for:</li>
43   *     <ul>
44   *       <li>Client Protocol</li>
45   *       <li>Database</li>
46   *	   </ul>
47   *   </li>
48   *   <li>Configure and startup KEW for "Thin Client" mode OR</li>
49   *   <li>Configure and startup KEW for "Embedded Mode"</li>
50   * </ol>
51   *
52   * @author Kuali Rice Team (rice.collab@kuali.org)
53   */
54  public class KEWConfigurer extends ModuleConfigurer {
55  
56  	public static final String KEW_DATASOURCE_OBJ = "org.kuali.workflow.datasource";
57  
58  	private DataSource dataSource;
59  
60      public KEWConfigurer() {
61          super(KewApiConstants.Namespaces.MODULE_NAME);
62          setValidRunModes(Arrays.asList(RunMode.THIN, RunMode.REMOTE, RunMode.EMBEDDED, RunMode.LOCAL));
63      }
64  
65  	@Override
66  	public List<String> getPrimarySpringFiles() {
67          List<String> springFileLocations = new ArrayList<String>();
68          if (RunMode.THIN == getRunMode()) {
69              springFileLocations.add(getDefaultConfigPackagePath() + "KewThinSpringBeans.xml");
70          } else if (RunMode.REMOTE == getRunMode()) {
71              springFileLocations.add(getDefaultConfigPackagePath() + "KewRemoteSpringBeans.xml");
72          } else if (RunMode.EMBEDDED == getRunMode()) {
73              springFileLocations.add(getDefaultConfigPackagePath() + "KewEmbeddedSpringBeans.xml");
74          } else if (RunMode.LOCAL == getRunMode()) {
75              springFileLocations.add(getDefaultConfigPackagePath() + "KewLocalSpringBeans.xml");
76          }
77  		return springFileLocations;
78  	}
79  	
80  	@Override
81  	public List<Lifecycle> loadLifecycles() throws Exception {
82  		
83  		List<Lifecycle> lifecycles = new LinkedList<Lifecycle>();
84          if ( getRunMode().equals( RunMode.LOCAL ) ) { // local or embedded
85  			lifecycles.add(createStandaloneLifeCycle());
86  		}
87  		return lifecycles;
88  	}
89  
90  	/**
91  	 * TODO Because a lot of our lifecycles live behind the embedded plugin and the KEWConfigurer does not, this is a simple
92  	 * measure to load these without having to deal with the removal of the embedded plugin right away.
93       * @return Life Cycle
94       * @throws Exception if life cycle not created
95       */
96  	private Lifecycle createStandaloneLifeCycle() throws Exception {
97  		return new StandaloneLifeCycle();
98  	}
99  
100 	@Override
101 	public void addAdditonalToConfig() {
102 		configureDataSource();
103 	}
104 
105 	private void configureDataSource() {
106 		if (getDataSource() != null) {
107 			ConfigContext.getCurrentContextConfig().putObject(KEW_DATASOURCE_OBJ, getDataSource());
108 		}
109 	}
110 
111 	@Override
112 	public Collection<ResourceLoader> getResourceLoadersToRegister() throws Exception {
113         List<ResourceLoader> resourceLoaders = new ArrayList<ResourceLoader>();
114 		String pluginRegistryEnabled = ConfigContext.getCurrentContextConfig().getProperty("plugin.registry.enabled");
115 		if (!StringUtils.isBlank(pluginRegistryEnabled) && Boolean.valueOf(pluginRegistryEnabled).booleanValue()) {
116     		// create the plugin registry
117 			PluginRegistry registry = new PluginRegistryFactory().createPluginRegistry();
118             registry.start();
119             resourceLoaders.add(registry);
120 		}
121         return resourceLoaders;
122 	}
123 
124 	public DataSource getDataSource() {
125 		return dataSource;
126 	}
127 
128 	public void setDataSource(DataSource dataSource) {
129 		this.dataSource = dataSource;
130 	}
131 
132     @Override
133     public boolean hasWebInterface() {
134         return true;
135     }
136 
137     @Override
138     protected WebModuleConfiguration loadWebModule() {
139         WebModuleConfiguration configuration = super.loadWebModule();
140         configuration.setWebSpringFiles(Arrays.asList(getDefaultConfigPackagePath() + "KewWebSpringBeans.xml"));
141         return configuration;
142     }
143 }