View Javadoc

1   /**
2    * Copyright 2005-2012 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.core.framework.persistence.jpa.OrmUtils;
26  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
27  import org.kuali.rice.core.framework.resourceloader.RiceResourceLoaderFactory;
28  import org.kuali.rice.kew.api.KewApiConstants;
29  import org.kuali.rice.kew.lifecycle.EmbeddedLifeCycle;
30  import org.kuali.rice.kew.plugin.PluginRegistry;
31  import org.kuali.rice.kew.plugin.PluginRegistryFactory;
32  import org.kuali.rice.kew.resourceloader.CoreResourceLoader;
33  import org.kuali.rice.kew.api.KewApiConstants.ClientProtocol;
34  
35  import javax.sql.DataSource;
36  import java.util.ArrayList;
37  import java.util.Arrays;
38  import java.util.Collection;
39  import java.util.Collections;
40  import java.util.LinkedList;
41  import java.util.List;
42  
43  
44  /**
45   * Configures the KEW Rice module.  KEW module initiation proceeds as follows:
46   *
47   * <ol>
48   *   <li>Parse and load configuration for:</li>
49   *     <ul>
50   *       <li>Client Protocol</li>
51   *       <li>Database</li>
52   *	   </ul>
53   *   </li>
54   *   <li>Configure and startup KEW for "Thin Client" mode OR</li>
55   *   <li>Configure and startup KEW for "Embedded Mode"</li>
56   * </ol>
57   *
58   * @author Kuali Rice Team (rice.collab@kuali.org)
59   */
60  public class KEWConfigurer extends ModuleConfigurer {
61  
62  	public static final String KEW_DATASOURCE_OBJ = "org.kuali.workflow.datasource";
63  
64  	private DataSource dataSource;
65  
66      public KEWConfigurer() {
67          super(KewApiConstants.Namespaces.MODULE_NAME);
68          setValidRunModes(Arrays.asList(RunMode.REMOTE, RunMode.EMBEDDED, RunMode.LOCAL));
69      }
70  
71  	@Override
72  	public List<String> getPrimarySpringFiles() {
73          List<String> springFileLocations = new ArrayList<String>();
74          if (RunMode.REMOTE == getRunMode()) {
75              springFileLocations.add(getDefaultConfigPackagePath() + "KewRemoteSpringBeans.xml");
76          } else if (RunMode.EMBEDDED == getRunMode()) {
77              springFileLocations.add(getDefaultConfigPackagePath() + "KewEmbeddedSpringBeans.xml");
78          } else if (RunMode.LOCAL == getRunMode()) {
79              springFileLocations.add(getDefaultConfigPackagePath() + "KewLocalSpringBeans.xml");
80          }
81  		return springFileLocations;
82  	}
83  	
84  	@Override
85  	public List<Lifecycle> loadLifecycles() throws Exception {
86  		
87  		List<Lifecycle> lifecycles = new LinkedList<Lifecycle>();
88          if ( !getRunMode().equals( RunMode.REMOTE ) ) { // local or embedded
89  			lifecycles.add(createEmbeddedLifeCycle());
90  		}
91  		return lifecycles;
92  	}
93  
94  	/**
95  	 * TODO Because a lot of our lifecycles live behind the embedded plugin and the KEWConfigurer does not, this is a simple
96  	 * measure to load these without having to deal with the removal of the embedded plugin right away.
97       * @return Life Cycle
98       * @throws Exception if life cycle not created
99       */
100 	private Lifecycle createEmbeddedLifeCycle() throws Exception {
101 		return new EmbeddedLifeCycle();
102 	}
103 
104 	@Override
105 	public void addAdditonalToConfig() {
106 		configureDataSource();
107 	}
108 
109 	private void configureDataSource() {
110 		if (getDataSource() != null) {
111 			ConfigContext.getCurrentContextConfig().putObject(KEW_DATASOURCE_OBJ, getDataSource());
112 		}
113 	}
114 
115 	@Override
116 	public Collection<ResourceLoader> getResourceLoadersToRegister() throws Exception {
117 		// create the plugin registry
118 		PluginRegistry registry = null;
119 		String pluginRegistryEnabled = ConfigContext.getCurrentContextConfig().getProperty("plugin.registry.enabled");
120 		if (!StringUtils.isBlank(pluginRegistryEnabled) && Boolean.valueOf(pluginRegistryEnabled).booleanValue()) {
121 			registry = new PluginRegistryFactory().createPluginRegistry();
122 		}
123 
124 		final Collection<ResourceLoader> rls = new ArrayList<ResourceLoader>();
125 		for (ResourceLoader rl : RiceResourceLoaderFactory.getSpringResourceLoaders()) {
126 			CoreResourceLoader coreResourceLoader = 
127 				new CoreResourceLoader(rl, registry);
128 			coreResourceLoader.start();
129 
130 			//wait until core resource loader is started to attach to GRL;  this is so startup
131 			//code can depend on other things hooked into GRL without incomplete KEW resources
132 			//messing things up.
133 
134 			GlobalResourceLoader.addResourceLoader(coreResourceLoader);
135 
136 			// now start the plugin registry if there is one
137 			if (registry != null) {
138 				registry.start();
139 				// the registry resourceloader is now being handled by the CoreResourceLoader
140 				//GlobalResourceLoader.addResourceLoader(registry);
141 			}
142 			rls.add(coreResourceLoader);
143 		}
144 
145 		return rls;
146 	}
147 
148 	public DataSource getDataSource() {
149 		return dataSource;
150 	}
151 
152 	public void setDataSource(DataSource dataSource) {
153 		this.dataSource = dataSource;
154 	}
155 
156     @Override
157     public boolean hasWebInterface() {
158         return true;
159     }
160 
161     @Override
162     protected WebModuleConfiguration loadWebModule() {
163         WebModuleConfiguration configuration = super.loadWebModule();
164         configuration.setWebSpringFiles(Arrays.asList(getDefaultConfigPackagePath() + "KewWebSpringBeans.xml"));
165         return configuration;
166     }
167 }