001 /** 002 * Copyright 2005-2011 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.edl.impl.config; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.rice.core.api.config.module.RunMode; 020 import org.kuali.rice.core.api.config.property.ConfigContext; 021 import org.kuali.rice.core.api.lifecycle.Lifecycle; 022 import org.kuali.rice.core.api.resourceloader.ResourceLoader; 023 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; 024 import org.kuali.rice.core.impl.config.module.ModuleConfigurer; 025 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; 026 import org.kuali.rice.core.impl.resourceloader.RiceResourceLoaderFactory; 027 import org.kuali.rice.kew.lifecycle.EmbeddedLifeCycle; 028 import org.kuali.rice.kew.plugin.PluginRegistry; 029 import org.kuali.rice.kew.plugin.PluginRegistryFactory; 030 import org.kuali.rice.kew.resourceloader.CoreResourceLoader; 031 import org.kuali.rice.kew.api.KewApiConstants.ClientProtocol; 032 033 import javax.sql.DataSource; 034 import java.util.ArrayList; 035 import java.util.Collection; 036 import java.util.Collections; 037 import java.util.LinkedList; 038 import java.util.List; 039 040 041 /** 042 * Configures the EDocLite module. 043 * 044 * @author Kuali Rice Team (rice.collab@kuali.org) 045 */ 046 public class EDLConfigurer extends ModuleConfigurer { 047 048 public static final String KEW_DATASOURCE_OBJ = "org.kuali.workflow.datasource"; 049 050 private DataSource dataSource; 051 052 @Override 053 public List<String> getPrimarySpringFiles() { 054 final List<String> springFileLocations; 055 // if (RunMode.REMOTE.equals(getRunMode()) || RunMode.THIN.equals(getRunMode()) || 056 // ClientProtocol.WEBSERVICE.equals(getClientProtocol())) { 057 // springFileLocations = Collections.emptyList(); 058 // } else { 059 springFileLocations = getEmbeddedSpringFileLocation(); 060 // } 061 062 return springFileLocations; 063 } 064 065 private List<String> getEmbeddedSpringFileLocation(){ 066 final List<String> springFileLocations = new ArrayList<String>(); 067 springFileLocations.add("classpath:org/kuali/rice/edl/impl/config/EDLSpringBeans.xml"); 068 069 // if ( isExposeServicesOnBus() ) { 070 // if (isSetSOAPServicesAsDefault()) { 071 // springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWServiceBusSOAPDefaultSpringBeans.xml"); 072 // } else { 073 // springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWServiceBusSpringBeans.xml"); 074 // } 075 // } 076 077 // if (OrmUtils.isJpaEnabled("rice.kew")) { 078 // springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWJPASpringBeans.xml"); 079 // } 080 // else { 081 springFileLocations.add("classpath:org/kuali/rice/edl/impl/config/EDLOJBSpringBeans.xml"); 082 // } 083 084 return springFileLocations; 085 } 086 087 @Override 088 public void addAdditonalToConfig() { 089 configureDataSource(); 090 } 091 092 private void configureDataSource() { 093 if (getDataSource() != null) { 094 ConfigContext.getCurrentContextConfig().putObject(KEW_DATASOURCE_OBJ, getDataSource()); 095 } 096 } 097 098 @Override 099 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 }