Coverage Report - org.kuali.rice.core.lifecycle.ServiceDelegatingLifecycle
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceDelegatingLifecycle
0%
0/19
0%
0/8
2.2
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 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  
  * A lifecycle that wraps a service.  This fetches and calls a lifecycle available
 26  
  * in the GRL and calls lifecycle methods on that.
 27  
  *
 28  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
 }