1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.impl.lifecycle; |
17 | |
|
18 | |
import javax.xml.namespace.QName; |
19 | |
|
20 | |
import org.kuali.rice.core.api.lifecycle.BaseLifecycle; |
21 | |
import org.kuali.rice.core.api.lifecycle.Lifecycle; |
22 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
23 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class ServiceDelegatingLifecycle extends BaseLifecycle { |
32 | |
|
33 | |
private QName serviceName; |
34 | |
|
35 | 0 | public ServiceDelegatingLifecycle(QName serviceName) { |
36 | 0 | this.serviceName = serviceName; |
37 | 0 | } |
38 | |
|
39 | |
public ServiceDelegatingLifecycle(String serviceName) { |
40 | 0 | this(new QName(serviceName)); |
41 | 0 | } |
42 | |
|
43 | |
public void start() throws Exception { |
44 | 0 | if (!isStarted()) { |
45 | 0 | loadService(this.serviceName).start(); |
46 | |
} |
47 | 0 | super.start(); |
48 | 0 | } |
49 | |
|
50 | |
public void stop() throws Exception { |
51 | 0 | if (isStarted()) { |
52 | 0 | loadService(this.serviceName).stop(); |
53 | |
} |
54 | 0 | super.stop(); |
55 | 0 | } |
56 | |
|
57 | |
protected Lifecycle loadService(QName serviceName) { |
58 | 0 | Object service = GlobalResourceLoader.getService(serviceName); |
59 | 0 | if (service == null) { |
60 | 0 | throw new RuntimeException("Failed to locate service with name " + serviceName); |
61 | |
} |
62 | 0 | if (!(service instanceof Lifecycle)) { |
63 | 0 | throw new RuntimeException("Service with name " + serviceName + " does not implement the Lifecycle interface!"); |
64 | |
} |
65 | 0 | return (Lifecycle) service; |
66 | |
} |
67 | |
|
68 | |
} |