View Javadoc

1   /**
2    * Copyright 2005-2011 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.edl.impl.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.persistence.jpa.OrmUtils;
24  import org.kuali.rice.core.impl.config.module.ModuleConfigurer;
25  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
26  import org.kuali.rice.core.impl.resourceloader.RiceResourceLoaderFactory;
27  import org.kuali.rice.kew.lifecycle.EmbeddedLifeCycle;
28  import org.kuali.rice.kew.plugin.PluginRegistry;
29  import org.kuali.rice.kew.plugin.PluginRegistryFactory;
30  import org.kuali.rice.kew.resourceloader.CoreResourceLoader;
31  import org.kuali.rice.kew.api.KewApiConstants.ClientProtocol;
32  
33  import javax.sql.DataSource;
34  import java.util.ArrayList;
35  import java.util.Collection;
36  import java.util.Collections;
37  import java.util.LinkedList;
38  import java.util.List;
39  
40  
41  /**
42   * Configures the EDocLite module. 
43   *
44   * @author Kuali Rice Team (rice.collab@kuali.org)
45   */
46  public class EDLConfigurer extends ModuleConfigurer {
47  
48  	public static final String KEW_DATASOURCE_OBJ = "org.kuali.workflow.datasource";
49  
50  	private DataSource dataSource;
51  	
52  	@Override
53  	public List<String> getPrimarySpringFiles() {
54  		final List<String> springFileLocations;
55  //		if (RunMode.REMOTE.equals(getRunMode()) || RunMode.THIN.equals(getRunMode()) ||
56  //				ClientProtocol.WEBSERVICE.equals(getClientProtocol())) {
57  //			springFileLocations = Collections.emptyList();
58  //		} else {
59  			springFileLocations = getEmbeddedSpringFileLocation();
60  //		}
61  
62  		return springFileLocations;
63  	}
64  	
65      private List<String> getEmbeddedSpringFileLocation(){
66      	final List<String> springFileLocations = new ArrayList<String>();
67      	springFileLocations.add("classpath:org/kuali/rice/edl/impl/config/EDLSpringBeans.xml");
68  
69  //        if ( isExposeServicesOnBus() ) {
70  //        	if (isSetSOAPServicesAsDefault()) {
71  //        		springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWServiceBusSOAPDefaultSpringBeans.xml");
72  //        	} else {
73  //        		springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWServiceBusSpringBeans.xml");
74  //        	}
75  //        }
76          
77  //        if (OrmUtils.isJpaEnabled("rice.kew")) {
78  //        	springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWJPASpringBeans.xml");
79  //        }
80  //        else {
81          	springFileLocations.add("classpath:org/kuali/rice/edl/impl/config/EDLOJBSpringBeans.xml");
82  //        }
83  
84      	return springFileLocations;
85      }
86  
87  	@Override
88  	public void addAdditonalToConfig() {
89  		configureDataSource();
90  	}
91  
92  	private void configureDataSource() {
93  		if (getDataSource() != null) {
94  			ConfigContext.getCurrentContextConfig().putObject(KEW_DATASOURCE_OBJ, getDataSource());
95  		}
96  	}
97  
98  	@Override
99  	public Collection<ResourceLoader> getResourceLoadersToRegister() throws Exception {
100 		// create the plugin registry
101 		PluginRegistry registry = null;
102 		String pluginRegistryEnabled = ConfigContext.getCurrentContextConfig().getProperty("plugin.registry.enabled");
103 		if (!StringUtils.isBlank(pluginRegistryEnabled) && Boolean.valueOf(pluginRegistryEnabled).booleanValue()) {
104 			registry = new PluginRegistryFactory().createPluginRegistry();
105 		}
106 
107 		final Collection<ResourceLoader> rls = new ArrayList<ResourceLoader>();
108 		for (ResourceLoader rl : RiceResourceLoaderFactory.getSpringResourceLoaders()) {
109 			CoreResourceLoader coreResourceLoader = 
110 				new CoreResourceLoader(rl, registry);
111 			coreResourceLoader.start();
112 
113 			//wait until core resource loader is started to attach to GRL;  this is so startup
114 			//code can depend on other things hooked into GRL without incomplete KEW resources
115 			//messing things up.
116 
117 			GlobalResourceLoader.addResourceLoader(coreResourceLoader);
118 
119 			// now start the plugin registry if there is one
120 			if (registry != null) {
121 				registry.start();
122 				// the registry resourceloader is now being handled by the CoreResourceLoader
123 				//GlobalResourceLoader.addResourceLoader(registry);
124 			}
125 			rls.add(coreResourceLoader);
126 		}
127 
128 		return rls;
129 	}
130 
131 	private ClientProtocol getClientProtocol() {
132 		return ClientProtocol.valueOf(ConfigContext.getCurrentContextConfig().getProperty("client.protocol"));
133 	}
134 
135 	public DataSource getDataSource() {
136 		return dataSource;
137 	}
138 
139 	public void setDataSource(DataSource dataSource) {
140 		this.dataSource = dataSource;
141 	}
142 }