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.test.lifecycles;
17:
18: import java.util.Map;
19:
20: import org.kuali.rice.config.Config;
21: import org.kuali.rice.core.Core;
22: import org.kuali.rice.lifecycle.Lifecycle;
23: import org.kuali.rice.resourceloader.GlobalResourceLoader;
24: import org.kuali.rice.resourceloader.ResourceLoader;
25: import org.kuali.rice.web.jetty.JettyServer;
26: import org.mortbay.jetty.webapp.WebAppClassLoader;
27:
28: /**
29: * A lifecycle for running a jetty web server.
30: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
31: */
32: public class JettyServerLifecycle implements Lifecycle {
33:
34: private boolean started;
35:
36: private JettyServer jettyServer;
37:
38: public JettyServerLifecycle() {
39: this (8080, null);
40: }
41:
42: public JettyServerLifecycle(int port) {
43: this (port, null, null);
44: }
45:
46: public JettyServerLifecycle(int port, String contextName) {
47: this (port, contextName, null);
48: }
49:
50: public JettyServerLifecycle(int port, String contextName,
51: String relativeWebappRoot) {
52: jettyServer = new JettyServer(port, contextName,
53: relativeWebappRoot);
54: }
55:
56: public boolean isStarted() {
57: return started;
58: }
59:
60: public void start() throws Exception {
61: jettyServer.start();
62: Map<ClassLoader, Config> configs = Core.getCONFIGS();
63: for (Map.Entry<ClassLoader, Config> configEntry : configs
64: .entrySet()) {
65: if (configEntry.getKey() instanceof WebAppClassLoader) {
66: ResourceLoader rl = GlobalResourceLoader
67: .getResourceLoader(configEntry.getKey());
68: if (rl == null) {
69: throw new RuntimeException(
70: "Could not find resource loader for workflow test harness web app for: "
71: + configEntry.getKey());
72: }
73: GlobalResourceLoader.addResourceLoader(rl);
74: configs.put(Thread.currentThread()
75: .getContextClassLoader(), configEntry
76: .getValue());
77: }
78: }
79: started = true;
80: }
81:
82: public void stop() throws Exception {
83: started = false;
84: }
85: }
|