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.property.ConfigContext;
020    import org.kuali.rice.core.api.resourceloader.ResourceLoader;
021    import org.kuali.rice.core.framework.config.module.ModuleConfigurer;
022    import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
023    import org.kuali.rice.core.framework.resourceloader.RiceResourceLoaderFactory;
024    import org.kuali.rice.kew.plugin.PluginRegistry;
025    import org.kuali.rice.kew.plugin.PluginRegistryFactory;
026    import org.kuali.rice.kew.resourceloader.CoreResourceLoader;
027    import org.kuali.rice.kew.api.KewApiConstants.ClientProtocol;
028    
029    import javax.sql.DataSource;
030    import java.util.ArrayList;
031    import java.util.Collection;
032    import java.util.List;
033    
034    
035    /**
036     * Configures the EDocLite module. 
037     *
038     * @author Kuali Rice Team (rice.collab@kuali.org)
039     */
040    public class EDLConfigurer extends ModuleConfigurer {
041    
042            public static final String KEW_DATASOURCE_OBJ = "org.kuali.workflow.datasource";
043    
044            private DataSource dataSource;
045            
046            @Override
047            public List<String> getPrimarySpringFiles() {
048                    final List<String> springFileLocations;
049    //              if (RunMode.REMOTE.equals(getRunMode()) || RunMode.THIN.equals(getRunMode()) ||
050    //                              ClientProtocol.WEBSERVICE.equals(getClientProtocol())) {
051    //                      springFileLocations = Collections.emptyList();
052    //              } else {
053                            springFileLocations = getEmbeddedSpringFileLocation();
054    //              }
055    
056                    return springFileLocations;
057            }
058            
059        private List<String> getEmbeddedSpringFileLocation(){
060            final List<String> springFileLocations = new ArrayList<String>();
061            springFileLocations.add("classpath:org/kuali/rice/edl/impl/config/EDLSpringBeans.xml");
062    
063    //        if ( isExposeServicesOnBus() ) {
064    //              if (isSetSOAPServicesAsDefault()) {
065    //                      springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWServiceBusSOAPDefaultSpringBeans.xml");
066    //              } else {
067    //                      springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWServiceBusSpringBeans.xml");
068    //              }
069    //        }
070            
071    //        if (OrmUtils.isJpaEnabled("rice.kew")) {
072    //              springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWJPASpringBeans.xml");
073    //        }
074    //        else {
075                    springFileLocations.add("classpath:org/kuali/rice/edl/impl/config/EDLOJBSpringBeans.xml");
076    //        }
077    
078            return springFileLocations;
079        }
080    
081            @Override
082            public void addAdditonalToConfig() {
083                    configureDataSource();
084            }
085    
086            private void configureDataSource() {
087                    if (getDataSource() != null) {
088                            ConfigContext.getCurrentContextConfig().putObject(KEW_DATASOURCE_OBJ, getDataSource());
089                    }
090            }
091    
092            @Override
093            public Collection<ResourceLoader> getResourceLoadersToRegister() throws Exception {
094                    // create the plugin registry
095                    PluginRegistry registry = null;
096                    String pluginRegistryEnabled = ConfigContext.getCurrentContextConfig().getProperty("plugin.registry.enabled");
097                    if (!StringUtils.isBlank(pluginRegistryEnabled) && Boolean.valueOf(pluginRegistryEnabled).booleanValue()) {
098                            registry = new PluginRegistryFactory().createPluginRegistry();
099                    }
100    
101                    final Collection<ResourceLoader> rls = new ArrayList<ResourceLoader>();
102                    for (ResourceLoader rl : RiceResourceLoaderFactory.getSpringResourceLoaders()) {
103                            CoreResourceLoader coreResourceLoader = 
104                                    new CoreResourceLoader(rl, registry);
105                            coreResourceLoader.start();
106    
107                            //wait until core resource loader is started to attach to GRL;  this is so startup
108                            //code can depend on other things hooked into GRL without incomplete KEW resources
109                            //messing things up.
110    
111                            GlobalResourceLoader.addResourceLoader(coreResourceLoader);
112    
113                            // now start the plugin registry if there is one
114                            if (registry != null) {
115                                    registry.start();
116                                    // the registry resourceloader is now being handled by the CoreResourceLoader
117                                    //GlobalResourceLoader.addResourceLoader(registry);
118                            }
119                            rls.add(coreResourceLoader);
120                    }
121    
122                    return rls;
123            }
124    
125            private ClientProtocol getClientProtocol() {
126                    return ClientProtocol.valueOf(ConfigContext.getCurrentContextConfig().getProperty("client.protocol"));
127            }
128    
129            public DataSource getDataSource() {
130                    return dataSource;
131            }
132    
133            public void setDataSource(DataSource dataSource) {
134                    this.dataSource = dataSource;
135            }
136    }