01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.web;
17:
18: import java.util.ArrayList;
19: import java.util.List;
20:
21: import javax.servlet.ServletContext;
22: import javax.servlet.ServletContextEvent;
23: import javax.servlet.ServletContextListener;
24:
25: import org.apache.commons.lang.StringUtils;
26: import org.kuali.rice.config.SimpleConfig;
27: import org.kuali.rice.core.Core;
28:
29: import edu.iu.uis.eden.EdenConstants;
30:
31: public class RiceConfigurationListener implements
32: ServletContextListener {
33:
34: public void contextDestroyed(ServletContextEvent sce) {
35:
36: }
37:
38: public void contextInitialized(ServletContextEvent sce) {
39: sce.getServletContext().setAttribute("Constants",
40: new EdenConstants());
41:
42: List<String> configLocations = new ArrayList<String>();
43: // use the system prop as an override of the default packaged META-INF/workflow.xml
44: String altCoreConfigLocation = System
45: .getProperty(EdenConstants.DEFAULT_CONFIG_LOCATION_PARAM);
46: if (altCoreConfigLocation != null) {
47: configLocations.add(altCoreConfigLocation);
48: } else {
49: addDefaultConfigLocation(sce.getServletContext(),
50: configLocations);
51: }
52:
53: // use the system property to add additional configurations (useful for testing)
54: String additionalConfigLocations = System
55: .getProperty(EdenConstants.ADDITIONAL_CONFIG_LOCATIONS_PARAM);
56: if (!StringUtils.isEmpty(additionalConfigLocations)) {
57: String[] additionalConfigLocationArray = additionalConfigLocations
58: .split(",");
59: for (String additionalConfigLocation : additionalConfigLocationArray) {
60: configLocations.add(additionalConfigLocation);
61: }
62: }
63:
64: try {
65: SimpleConfig serverConfig = new SimpleConfig(
66: configLocations);
67: serverConfig.parseConfig();
68: Core.init(serverConfig);
69: } catch (Exception e) {
70: e.printStackTrace();
71: throw new RuntimeException(
72: "Workflow failed to start properly. Exiting.", e);
73: }
74: }
75:
76: /**
77: * Configures the default config location by first checking the init params for default locations and then falling back to the
78: * standard default config location.
79: */
80: protected void addDefaultConfigLocation(ServletContext context,
81: List<String> configLocations) {
82: String defaultConfigLocation = context
83: .getInitParameter(EdenConstants.DEFAULT_CONFIG_LOCATION_PARAM);
84: if (!StringUtils.isEmpty(defaultConfigLocation)) {
85: String[] locations = defaultConfigLocation.split(",");
86: for (String location : locations) {
87: configLocations.add(location);
88: }
89: } else {
90: // TODO: say what? Why workflow.xml?
91: configLocations.add("classpath:META-INF/workflow.xml");
92: }
93: }
94: }
|