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